use of org.kie.dmn.feel.lang.ast.StringNode 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(StringNode.class)));
StringNode nameNode = (StringNode) entry.getName();
assertThat(nameNode.getText(), is(notNullValue()));
// Reference String literal test, BaseNode#getText() return the FEEL equivalent expression, in this case quoted.
assertThat(nameNode.getText(), 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)));
NameDefNode 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]"));
}
Aggregations