Search in sources :

Example 61 with BaseNode

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

the class FEELParserTest method testInstanceOfExpression.

@Test
public void testInstanceOfExpression() {
    String inputExpression = "\"foo\" instance of string";
    BaseNode instanceOfBase = parse(inputExpression);
    assertThat(instanceOfBase, is(instanceOf(InstanceOfNode.class)));
    assertThat(instanceOfBase.getText(), is(inputExpression));
    assertThat(instanceOfBase.getResultType(), is(BuiltInType.BOOLEAN));
    InstanceOfNode ioExpr = (InstanceOfNode) instanceOfBase;
    assertThat(ioExpr.getExpression(), is(instanceOf(StringNode.class)));
    assertThat(ioExpr.getExpression().getText(), is("\"foo\""));
    assertThat(ioExpr.getType(), is(instanceOf(TypeNode.class)));
    assertThat(ioExpr.getType().getText(), is("string"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InstanceOfNode(org.kie.dmn.feel.lang.ast.InstanceOfNode) Test(org.junit.Test)

Example 62 with BaseNode

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

the class FEELParserTest method testInstanceOfExpressionFunction.

@Test
public void testInstanceOfExpressionFunction() {
    String inputExpression = "duration instance of function";
    BaseNode instanceOfBase = parse(inputExpression);
    assertThat(instanceOfBase, is(instanceOf(InstanceOfNode.class)));
    assertThat(instanceOfBase.getText(), is(inputExpression));
    assertThat(instanceOfBase.getResultType(), is(BuiltInType.BOOLEAN));
    InstanceOfNode ioExpr = (InstanceOfNode) instanceOfBase;
    assertThat(ioExpr.getExpression(), is(instanceOf(NameRefNode.class)));
    assertThat(ioExpr.getExpression().getText(), is("duration"));
    assertThat(ioExpr.getType(), is(instanceOf(TypeNode.class)));
    assertThat(ioExpr.getType().getText(), is("function"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InstanceOfNode(org.kie.dmn.feel.lang.ast.InstanceOfNode) Test(org.junit.Test)

Example 63 with BaseNode

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

the class FEELParserTest method testBooleanFalseLiteral.

@Test
public void testBooleanFalseLiteral() {
    String inputExpression = "false";
    BaseNode bool = parse(inputExpression);
    assertThat(bool, is(instanceOf(BooleanNode.class)));
    assertThat(bool.getResultType(), is(BuiltInType.BOOLEAN));
    assertLocation(inputExpression, bool);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 64 with BaseNode

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

the class FEELParserTest method testDivision.

@Test
public void testDivision() {
    String inputExpression = "y / 5 * ( x )";
    BaseNode infix = parse(inputExpression, mapOf(entry("x", BuiltInType.NUMBER), entry("y", BuiltInType.NUMBER)));
    assertThat(infix, is(instanceOf(InfixOpNode.class)));
    assertThat(infix.getResultType(), is(BuiltInType.NUMBER));
    assertThat(infix.getText(), is(inputExpression));
    InfixOpNode mult = (InfixOpNode) infix;
    assertThat(mult.getLeft(), is(instanceOf(InfixOpNode.class)));
    assertThat(mult.getLeft().getText(), is("y / 5"));
    InfixOpNode div = (InfixOpNode) mult.getLeft();
    assertThat(div.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(div.getLeft().getText(), is("y"));
    assertThat(div.getOperator(), is(InfixOpNode.InfixOperator.DIV));
    assertThat(div.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(div.getRight().getText(), is("5"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
    assertThat(mult.getRight(), is(instanceOf(NameRefNode.class)));
    assertThat(mult.getRight().getText(), is("x"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 65 with BaseNode

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

the class FEELParserTest method testNestedContexts.

@Test
public void testNestedContexts() {
    String inputExpression = "{ a value : 10," + " an applicant : { " + "    first name : \"Edson\", " + "    last + name : \"Tirelli\", " + "    full name : first name + last + name, " + "    address : {" + "        street : \"55 broadway st\"," + "        city : \"New York\" " + "    }, " + "    xxx: last + name" + " } " + "}";
    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(0);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    NameDefNode name = (NameDefNode) entry.getName();
    assertThat(name.getText(), is("a value"));
    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.getText(), is("an applicant"));
    assertThat(entry.getValue(), is(instanceOf(ContextNode.class)));
    ContextNode applicant = (ContextNode) entry.getValue();
    assertThat(applicant.getEntries().size(), is(5));
    assertThat(applicant.getEntries().get(0).getName().getText(), is("first name"));
    assertThat(applicant.getEntries().get(0).getResultType(), is(BuiltInType.STRING));
    assertThat(applicant.getEntries().get(1).getName().getText(), is("last + name"));
    assertThat(applicant.getEntries().get(1).getResultType(), is(BuiltInType.STRING));
    assertThat(applicant.getEntries().get(2).getName().getText(), is("full name"));
    assertThat(applicant.getEntries().get(2).getResultType(), is(BuiltInType.STRING));
    assertThat(applicant.getEntries().get(3).getName().getText(), is("address"));
    assertThat(applicant.getEntries().get(3).getValue(), is(instanceOf(ContextNode.class)));
    ContextNode address = (ContextNode) applicant.getEntries().get(3).getValue();
    assertThat(address.getEntries().size(), is(2));
    assertThat(address.getEntries().get(0).getName().getText(), is("street"));
    assertThat(address.getEntries().get(0).getResultType(), is(BuiltInType.STRING));
    assertThat(address.getEntries().get(1).getName().getText(), is("city"));
    assertThat(address.getEntries().get(0).getResultType(), is(BuiltInType.STRING));
}
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)

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