use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class DroolsMvelParserTest method testEnclosedBindVariable.
@Test
public void testEnclosedBindVariable() {
String expr = "($n : name == \"Mario\")";
DrlxExpression drlxExpression = parseExpression(parser, expr);
Expression enclosedExpr = drlxExpression.getExpr();
assertTrue(enclosedExpr instanceof EnclosedExpr);
Expression inner = ((EnclosedExpr) enclosedExpr).getInner();
assertTrue(inner instanceof DrlxExpression);
DrlxExpression innerDrlxExpression = (DrlxExpression) inner;
SimpleName bind = innerDrlxExpression.getBind();
assertEquals("$n", bind.asString());
Expression expression = innerDrlxExpression.getExpr();
BinaryExpr binaryExpr = ((BinaryExpr) expression);
assertEquals("name", toString(binaryExpr.getLeft()));
assertEquals("\"Mario\"", toString(binaryExpr.getRight()));
assertEquals(Operator.EQUALS, binaryExpr.getOperator());
}
use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class DroolsMvelParserTest method testComplexEnclosedBindVariable.
@Test
public void testComplexEnclosedBindVariable() {
String expr = "($n : name == \"Mario\") && (age > 20)";
DrlxExpression drlxExpression = parseExpression(parser, expr);
Expression bExpr = drlxExpression.getExpr();
assertTrue(bExpr instanceof BinaryExpr);
Node left = ((BinaryExpr) bExpr).getLeft();
assertTrue(left instanceof EnclosedExpr);
Expression inner = ((EnclosedExpr) left).getInner();
assertTrue(inner instanceof DrlxExpression);
DrlxExpression innerDrlxExpression = (DrlxExpression) inner;
SimpleName bind = innerDrlxExpression.getBind();
assertEquals("$n", bind.asString());
Expression expression = innerDrlxExpression.getExpr();
BinaryExpr binaryExpr = ((BinaryExpr) expression);
assertEquals("name", toString(binaryExpr.getLeft()));
assertEquals("\"Mario\"", toString(binaryExpr.getRight()));
assertEquals(Operator.EQUALS, binaryExpr.getOperator());
Node right = ((BinaryExpr) bExpr).getRight();
assertTrue(right instanceof EnclosedExpr);
Expression expression2 = ((EnclosedExpr) right).getInner();
BinaryExpr binaryExpr2 = ((BinaryExpr) expression2);
assertEquals("age", toString(binaryExpr2.getLeft()));
assertEquals("20", toString(binaryExpr2.getRight()));
assertEquals(Operator.GREATER, binaryExpr2.getOperator());
}
use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class DroolsMvelParserTest method testOOPathExprWithMultipleCondition.
@Test
public void testOOPathExprWithMultipleCondition() {
String expr = "$address : /address[street == \"Elm\",city == \"Big City\"]";
DrlxExpression drlx = parseExpression(parser, expr);
Expression expression = drlx.getExpr();
assertTrue(expression instanceof OOPathExpr);
assertEquals(expr, printNode(drlx));
}
use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class DroolsMvelParserTest method testOOPathExpr.
@Test
public void testOOPathExpr() {
String expr = "/wife/children[age > 10]/toys";
DrlxExpression drlx = parseExpression(parser, expr);
Expression expression = drlx.getExpr();
assertTrue(expression instanceof OOPathExpr);
assertEquals(expr, printNode(drlx));
}
use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class DroolsMvelParserTest method testLambdaParameter.
@Test
public void testLambdaParameter() {
String expr = "($p).setCanDrinkLambda(() -> true)";
DrlxExpression expression = parseExpression(parser, expr);
assertEquals(expr, printNode(expression));
}
Aggregations