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