Search in sources :

Example 11 with InfixOpNode

use of org.kie.dmn.feel.lang.ast.InfixOpNode 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

Test (org.junit.Test)11 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)11 InfixOpNode (org.kie.dmn.feel.lang.ast.InfixOpNode)11 InstanceOfNode (org.kie.dmn.feel.lang.ast.InstanceOfNode)1