@SuppressWarnings("unchecked")
    @Test
    public void testForEachWithWeightedSet() {
        var tester = new ScriptTester();
        var expression = tester.expressionFrom("input myWeightedSet | for_each { to_int } | attribute myInts");

        SimpleTestAdapter adapter = new SimpleTestAdapter();
        var myWeightedSet = new WeightedSet<StringFieldValue>(WeightedSetDataType.getWeightedSet(DataType.STRING));
        adapter.createField(new Field("myWeightedSet", myWeightedSet.getDataType()));
        adapter.setValue("myWeightedSet", myWeightedSet);
        adapter.createField(new Field("myInts", WeightedSetDataType.getWeightedSet(DataType.INT)));

        expression.resolve(adapter);
        ExecutionContext context = new ExecutionContext(adapter);
        expression.execute(context);
        assertTrue(((WeightedSet<IntegerFieldValue>)adapter.values.get("myInts")).isEmpty());

        myWeightedSet.put(new StringFieldValue("3"), 37);
        adapter.createField(new Field("myWeightedSet", myWeightedSet.getDataType()));
        adapter.setValue("myWeightedSet", myWeightedSet);
        adapter.createField(new Field("myInts", WeightedSetDataType.getWeightedSet(DataType.INT)));

        expression.resolve(adapter);
        expression.execute(context);
        assertEquals(37, ((WeightedSet<IntegerFieldValue>)adapter.values.get("myInts")).get(new IntegerFieldValue(3)).intValue());
    }
@author Simon Thoresen Hult
@author bratseth
indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java