Search in sources :

Example 6 with HalfBinaryExpr

use of org.drools.mvel.parser.ast.expr.HalfBinaryExpr 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());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

Example 7 with HalfBinaryExpr

use of org.drools.mvel.parser.ast.expr.HalfBinaryExpr 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());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

Example 8 with HalfBinaryExpr

use of org.drools.mvel.parser.ast.expr.HalfBinaryExpr 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());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

Example 9 with HalfBinaryExpr

use of org.drools.mvel.parser.ast.expr.HalfBinaryExpr 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());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

Example 10 with HalfBinaryExpr

use of org.drools.mvel.parser.ast.expr.HalfBinaryExpr in project drools by kiegroup.

the class DroolsMvelParserTest method testAndWithImplicitParameterAndParenthesisMixedRight.

@Test
public void testAndWithImplicitParameterAndParenthesisMixedRight() {
    String expr = "value (< 1 || (> 2 && < 3))";
    Expression expression = parseExpression(parser, expr).getExpr();
    BinaryExpr comboExpr = ((BinaryExpr) expression);
    assertEquals(Operator.OR, comboExpr.getOperator());
    BinaryExpr first = ((BinaryExpr) comboExpr.getLeft());
    assertEquals("value", toString(first.getLeft()));
    assertEquals("1", toString(first.getRight()));
    assertEquals(Operator.LESS, first.getOperator());
    BinaryExpr comboExprRight = ((BinaryExpr) comboExpr.getRight());
    assertEquals(Operator.AND, comboExprRight.getOperator());
    BinaryExpr third = (BinaryExpr) comboExprRight.getLeft();
    assertEquals("value", toString(third.getLeft()));
    assertEquals("2", toString(third.getRight()));
    assertEquals(Operator.GREATER, third.getOperator());
    HalfBinaryExpr forth = (HalfBinaryExpr) comboExprRight.getRight();
    assertEquals("3", toString(forth.getRight()));
    assertEquals(HalfBinaryExpr.Operator.LESS, forth.getOperator());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)17 HalfBinaryExpr (org.drools.mvel.parser.ast.expr.HalfBinaryExpr)17 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)16 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)16 DrlxParser.parseExpression (org.drools.mvel.parser.DrlxParser.parseExpression)13 Test (org.junit.Test)13 NullSafeFieldAccessExpr (org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr)4 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)3 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)3 Node (com.github.javaparser.ast.Node)2 NameExpr (com.github.javaparser.ast.expr.NameExpr)2 NodeList (com.github.javaparser.ast.NodeList)1 NodeList.nodeList (com.github.javaparser.ast.NodeList.nodeList)1 InitializerDeclaration (com.github.javaparser.ast.body.InitializerDeclaration)1 ArrayAccessExpr (com.github.javaparser.ast.expr.ArrayAccessExpr)1 ArrayCreationExpr (com.github.javaparser.ast.expr.ArrayCreationExpr)1 ArrayInitializerExpr (com.github.javaparser.ast.expr.ArrayInitializerExpr)1 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)1 Operator (com.github.javaparser.ast.expr.BinaryExpr.Operator)1 CastExpr (com.github.javaparser.ast.expr.CastExpr)1