use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method test3BindingOn3Conditions.
@Test
public void test3BindingOn3Conditions() {
String expr = "$n : name == \"Mario\" && $a : age > 20 && $l : likes != null";
DrlxExpression drlxExpression = parseExpression(parser, expr);
Expression bExpr = drlxExpression.getExpr();
assertTrue(bExpr instanceof BinaryExpr);
Expression left = ((BinaryExpr) bExpr).getLeft();
assertTrue(left instanceof BinaryExpr);
BinaryExpr leftExpr = (BinaryExpr) left;
DrlxExpression first = (DrlxExpression) leftExpr.getLeft();
DrlxExpression second = (DrlxExpression) leftExpr.getRight();
DrlxExpression third = (DrlxExpression) ((BinaryExpr) bExpr).getRight();
SimpleName bind = first.getBind();
assertEquals("$n", bind.asString());
BinaryExpr binaryExpr = ((BinaryExpr) first.getExpr());
assertEquals("name", toString(binaryExpr.getLeft()));
assertEquals("\"Mario\"", toString(binaryExpr.getRight()));
assertEquals(Operator.EQUALS, binaryExpr.getOperator());
bind = second.getBind();
assertEquals("$a", bind.asString());
binaryExpr = ((BinaryExpr) second.getExpr());
assertEquals("age", toString(binaryExpr.getLeft()));
assertEquals("20", toString(binaryExpr.getRight()));
assertEquals(Operator.GREATER, binaryExpr.getOperator());
bind = third.getBind();
assertEquals("$l", bind.asString());
binaryExpr = ((BinaryExpr) third.getExpr());
assertEquals("likes", toString(binaryExpr.getLeft()));
assertEquals("null", toString(binaryExpr.getRight()));
assertEquals(Operator.NOT_EQUALS, binaryExpr.getOperator());
}
use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testAndWithImplicitParameterAndParenthesisComplexOnNullSafeField.
@Test
public void testAndWithImplicitParameterAndParenthesisComplexOnNullSafeField() {
String expr = "value!.length ((> 1 && < 2) || (> 3 && < 4))";
Expression expression = parseExpression(parser, expr).getExpr();
BinaryExpr comboExpr = ((BinaryExpr) expression);
assertEquals(Operator.OR, comboExpr.getOperator());
BinaryExpr comboExprLeft = ((BinaryExpr) comboExpr.getLeft());
assertEquals(Operator.AND, comboExprLeft.getOperator());
BinaryExpr first = (BinaryExpr) comboExprLeft.getLeft();
assertTrue(first.getLeft() instanceof NullSafeFieldAccessExpr);
assertEquals("value!.length", toString(first.getLeft()));
assertEquals("1", toString(first.getRight()));
assertEquals(Operator.GREATER, first.getOperator());
HalfBinaryExpr second = (HalfBinaryExpr) comboExprLeft.getRight();
assertEquals("2", toString(second.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, second.getOperator());
BinaryExpr comboExprRight = ((BinaryExpr) comboExpr.getRight());
assertEquals(Operator.AND, comboExprRight.getOperator());
BinaryExpr third = (BinaryExpr) comboExprRight.getLeft();
assertEquals("value!.length", toString(third.getLeft()));
assertEquals("3", toString(third.getRight()));
assertEquals(Operator.GREATER, third.getOperator());
HalfBinaryExpr forth = (HalfBinaryExpr) comboExprRight.getRight();
assertEquals("4", toString(forth.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, forth.getOperator());
}
use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testAndWithImplicitParameter2.
@Test
public void testAndWithImplicitParameter2() {
String expr = "name == \"Mark\" && == \"Mario\" || == \"Luca\"";
Expression expression = parseExpression(parser, expr).getExpr();
BinaryExpr comboExpr = ((BinaryExpr) expression);
assertEquals(Operator.OR, comboExpr.getOperator());
assertEquals(Operator.AND, ((BinaryExpr) (comboExpr.getLeft())).getOperator());
BinaryExpr first = ((BinaryExpr) ((BinaryExpr) comboExpr.getLeft()).getLeft());
assertEquals("name", toString(first.getLeft()));
assertEquals("\"Mark\"", toString(first.getRight()));
assertEquals(Operator.EQUALS, first.getOperator());
HalfBinaryExpr second = (HalfBinaryExpr) ((BinaryExpr) comboExpr.getLeft()).getRight();
assertEquals("\"Mario\"", toString(second.getRight()));
assertEquals(HalfBinaryExpr.Operator.EQUALS, second.getOperator());
HalfBinaryExpr third = (HalfBinaryExpr) comboExpr.getRight();
assertEquals("\"Luca\"", toString(third.getRight()));
assertEquals(HalfBinaryExpr.Operator.EQUALS, third.getOperator());
}
use of com.github.javaparser.ast.expr.BinaryExpr 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 com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testDotFreeExprWithOr.
@Test
public void testDotFreeExprWithOr() {
String expr = "this after $a || this after $b";
Expression expression = parseExpression(parser, expr).getExpr();
assertTrue(expression instanceof BinaryExpr);
assertEquals(expr, printNode(expression));
}
Aggregations