Search in sources :

Example 1 with StringNode

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]"));
}
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) StringNode(org.kie.dmn.feel.lang.ast.StringNode) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)1 ContextEntryNode (org.kie.dmn.feel.lang.ast.ContextEntryNode)1 ContextNode (org.kie.dmn.feel.lang.ast.ContextNode)1 IterationContextNode (org.kie.dmn.feel.lang.ast.IterationContextNode)1 NameDefNode (org.kie.dmn.feel.lang.ast.NameDefNode)1 StringNode (org.kie.dmn.feel.lang.ast.StringNode)1