Search in sources :

Example 1 with FunctionInvocationNode

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

the class FEELParserTest method testFunctionDecisionTableInvocation.

@Ignore("dropped since DMNv1.2")
@Test
public void testFunctionDecisionTableInvocation() {
    String inputExpression = "decision table( " + "    outputs: \"Applicant Risk Rating\"," + "    input expression list: [\"Applicant Age\", \"Medical History\"]," + "    rule list: [" + "        [ >60      , \"good\" , \"Medium\" ]," + "        [ >60      , \"bad\"  , \"High\"   ]," + // also another problem is the - operator cannot be inside of expression.
    "        [ [25..60] , -        , \"Medium\" ]," + "        [ <25      , \"good\" , \"Low\"    ]," + "        [ <25      , \"bad\"  , \"Medium\" ] ]," + "    hit policy: \"Unique\" )";
    // need to call parse passing in the input variables
    BaseNode functionBase = parse(inputExpression);
    assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(functionBase.getText(), is(inputExpression));
    FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
    assertThat(function.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(function.getName().getText(), is("decision table"));
    assertThat(function.getParams(), is(instanceOf(ListNode.class)));
    assertThat(function.getParams().getElements().size(), is(4));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(NamedParameterNode.class)));
    assertThat(function.getParams().getElements().get(1), is(instanceOf(NamedParameterNode.class)));
    assertThat(function.getParams().getElements().get(2), is(instanceOf(NamedParameterNode.class)));
    assertThat(function.getParams().getElements().get(3), is(instanceOf(NamedParameterNode.class)));
    NamedParameterNode named = (NamedParameterNode) function.getParams().getElements().get(0);
    assertThat(named.getText(), is("outputs: \"Applicant Risk Rating\""));
    assertThat(named.getName().getText(), is("outputs"));
    assertThat(named.getExpression(), is(instanceOf(StringNode.class)));
    assertThat(named.getExpression().getText(), is("\"Applicant Risk Rating\""));
    named = (NamedParameterNode) function.getParams().getElements().get(1);
    assertThat(named.getName().getText(), is("input expression list"));
    assertThat(named.getExpression(), is(instanceOf(ListNode.class)));
    ListNode list = (ListNode) named.getExpression();
    assertThat(list.getElements().size(), is(2));
    assertThat(list.getElements().get(0), is(instanceOf(StringNode.class)));
    assertThat(list.getElements().get(0).getText(), is("\"Applicant Age\""));
    assertThat(list.getElements().get(1), is(instanceOf(StringNode.class)));
    assertThat(list.getElements().get(1).getText(), is("\"Medical History\""));
    named = (NamedParameterNode) function.getParams().getElements().get(2);
    assertThat(named.getName().getText(), is("rule list"));
    assertThat(named.getExpression(), is(instanceOf(ListNode.class)));
    list = (ListNode) named.getExpression();
    // this assert on the 5 rows but third row contains the - operation which is not allowed in expression.
    assertThat(list.getElements().size(), is(5));
    assertThat(list.getElements().get(0), is(instanceOf(ListNode.class)));
    ListNode rule = (ListNode) list.getElements().get(0);
    assertThat(rule.getElements().size(), is(3));
    assertThat(rule.getElements().get(0), is(instanceOf(RangeNode.class)));
    assertThat(rule.getElements().get(0).getText(), is(">60"));
    assertThat(rule.getElements().get(1), is(instanceOf(StringNode.class)));
    assertThat(rule.getElements().get(1).getText(), is("\"good\""));
    assertThat(rule.getElements().get(2), is(instanceOf(StringNode.class)));
    assertThat(rule.getElements().get(2).getText(), is("\"Medium\""));
    named = (NamedParameterNode) function.getParams().getElements().get(3);
    assertThat(named.getName().getText(), is("hit policy"));
    assertThat(named.getExpression(), is(instanceOf(StringNode.class)));
    assertThat(named.getExpression().getText(), is("\"Unique\""));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) NamedParameterNode(org.kie.dmn.feel.lang.ast.NamedParameterNode) ListNode(org.kie.dmn.feel.lang.ast.ListNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with FunctionInvocationNode

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

the class TemporalConstantFoldingParserTest method testKie.

@Test
public void testKie() {
    CompilerContext ctx = FEEL_KIE.newCompilerContext();
    CompiledExpression compile = FEEL_KIE.compile(expression, ctx);
    ASTNode ast = extractAST(compile);
    assertThat(ast).isInstanceOf(FunctionInvocationNode.class);
    assertThat(((FunctionInvocationNode) ast).getTcFolded()).isNotNull();
}
Also used : CompilerContext(org.kie.dmn.feel.lang.CompilerContext) ASTNode(org.kie.dmn.feel.lang.ast.ASTNode) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 3 with FunctionInvocationNode

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

the class TemporalConstantFoldingParserTest method testStrict.

@Test
public void testStrict() {
    CompilerContext ctx = FEEL_STRICT.newCompilerContext();
    CompiledExpression compile = FEEL_STRICT.compile(expression, ctx);
    ASTNode ast = extractAST(compile);
    assertThat(ast).isInstanceOf(FunctionInvocationNode.class);
    assertThat(((FunctionInvocationNode) ast).getTcFolded()).isNotNull();
}
Also used : CompilerContext(org.kie.dmn.feel.lang.CompilerContext) ASTNode(org.kie.dmn.feel.lang.ast.ASTNode) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 4 with FunctionInvocationNode

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

the class FEELParserTest method testFunctionInvocationWithKeyword.

@Test
public void testFunctionInvocationWithKeyword() {
    String inputExpression = "date and time( \"2016-07-29T19:47:53\" )";
    BaseNode functionBase = parse(inputExpression);
    assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(functionBase.getText(), is(inputExpression));
    FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
    assertThat(function.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(function.getName().getText(), is("date and time"));
    assertThat(function.getParams(), is(instanceOf(ListNode.class)));
    assertThat(function.getParams().getElements().size(), is(1));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(StringNode.class)));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 5 with FunctionInvocationNode

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

the class FEELParserTest method testFunctionInvocationEmptyParams.

@Test
public void testFunctionInvocationEmptyParams() {
    String inputExpression = "my.test.Function()";
    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(), is(empty()));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) 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