Search in sources :

Example 16 with BaseNode

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

the class FEELParserTest method testContextWithMultipleEntries.

@Test
public void testContextWithMultipleEntries() {
    String inputExpression = "{ \"a string key\" : 10," + " a non-string key : foo+bar," + " a key.with + /' odd chars : [10..50] }";
    BaseNode ctxbase = parse(inputExpression, mapOf(entry("foo", BuiltInType.NUMBER), entry("bar", BuiltInType.NUMBER)));
    assertThat(ctxbase, is(instanceOf(ContextNode.class)));
    assertThat(ctxbase.getText(), is(inputExpression));
    ContextNode ctx = (ContextNode) ctxbase;
    assertThat(ctx.getEntries().size(), is(3));
    ContextEntryNode entry = ctx.getEntries().get(0);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    NameDefNode name = (NameDefNode) entry.getName();
    assertThat(name.getName(), is(notNullValue()));
    assertThat(name.getName(), is("\"a string key\""));
    assertThat(entry.getValue(), is(instanceOf(NumberNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.NUMBER));
    assertThat(entry.getValue().getText(), is("10"));
    entry = ctx.getEntries().get(1);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    name = (NameDefNode) entry.getName();
    assertThat(name.getParts(), is(notNullValue()));
    assertThat(name.getParts().size(), is(5));
    assertThat(entry.getName().getText(), is("a non-string key"));
    assertThat(entry.getValue(), is(instanceOf(InfixOpNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.NUMBER));
    assertThat(entry.getValue().getText(), is("foo+bar"));
    entry = ctx.getEntries().get(2);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    name = (NameDefNode) entry.getName();
    assertThat(name.getParts(), is(notNullValue()));
    assertThat(name.getParts().size(), is(9));
    assertThat(entry.getName().getText(), is("a key.with + /' odd chars"));
    assertThat(entry.getValue(), is(instanceOf(RangeNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.RANGE));
    assertThat(entry.getValue().getText(), is("[10..50]"));
}
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) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) Test(org.junit.Test)

Example 17 with BaseNode

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

the class FEELParserTest method testFilterExpression.

@Test
public void testFilterExpression() {
    String inputExpression = "[ {x:1, y:2}, {x:2, y:3} ][ x=1 ]";
    BaseNode filterBase = parse(inputExpression);
    assertThat(filterBase, is(instanceOf(FilterExpressionNode.class)));
    assertThat(filterBase.getText(), is(inputExpression));
    FilterExpressionNode filter = (FilterExpressionNode) filterBase;
    assertThat(filter.getExpression(), is(instanceOf(ListNode.class)));
    assertThat(filter.getExpression().getText(), is("{x:1, y:2}, {x:2, y:3}"));
    assertThat(filter.getFilter(), is(instanceOf(InfixOpNode.class)));
    assertThat(filter.getFilter().getText(), is("x=1"));
}
Also used : FilterExpressionNode(org.kie.dmn.feel.lang.ast.FilterExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 18 with BaseNode

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

the class FEELParserTest method testFunctionInvocationPositionalParams.

@Test
public void testFunctionInvocationPositionalParams() {
    String inputExpression = "my.test.Function( x+10, \"foo\" )";
    BaseNode functionBase = parse(inputExpression);
    assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(functionBase.getText(), is(inputExpression));
    FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
    assertThat(function.getName(), is(instanceOf(QualifiedNameNode.class)));
    assertThat(function.getName().getText(), is("my.test.Function"));
    assertThat(function.getParams(), is(instanceOf(ListNode.class)));
    assertThat(function.getParams().getElements().size(), is(2));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(InfixOpNode.class)));
    assertThat(function.getParams().getElements().get(1), 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)

Example 19 with BaseNode

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

the class FEELParserTest method testFloatLiteral.

@Test
public void testFloatLiteral() {
    String inputExpression = "10.5";
    BaseNode number = parse(inputExpression);
    assertThat(number, is(instanceOf(NumberNode.class)));
    assertThat(number.getResultType(), is(BuiltInType.NUMBER));
    assertLocation(inputExpression, number);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 20 with BaseNode

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

the class FEELParserTest method testEmptyList.

@Test
public void testEmptyList() {
    String inputExpression = "[]";
    BaseNode list = parse(inputExpression);
    assertThat(list, is(instanceOf(ListNode.class)));
    assertThat(list.getResultType(), is(BuiltInType.LIST));
    assertThat(list.getText(), is(inputExpression));
    ListNode ln = (ListNode) list;
    assertThat(ln.getElements(), is(empty()));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ListNode(org.kie.dmn.feel.lang.ast.ListNode) 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