Search in sources :

Example 36 with BaseNode

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

the class FEELParserTest method testFunctionInvocationWithExpressionParameters.

@Test
public void testFunctionInvocationWithExpressionParameters() {
    String inputExpression = "date and time( date(\"2016-07-29\"), time(\"19: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(2));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(FunctionInvocationNode.class)));
    assertThat(function.getParams().getElements().get(1), is(instanceOf(FunctionInvocationNode.class)));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 37 with BaseNode

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

the class FEELParserTest method testQuantifiedExpressionSome.

@Test
public void testQuantifiedExpressionSome() {
    String inputExpression = "some item in order.items satisfies item.price > 100";
    BaseNode someBase = parse(inputExpression);
    assertThat(someBase, is(instanceOf(QuantifiedExpressionNode.class)));
    assertThat(someBase.getText(), is(inputExpression));
    assertThat(someBase.getResultType(), is(BuiltInType.BOOLEAN));
    QuantifiedExpressionNode someExpr = (QuantifiedExpressionNode) someBase;
    assertThat(someExpr.getQuantifier(), is(QuantifiedExpressionNode.Quantifier.SOME));
    assertThat(someExpr.getIterationContexts().size(), is(1));
    assertThat(someExpr.getIterationContexts().get(0).getText(), is("item in order.items"));
    assertThat(someExpr.getExpression().getText(), is("item.price > 100"));
}
Also used : QuantifiedExpressionNode(org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 38 with BaseNode

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

the class FEELParserTest method testParensWithLiteral.

@Test
public void testParensWithLiteral() {
    String inputExpression = "(10.5 )";
    BaseNode number = parse(inputExpression);
    assertThat(number, is(instanceOf(NumberNode.class)));
    assertThat(number.getResultType(), is(BuiltInType.NUMBER));
    assertThat(number.getText(), is("10.5"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 39 with BaseNode

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

the class FEELParserTest method testInUnaryTest.

@Test
public void testInUnaryTest() {
    String inputExpression = "x - y in [(10+5)..(a*b))";
    BaseNode inNode = parse(inputExpression);
    assertThat(inNode, is(instanceOf(InNode.class)));
    assertThat(inNode.getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(inNode.getText(), is(inputExpression));
    InNode in = (InNode) inNode;
    assertThat(in.getValue(), is(instanceOf(InfixOpNode.class)));
    assertThat(in.getValue().getText(), is("x - y"));
    assertThat(in.getExprs(), is(instanceOf(RangeNode.class)));
    assertThat(in.getExprs().getText(), is("[(10+5)..(a*b))"));
}
Also used : InNode(org.kie.dmn.feel.lang.ast.InNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 40 with BaseNode

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

the class FEELParserTest method testPositiveIntegerLiteral.

@Test
public void testPositiveIntegerLiteral() {
    String inputExpression = "+10";
    BaseNode number = parse(inputExpression);
    assertThat(number, is(instanceOf(SignedUnaryNode.class)));
    assertThat(number.getResultType(), is(BuiltInType.NUMBER));
    assertLocation(inputExpression, number);
    SignedUnaryNode sun = (SignedUnaryNode) number;
    assertThat(sun.getSign(), is(SignedUnaryNode.Sign.POSITIVE));
    assertThat(sun.getExpression(), is(instanceOf(NumberNode.class)));
    assertThat(sun.getExpression().getText(), is("10"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) SignedUnaryNode(org.kie.dmn.feel.lang.ast.SignedUnaryNode) Test(org.junit.Test)

Aggregations

BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)84 Test (org.junit.Test)54 ListNode (org.kie.dmn.feel.lang.ast.ListNode)12 InfixOpNode (org.kie.dmn.feel.lang.ast.InfixOpNode)11 FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)7 IterationContextNode (org.kie.dmn.feel.lang.ast.IterationContextNode)7 NameDefNode (org.kie.dmn.feel.lang.ast.NameDefNode)7 ContextEntryNode (org.kie.dmn.feel.lang.ast.ContextEntryNode)6 ContextNode (org.kie.dmn.feel.lang.ast.ContextNode)6 PathExpressionNode (org.kie.dmn.feel.lang.ast.PathExpressionNode)4 SignedUnaryNode (org.kie.dmn.feel.lang.ast.SignedUnaryNode)4 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 InNode (org.kie.dmn.feel.lang.ast.InNode)3 InstanceOfNode (org.kie.dmn.feel.lang.ast.InstanceOfNode)3 RangeNode (org.kie.dmn.feel.lang.ast.RangeNode)3 ArrayList (java.util.ArrayList)2 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)2 FunctionDefNode (org.kie.dmn.feel.lang.ast.FunctionDefNode)2 NamedParameterNode (org.kie.dmn.feel.lang.ast.NamedParameterNode)2 QualifiedNameNode (org.kie.dmn.feel.lang.ast.QualifiedNameNode)2