@Test
    public void testForEachOverStruct() {
        var tester = new ScriptTester();
        var expression = tester.expressionFrom("input myInStruct | for_each { substring 0 2 } | attribute myOutStruct");
        StructDataType type = new StructDataType("myStruct");
        type.addField(new Field("myString1", DataType.STRING));
        type.addField(new Field("myString2", DataType.STRING));

        SimpleTestAdapter adapter = new SimpleTestAdapter();
        adapter.createField(new Field("myInStruct", type));
        adapter.createField(new Field("myOutStruct", type));
        expression.resolve(adapter);

        var inStruct = new Struct(type);
        inStruct.setFieldValue("myString1", "foo");
        inStruct.setFieldValue("myString2", "the bar");
        adapter.setValue("myInStruct", inStruct);
        var context = new ExecutionContext(adapter);
        expression.execute(context);
        var outStruct = (Struct)adapter.values.get("myOutStruct");
        assertEquals("fo", outStruct.getFieldValue("myString1").getWrappedValue());
        assertEquals("th", outStruct.getFieldValue("myString2").getWrappedValue());
    }
@author Simon Thoresen Hult
@author bratseth
indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java