Search in sources :

Example 26 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELParserTest method testNegativeIntegerLiteral.

@Test
public void testNegativeIntegerLiteral() {
    String inputExpression = "-10";
    BaseNode number = parse(inputExpression);
    assertThat(number, is(instanceOf(SignedUnaryNode.class)));
    assertThat(number.getResultType(), is(BuiltInType.NUMBER));
    assertLocation(inputExpression, number);
    SignedUnaryNode sun = (SignedUnaryNode) number;
    assertThat(sun.getSign(), is(SignedUnaryNode.Sign.NEGATIVE));
    assertThat(sun.getExpression(), is(instanceOf(NumberNode.class)));
    assertThat(sun.getExpression().getText(), is("10"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) SignedUnaryNode(org.kie.dmn.feel.lang.ast.SignedUnaryNode) Test(org.junit.Test)

Example 27 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELParserTest method testQuantifiedExpressionEvery.

@Test
public void testQuantifiedExpressionEvery() {
    String inputExpression = "every item in order.items satisfies item.price > 100";
    BaseNode everyBase = parse(inputExpression);
    assertThat(everyBase, is(instanceOf(QuantifiedExpressionNode.class)));
    assertThat(everyBase.getText(), is(inputExpression));
    assertThat(everyBase.getResultType(), is(BuiltInType.BOOLEAN));
    QuantifiedExpressionNode everyExpr = (QuantifiedExpressionNode) everyBase;
    assertThat(everyExpr.getQuantifier(), is(QuantifiedExpressionNode.Quantifier.EVERY));
    assertThat(everyExpr.getIterationContexts().size(), is(1));
    assertThat(everyExpr.getIterationContexts().get(0).getText(), is("item in order.items"));
    assertThat(everyExpr.getExpression().getText(), is("item.price > 100"));
}
Also used : QuantifiedExpressionNode(org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 28 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELParserTest method testFunctionDefinition.

@Test
public void testFunctionDefinition() {
    String inputExpression = "{ is minor : function( person's age ) person's age < 21 }";
    BaseNode ctxbase = parse(inputExpression);
    assertThat(ctxbase, is(instanceOf(ContextNode.class)));
    assertThat(ctxbase.getText(), is(inputExpression));
    ContextNode ctx = (ContextNode) ctxbase;
    assertThat(ctx.getEntries().size(), is(1));
    ContextEntryNode entry = ctx.getEntries().get(0);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    NameDefNode name = (NameDefNode) entry.getName();
    assertThat(name.getText(), is("is minor"));
    assertThat(entry.getValue(), is(instanceOf(FunctionDefNode.class)));
    assertThat(entry.getValue().getText(), is("function( person's age ) person's age < 21"));
    FunctionDefNode isMinorFunc = (FunctionDefNode) entry.getValue();
    assertThat(isMinorFunc.getFormalParameters().size(), is(1));
    assertThat(isMinorFunc.getFormalParameters().get(0).getText(), is("person's age"));
    assertThat(isMinorFunc.isExternal(), is(false));
    assertThat(isMinorFunc.getBody(), is(instanceOf(InfixOpNode.class)));
}
Also used : FunctionDefNode(org.kie.dmn.feel.lang.ast.FunctionDefNode) NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) IterationContextNode(org.kie.dmn.feel.lang.ast.IterationContextNode) ContextNode(org.kie.dmn.feel.lang.ast.ContextNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) Test(org.junit.Test)

Example 29 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELParserTest method testNestedContexts2.

@Test
public void testNestedContexts2() {
    String inputExpression = "{ an applicant : { " + "    home address : {" + "        street name: \"broadway st\"," + "        city : \"New York\" " + "    } " + " },\n " + " street : an applicant.home address.street name \n" + "}";
    BaseNode ctxbase = parse(inputExpression);
    assertThat(ctxbase, is(instanceOf(ContextNode.class)));
    assertThat(ctxbase.getText(), is(inputExpression));
    ContextNode ctx = (ContextNode) ctxbase;
    assertThat(ctx.getEntries().size(), is(2));
    ContextEntryNode entry = ctx.getEntries().get(1);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.STRING));
    NameDefNode name = (NameDefNode) entry.getName();
    assertThat(name.getText(), is("street"));
    assertThat(entry.getValue(), is(instanceOf(QualifiedNameNode.class)));
    QualifiedNameNode qnn = (QualifiedNameNode) entry.getValue();
    assertThat(qnn.getParts().get(0).getText(), is("an applicant"));
    assertThat(qnn.getParts().get(1).getText(), is("home address"));
    assertThat(qnn.getParts().get(2).getText(), is("street name"));
}
Also used : NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) IterationContextNode(org.kie.dmn.feel.lang.ast.IterationContextNode) ContextNode(org.kie.dmn.feel.lang.ast.ContextNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) QualifiedNameNode(org.kie.dmn.feel.lang.ast.QualifiedNameNode) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) Test(org.junit.Test)

Example 30 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELParserTest method testFunctionInvocationWithKeyword.

@Test
public void testFunctionInvocationWithKeyword() {
    String inputExpression = "date and time( \"2016-07-29T19:47:53\" )";
    BaseNode functionBase = parse(inputExpression);
    assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(functionBase.getText(), is(inputExpression));
    FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
    assertThat(function.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(function.getName().getText(), is("date and time"));
    assertThat(function.getParams(), is(instanceOf(ListNode.class)));
    assertThat(function.getParams().getElements().size(), is(1));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(StringNode.class)));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Aggregations

BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)84 Test (org.junit.Test)54 ListNode (org.kie.dmn.feel.lang.ast.ListNode)12 InfixOpNode (org.kie.dmn.feel.lang.ast.InfixOpNode)11 FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)7 IterationContextNode (org.kie.dmn.feel.lang.ast.IterationContextNode)7 NameDefNode (org.kie.dmn.feel.lang.ast.NameDefNode)7 ContextEntryNode (org.kie.dmn.feel.lang.ast.ContextEntryNode)6 ContextNode (org.kie.dmn.feel.lang.ast.ContextNode)6 PathExpressionNode (org.kie.dmn.feel.lang.ast.PathExpressionNode)4 SignedUnaryNode (org.kie.dmn.feel.lang.ast.SignedUnaryNode)4 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 InNode (org.kie.dmn.feel.lang.ast.InNode)3 InstanceOfNode (org.kie.dmn.feel.lang.ast.InstanceOfNode)3 RangeNode (org.kie.dmn.feel.lang.ast.RangeNode)3 ArrayList (java.util.ArrayList)2 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)2 FunctionDefNode (org.kie.dmn.feel.lang.ast.FunctionDefNode)2 NamedParameterNode (org.kie.dmn.feel.lang.ast.NamedParameterNode)2 QualifiedNameNode (org.kie.dmn.feel.lang.ast.QualifiedNameNode)2