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]"));
}
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"));
}
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)));
}
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);
}
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()));
}
Aggregations