use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testNegativeIntegerLiteral.
@Test
public void testNegativeIntegerLiteral() {
String inputExpression = "-10";
BaseNode number = parse(inputExpression);
assertThat(number, is(instanceOf(SignedUnaryNode.class)));
assertThat(number.getResultType(), is(BuiltInType.NUMBER));
assertLocation(inputExpression, number);
SignedUnaryNode sun = (SignedUnaryNode) number;
assertThat(sun.getSign(), is(SignedUnaryNode.Sign.NEGATIVE));
assertThat(sun.getExpression(), is(instanceOf(NumberNode.class)));
assertThat(sun.getExpression().getText(), is("10"));
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testQuantifiedExpressionEvery.
@Test
public void testQuantifiedExpressionEvery() {
String inputExpression = "every item in order.items satisfies item.price > 100";
BaseNode everyBase = parse(inputExpression);
assertThat(everyBase, is(instanceOf(QuantifiedExpressionNode.class)));
assertThat(everyBase.getText(), is(inputExpression));
assertThat(everyBase.getResultType(), is(BuiltInType.BOOLEAN));
QuantifiedExpressionNode everyExpr = (QuantifiedExpressionNode) everyBase;
assertThat(everyExpr.getQuantifier(), is(QuantifiedExpressionNode.Quantifier.EVERY));
assertThat(everyExpr.getIterationContexts().size(), is(1));
assertThat(everyExpr.getIterationContexts().get(0).getText(), is("item in order.items"));
assertThat(everyExpr.getExpression().getText(), is("item.price > 100"));
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testFunctionDefinition.
@Test
public void testFunctionDefinition() {
String inputExpression = "{ is minor : function( person's age ) person's age < 21 }";
BaseNode ctxbase = parse(inputExpression);
assertThat(ctxbase, is(instanceOf(ContextNode.class)));
assertThat(ctxbase.getText(), is(inputExpression));
ContextNode ctx = (ContextNode) ctxbase;
assertThat(ctx.getEntries().size(), is(1));
ContextEntryNode entry = ctx.getEntries().get(0);
assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
NameDefNode name = (NameDefNode) entry.getName();
assertThat(name.getText(), is("is minor"));
assertThat(entry.getValue(), is(instanceOf(FunctionDefNode.class)));
assertThat(entry.getValue().getText(), is("function( person's age ) person's age < 21"));
FunctionDefNode isMinorFunc = (FunctionDefNode) entry.getValue();
assertThat(isMinorFunc.getFormalParameters().size(), is(1));
assertThat(isMinorFunc.getFormalParameters().get(0).getText(), is("person's age"));
assertThat(isMinorFunc.isExternal(), is(false));
assertThat(isMinorFunc.getBody(), is(instanceOf(InfixOpNode.class)));
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testNestedContexts2.
@Test
public void testNestedContexts2() {
String inputExpression = "{ an applicant : { " + " home address : {" + " street name: \"broadway st\"," + " city : \"New York\" " + " } " + " },\n " + " street : an applicant.home address.street name \n" + "}";
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(1);
assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
assertThat(entry.getResultType(), is(BuiltInType.STRING));
NameDefNode name = (NameDefNode) entry.getName();
assertThat(name.getText(), is("street"));
assertThat(entry.getValue(), is(instanceOf(QualifiedNameNode.class)));
QualifiedNameNode qnn = (QualifiedNameNode) entry.getValue();
assertThat(qnn.getParts().get(0).getText(), is("an applicant"));
assertThat(qnn.getParts().get(1).getText(), is("home address"));
assertThat(qnn.getParts().get(2).getText(), is("street name"));
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testFunctionInvocationWithKeyword.
@Test
public void testFunctionInvocationWithKeyword() {
String inputExpression = "date and time( \"2016-07-29T19:47:53\" )";
BaseNode functionBase = parse(inputExpression);
assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
assertThat(functionBase.getText(), is(inputExpression));
FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
assertThat(function.getName(), is(instanceOf(NameRefNode.class)));
assertThat(function.getName().getText(), is("date and time"));
assertThat(function.getParams(), is(instanceOf(ListNode.class)));
assertThat(function.getParams().getElements().size(), is(1));
assertThat(function.getParams().getElements().get(0), is(instanceOf(StringNode.class)));
}
Aggregations