Search in sources :

Example 1 with InfixOpNode

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

the class FEELParserTest method testAdd1.

@Test
public void testAdd1() {
    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 add = (InfixOpNode) infix;
    assertThat(add.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(add.getLeft().getText(), is("y"));
    assertThat(add.getOperator(), is(InfixOpNode.InfixOperator.ADD));
    assertThat(add.getRight(), is(instanceOf(InfixOpNode.class)));
    assertThat(add.getRight().getText(), is("5 * 3"));
    InfixOpNode mult = (InfixOpNode) add.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 2 with InfixOpNode

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

the class FEELParserTest method testComparisonInFixOp.

@Test
public void testComparisonInFixOp() {
    String inputExpression = "foo >= bar * 10";
    BaseNode infix = parse(inputExpression);
    assertThat(infix, is(instanceOf(InfixOpNode.class)));
    assertThat(infix.getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(infix.getText(), is(inputExpression));
    InfixOpNode in = (InfixOpNode) infix;
    assertThat(in.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(in.getLeft().getText(), is("foo"));
    assertThat(in.getRight(), is(instanceOf(InfixOpNode.class)));
    assertThat(in.getRight().getText(), is("bar * 10"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 3 with InfixOpNode

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

the class FEELParserTest method testPower1.

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

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

the class FEELParserTest method testMultiplication.

@Test
public void testMultiplication() {
    String inputExpression = "10 * x";
    BaseNode infix = parse(inputExpression, mapOf(entry("x", 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(NumberNode.class)));
    assertThat(mult.getLeft().getText(), is("10"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
    assertThat(mult.getRight(), is(instanceOf(NameRefNode.class)));
    assertThat(mult.getRight().getText(), is("x"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 5 with InfixOpNode

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

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