Search in sources :

Example 6 with DrlxExpression

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

the class DroolsMvelParserTest method testOOPathExprWithDot.

@Test
public void testOOPathExprWithDot() {
    String expr = "/wife.children/toys";
    DrlxExpression drlx = parseExpression(parser, expr);
    Expression expression = drlx.getExpr();
    assertTrue(expression instanceof OOPathExpr);
    assertEquals(expr, printNode(drlx));
}
Also used : DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) OOPathExpr(org.drools.mvel.parser.ast.expr.OOPathExpr) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) Test(org.junit.Test)

Example 7 with DrlxExpression

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

the class DroolsMvelParserTest method testBindingOnRight.

@Test
public void testBindingOnRight() {
    String expr = "$n : name == \"Mario\" && $a : age > 20";
    DrlxExpression drlxExpression = parseExpression(parser, expr);
    Expression bExpr = drlxExpression.getExpr();
    assertTrue(bExpr instanceof BinaryExpr);
    Node left = ((BinaryExpr) bExpr).getLeft();
    assertTrue(left instanceof DrlxExpression);
    DrlxExpression leftExpr = (DrlxExpression) left;
    SimpleName leftBind = leftExpr.getBind();
    assertEquals("$n", leftBind.asString());
    Expression expression = leftExpr.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 DrlxExpression);
    DrlxExpression rightExpr = (DrlxExpression) right;
    SimpleName rightBind = rightExpr.getBind();
    assertEquals("$a", rightBind.asString());
    BinaryExpr binaryExpr2 = ((BinaryExpr) rightExpr.getExpr());
    assertEquals("age", toString(binaryExpr2.getLeft()));
    assertEquals("20", toString(binaryExpr2.getRight()));
    assertEquals(Operator.GREATER, binaryExpr2.getOperator());
}
Also used : DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) Node(com.github.javaparser.ast.Node) SimpleName(com.github.javaparser.ast.expr.SimpleName) Test(org.junit.Test)

Example 8 with DrlxExpression

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

Example 9 with DrlxExpression

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

the class DroolsMvelParserTest method testMapInitializationLiteralAsArgument.

@Test
public void testMapInitializationLiteralAsArgument() {
    String expr = "countItems([123 : 456, 789 : 1011])";
    DrlxExpression drlx = parseExpression(parser, expr);
    assertEquals(expr, printNode(drlx));
}
Also used : DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) Test(org.junit.Test)

Example 10 with DrlxExpression

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

the class DroolsMvelParserTest method testLambda.

@Test
public void testLambda() {
    String expr = "x -> y";
    DrlxExpression expression = parseExpression(parser, expr);
    assertEquals(expr, printNode(expression));
}
Also used : DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) Test(org.junit.Test)

Aggregations

DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)20 Test (org.junit.Test)15 Expression (com.github.javaparser.ast.expr.Expression)13 DrlxParser.parseExpression (org.drools.mvel.parser.DrlxParser.parseExpression)10 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)8 HalfBinaryExpr (org.drools.mvel.parser.ast.expr.HalfBinaryExpr)8 SimpleName (com.github.javaparser.ast.expr.SimpleName)7 OOPathExpr (org.drools.mvel.parser.ast.expr.OOPathExpr)6 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)3 PrintUtil.printNode (org.drools.mvel.parser.printer.PrintUtil.printNode)3 Node (com.github.javaparser.ast.Node)2 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)2 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)2 NameExpr (com.github.javaparser.ast.expr.NameExpr)2 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)2 DrlNameExpr (org.drools.mvel.parser.ast.expr.DrlNameExpr)2 NodeList (com.github.javaparser.ast.NodeList)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 AND (com.github.javaparser.ast.expr.BinaryExpr.Operator.AND)1 DIVIDE (com.github.javaparser.ast.expr.BinaryExpr.Operator.DIVIDE)1