use of com.github.javaparser.ast.expr.BinaryExpr 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 com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testAndWithImplicitParameter3.
@Test
public void testAndWithImplicitParameter3() {
String expr = "age == 2 && == 3 || == 4";
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("age", toString(first.getLeft()));
assertEquals("2", toString(first.getRight()));
assertEquals(Operator.EQUALS, first.getOperator());
HalfBinaryExpr second = (HalfBinaryExpr) ((BinaryExpr) comboExpr.getLeft()).getRight();
assertEquals("3", toString(second.getRight()));
assertEquals(HalfBinaryExpr.Operator.EQUALS, second.getOperator());
HalfBinaryExpr third = (HalfBinaryExpr) comboExpr.getRight();
assertEquals("4", 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 testAndWithImplicitParameterAndParenthesis.
@Test
public void testAndWithImplicitParameterAndParenthesis() {
String expr = "value (> 1 && < 2)";
Expression expression = parseExpression(parser, expr).getExpr();
BinaryExpr comboExpr = ((BinaryExpr) expression);
assertEquals(Operator.AND, comboExpr.getOperator());
BinaryExpr first = (BinaryExpr) comboExpr.getLeft();
assertEquals("value", toString(first.getLeft()));
assertEquals("1", toString(first.getRight()));
assertEquals(Operator.GREATER, first.getOperator());
HalfBinaryExpr second = (HalfBinaryExpr) comboExpr.getRight();
assertEquals("2", toString(second.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, second.getOperator());
}
use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testAndWithImplicitParameter.
@Test
public void testAndWithImplicitParameter() {
String expr = "name == \"Mark\" && == \"Mario\" && == \"Luca\"";
Expression expression = parseExpression(parser, expr).getExpr();
BinaryExpr comboExpr = ((BinaryExpr) expression);
assertEquals(Operator.AND, comboExpr.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 testAndWithImplicitParameterAndParenthesisOnThis.
@Test
public void testAndWithImplicitParameterAndParenthesisOnThis() {
String expr = "this (> 1 && < 2)";
Expression expression = parseExpression(parser, expr).getExpr();
BinaryExpr comboExpr = ((BinaryExpr) expression);
assertEquals(Operator.AND, comboExpr.getOperator());
BinaryExpr first = (BinaryExpr) comboExpr.getLeft();
assertEquals("this", toString(first.getLeft()));
assertEquals("1", toString(first.getRight()));
assertEquals(Operator.GREATER, first.getOperator());
HalfBinaryExpr second = (HalfBinaryExpr) comboExpr.getRight();
assertEquals("2", toString(second.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, second.getOperator());
}
Aggregations