Search in sources :

Example 66 with BaseNode

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

the class FEELParserTest method testIfExpression.

@Test
public void testIfExpression() {
    String inputExpression = "if applicant.age < 18 then \"declined\" else \"accepted\"";
    BaseNode ifBase = parse(inputExpression);
    assertThat(ifBase, is(instanceOf(IfExpressionNode.class)));
    assertThat(ifBase.getText(), is(inputExpression));
    assertThat(ifBase.getResultType(), is(BuiltInType.STRING));
    IfExpressionNode ifExpr = (IfExpressionNode) ifBase;
    assertThat(ifExpr.getCondition().getText(), is("applicant.age < 18"));
    assertThat(ifExpr.getThenExpression().getText(), is("\"declined\""));
    assertThat(ifExpr.getElseExpression().getText(), is("\"accepted\""));
}
Also used : IfExpressionNode(org.kie.dmn.feel.lang.ast.IfExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 67 with BaseNode

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

the class FEELParserTest method testPower4.

@Test
public void testPower4() {
    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 exp = (InfixOpNode) infix;
    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(InfixOpNode.class)));
    assertThat(exp.getRight().getText(), is("5 * 3"));
    InfixOpNode mult = (InfixOpNode) exp.getRight();
    assertThat(mult.getLeft(), is(instanceOf(NumberNode.class)));
    assertThat(mult.getLeft().getText(), is("5"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
    assertThat(mult.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(mult.getRight().getText(), is("3"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 68 with BaseNode

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

the class FEELParserTest method testNegativeFloatLiteral.

@Test
public void testNegativeFloatLiteral() {
    String inputExpression = "-10.5";
    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.NEGATIVE));
    assertThat(sun.getExpression(), is(instanceOf(NumberNode.class)));
    assertThat(sun.getExpression().getText(), is("10.5"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) SignedUnaryNode(org.kie.dmn.feel.lang.ast.SignedUnaryNode) Test(org.junit.Test)

Example 69 with BaseNode

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

the class FEELParserTest method testStringLiteral.

@Test
public void testStringLiteral() {
    String inputExpression = "\"some string\"";
    BaseNode stringLit = parse(inputExpression);
    assertThat(stringLit, is(instanceOf(StringNode.class)));
    assertThat(stringLit.getResultType(), is(BuiltInType.STRING));
    assertLocation(inputExpression, stringLit);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 70 with BaseNode

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

the class FEELParserTest method testPower2.

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