Search in sources :

Example 56 with BaseNode

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

the class FEELParserTest method testPathExpression.

@Test
public void testPathExpression() {
    String inputExpression = "[ 10, 15 ].size";
    BaseNode pathBase = parse(inputExpression);
    assertThat(pathBase, is(instanceOf(PathExpressionNode.class)));
    assertThat(pathBase.getText(), is(inputExpression));
    PathExpressionNode pathExpr = (PathExpressionNode) pathBase;
    assertThat(pathExpr.getExpression(), is(instanceOf(ListNode.class)));
    assertThat(pathExpr.getExpression().getText(), is("10, 15"));
    assertThat(pathExpr.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(pathExpr.getName().getText(), is("size"));
}
Also used : PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 57 with BaseNode

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

the class FEELParserTest method testPower3.

@Test
public void testPower3() {
    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 mult = (InfixOpNode) infix;
    assertThat(mult.getLeft(), is(instanceOf(InfixOpNode.class)));
    assertThat(mult.getLeft().getText(), is("y ** 5"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
    assertThat(mult.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(mult.getRight().getText(), is("3"));
    InfixOpNode exp = (InfixOpNode) mult.getLeft();
    assertThat(exp.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(exp.getLeft().getText(), is("y"));
    assertThat(exp.getOperator(), is(InfixOpNode.InfixOperator.POW));
    assertThat(exp.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(exp.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)

Example 58 with BaseNode

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

the class FEELParserTest method testInstanceOfExpressionAnd.

@Test
public void testInstanceOfExpressionAnd() {
    String inputExpression = "\"foo\" instance of string and 10 instance of number";
    BaseNode andExpr = parse(inputExpression);
    assertThat(andExpr, is(instanceOf(InfixOpNode.class)));
    assertThat(andExpr.getText(), is(inputExpression));
    assertThat(andExpr.getResultType(), is(BuiltInType.BOOLEAN));
    InfixOpNode and = (InfixOpNode) andExpr;
    assertThat(and.getOperator(), is(InfixOpNode.InfixOperator.AND));
    assertThat(and.getLeft(), is(instanceOf(InstanceOfNode.class)));
    assertThat(and.getRight(), is(instanceOf(InstanceOfNode.class)));
    assertThat(and.getLeft().getText(), is("\"foo\" instance of string"));
    assertThat(and.getRight().getText(), is("10 instance of number"));
    assertThat(and.getLeft().getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(and.getRight().getResultType(), is(BuiltInType.BOOLEAN));
    InstanceOfNode ioExpr = (InstanceOfNode) and.getLeft();
    assertThat(ioExpr.getExpression(), is(instanceOf(StringNode.class)));
    assertThat(ioExpr.getExpression().getText(), is("\"foo\""));
    assertThat(ioExpr.getType(), is(instanceOf(TypeNode.class)));
    assertThat(ioExpr.getType().getText(), is("string"));
    ioExpr = (InstanceOfNode) and.getRight();
    assertThat(ioExpr.getExpression(), is(instanceOf(NumberNode.class)));
    assertThat(ioExpr.getExpression().getText(), is("10"));
    assertThat(ioExpr.getType(), is(instanceOf(TypeNode.class)));
    assertThat(ioExpr.getType().getText(), is("number"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) InstanceOfNode(org.kie.dmn.feel.lang.ast.InstanceOfNode) Test(org.junit.Test)

Example 59 with BaseNode

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

the class FEELParserTest method testConditionalLogicalOp.

@Test
public void testConditionalLogicalOp() {
    String inputExpression = "foo < 10 and bar = \"x\" or baz";
    BaseNode infix = parse(inputExpression);
    assertThat(infix, is(instanceOf(InfixOpNode.class)));
    assertThat(infix.getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(infix.getText(), is(inputExpression));
    InfixOpNode or = (InfixOpNode) infix;
    assertThat(or.getLeft(), is(instanceOf(InfixOpNode.class)));
    assertThat(or.getLeft().getText(), is("foo < 10 and bar = \"x\""));
    assertThat(or.getOperator(), is(InfixOpNode.InfixOperator.OR));
    assertThat(or.getRight(), is(instanceOf(NameRefNode.class)));
    assertThat(or.getRight().getText(), is("baz"));
    InfixOpNode and = (InfixOpNode) or.getLeft();
    assertThat(and.getLeft(), is(instanceOf(InfixOpNode.class)));
    assertThat(and.getLeft().getText(), is("foo < 10"));
    assertThat(and.getOperator(), is(InfixOpNode.InfixOperator.AND));
    assertThat(and.getRight(), is(instanceOf(InfixOpNode.class)));
    assertThat(and.getRight().getText(), is("bar = \"x\""));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 60 with BaseNode

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

the class FEELParserTest method testIntegerLiteral.

@Test
public void testIntegerLiteral() {
    String inputExpression = "10";
    BaseNode number = parse(inputExpression);
    assertThat(number, is(instanceOf(NumberNode.class)));
    assertThat(number.getResultType(), is(BuiltInType.NUMBER));
    assertLocation(inputExpression, number);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) 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