@Test
    public void testFunctionInTensorSerialization() throws ParseException {
        List<ExpressionFunction> functions = new ArrayList<>();
        functions.add(new ExpressionFunction("scalarFunction", List.of(), new RankingExpression("5")));
        functions.add(new ExpressionFunction("tensorFunction", List.of(), new RankingExpression("tensor(x[3]):[1, 2, 3]")));

        // Getting a value from a tensor supplied by a function, inside a tensor generate function
        assertSerialization(List.of("tensor(x[3])((rankingExpression(tensorFunction)[x]))"),
                            "tensor(x[3])(tensorFunction[x])",
                            functions, false);

        // Getting a value from a tensor supplied by a function, where the value index is supplied by a function, inside a tensor generate function, short form
        assertSerialization(List.of("tensor(x[3])((rankingExpression(tensorFunction)[(rankingExpression(scalarFunction))]))"),
                            "tensor(x[3])(tensorFunction[scalarFunction()])",
                            functions, false);

        // 'scalarFunction'  is interpreted as a label here since it is the short form of a mapped dimension
        assertSerialization(List.of("tensor(x[3])((rankingExpression(tensorFunction){scalarFunction}))"),
                            "tensor(x[3])(tensorFunction{scalarFunction})",
                            functions, false);

        // Getting a value from a tensor supplied by a function, where the value index is supplied by a function, inside a tensor generate function, long form
        assertSerialization(List.of("tensor(x[3])((rankingExpression(tensorFunction){x:(rankingExpression(scalarFunction))}))"),
                            "tensor(x[3])(tensorFunction{x:scalarFunction()})",
                            functions, false);

        // 'scalarFunction'  without parentheses is interpreted as a label instead of a reference to the function
        assertSerialization(List.of("tensor(x[3])((rankingExpression(tensorFunction){x:scalarFunction}))"),
                            "tensor(x[3])(tensorFunction{x:scalarFunction})",
                            functions, false);

        // Accessing a function in a dynamic tensor, short form
        assertSerialization(List.of("tensor(x[2]):{{x:0}:(rankingExpression(scalarFunction)),{x:1}:(rankingExpression(scalarFunction))}"),
                            "tensor(x[2]):[scalarFunction(), scalarFunction()]",
                            functions, false);

        // Accessing a function in a dynamic tensor, long form
        assertSerialization(List.of("tensor(x{}):{{x:foo}:(rankingExpression(scalarFunction)),{x:bar}:(rankingExpression(scalarFunction))}"),
                            "tensor(x{}):{{x:foo}:scalarFunction(), {x:bar}:scalarFunction()}",
                            functions, false);

        // Shadowing
        assertSerialization(List.of("tensor(scalarFunction[1])((rankingExpression(tensorFunction){x:(scalarFunction + rankingExpression(scalarFunction))}))"),
                            "tensor(scalarFunction[1])(tensorFunction{x: scalarFunction + scalarFunction()})",
                            functions, true);

    }
@author Simon Thoresen Hult
@author bratseth
searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java