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"));
}
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"));
}
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"));
}
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"));
}
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"));
}
Aggregations