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