Search in sources :

Example 81 with BaseNode

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

the class FEELParserTest method testContextPathExpression2.

@Test
public void testContextPathExpression2() {
    String inputExpression = "{ x : { y : \"foo\" } }.x.y";
    BaseNode pathBase = parse(inputExpression);
    assertThat(pathBase, is(instanceOf(PathExpressionNode.class)));
    assertThat(pathBase.getText(), is(inputExpression));
    assertThat(pathBase.getResultType(), is(BuiltInType.STRING));
    PathExpressionNode pathExpr = (PathExpressionNode) pathBase;
    assertThat(pathExpr.getExpression(), is(instanceOf(ContextNode.class)));
    assertThat(pathExpr.getExpression().getText(), is("{ x : { y : \"foo\" } }"));
    assertThat(pathExpr.getName(), is(instanceOf(QualifiedNameNode.class)));
    assertThat(pathExpr.getName().getText(), is("x.y"));
}
Also used : PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 82 with BaseNode

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

the class FEELParserTest method testNullLiteral.

@Test
public void testNullLiteral() {
    String inputExpression = "null";
    BaseNode nullLit = parse(inputExpression);
    assertThat(nullLit, is(instanceOf(NullNode.class)));
    assertThat(nullLit.getResultType(), is(BuiltInType.UNKNOWN));
    assertLocation(inputExpression, nullLit);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 83 with BaseNode

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

the class FEELParserTest method testContextPathExpression3.

@Test
public void testContextPathExpression3() {
    String inputExpression = "{ first name : \"bob\" }.first name";
    BaseNode pathBase = parse(inputExpression);
    assertThat(pathBase, is(instanceOf(PathExpressionNode.class)));
    assertThat(pathBase.getText(), is(inputExpression));
    assertThat(pathBase.getResultType(), is(BuiltInType.STRING));
    PathExpressionNode pathExpr = (PathExpressionNode) pathBase;
    assertThat(pathExpr.getExpression(), is(instanceOf(ContextNode.class)));
    assertThat(pathExpr.getExpression().getText(), is("{ first name : \"bob\" }"));
    assertThat(pathExpr.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(pathExpr.getName().getText(), is("first name"));
}
Also used : PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 84 with BaseNode

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

the class FEELParserTest method testSub1.

@Test
public void testSub1() {
    String inputExpression = "(y - 5) ** 3";
    BaseNode infix = parse(inputExpression, mapOf(entry("y", BuiltInType.NUMBER)));
    assertThat(infix, is(instanceOf(InfixOpNode.class)));
    assertThat(infix.getResultType(), is(BuiltInType.NUMBER));
    assertThat(infix.getText(), is(inputExpression));
    InfixOpNode sub = (InfixOpNode) infix;
    assertThat(sub.getLeft(), is(instanceOf(InfixOpNode.class)));
    assertThat(sub.getLeft().getText(), is("y - 5"));
    assertThat(sub.getOperator(), is(InfixOpNode.InfixOperator.POW));
    assertThat(sub.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(sub.getRight().getText(), is("3"));
    InfixOpNode mult = (InfixOpNode) sub.getLeft();
    assertThat(mult.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(mult.getLeft().getText(), is("y"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.SUB));
    assertThat(mult.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(mult.getRight().getText(), is("5"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) 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