Search in sources :

Example 11 with FunctionInvocationNode

use of org.kie.dmn.feel.lang.ast.FunctionInvocationNode in project drools by kiegroup.

the class FEELParserTest method testFunctionInvocationNamedParams.

@Test
public void testFunctionInvocationNamedParams() {
    String inputExpression = "my.test.Function( named parameter 1 : x+10, named parameter 2 : \"foo\" )";
    BaseNode functionBase = parse(inputExpression);
    assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(functionBase.getText(), is(inputExpression));
    FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
    assertThat(function.getName(), is(instanceOf(QualifiedNameNode.class)));
    assertThat(function.getName().getText(), is("my.test.Function"));
    assertThat(function.getParams(), is(instanceOf(ListNode.class)));
    assertThat(function.getParams().getElements().size(), is(2));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(NamedParameterNode.class)));
    assertThat(function.getParams().getElements().get(1), is(instanceOf(NamedParameterNode.class)));
    NamedParameterNode named = (NamedParameterNode) function.getParams().getElements().get(0);
    assertThat(named.getText(), is("named parameter 1 : x+10"));
    assertThat(named.getName().getText(), is("named parameter 1"));
    assertThat(named.getExpression(), is(instanceOf(InfixOpNode.class)));
    assertThat(named.getExpression().getText(), is("x+10"));
    named = (NamedParameterNode) function.getParams().getElements().get(1);
    assertThat(named.getText(), is("named parameter 2 : \"foo\""));
    assertThat(named.getName().getText(), is("named parameter 2"));
    assertThat(named.getExpression(), is(instanceOf(StringNode.class)));
    assertThat(named.getExpression().getText(), is("\"foo\""));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) NamedParameterNode(org.kie.dmn.feel.lang.ast.NamedParameterNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Aggregations

FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)11 Test (org.junit.Test)9 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)7 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)2 CompilerContext (org.kie.dmn.feel.lang.CompilerContext)2 ASTNode (org.kie.dmn.feel.lang.ast.ASTNode)2 NamedParameterNode (org.kie.dmn.feel.lang.ast.NamedParameterNode)2 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 Type (org.kie.dmn.feel.lang.Type)1 ListNode (org.kie.dmn.feel.lang.ast.ListNode)1 BuiltInType (org.kie.dmn.feel.lang.types.BuiltInType)1