use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class CompileEvaluateTest method test2.
@Test
public void test2() {
CompilerContext ctx = feel.newCompilerContext();
ctx.addInputVariableType("MyPerson", new MapBackedType().addField("FullName", BuiltInType.STRING));
CompiledExpression compiledExpression = feel.compile("MyPerson.fullName", ctx);
assertThat(errors.toString(), errors.size(), is(1));
Map<String, Object> inputs = new HashMap<>();
inputs.put("MyPerson", prototype(entry("FullName", "John Doe")));
Object result = feel.evaluate(compiledExpression, inputs);
assertThat(result, nullValue());
}
use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class CompileEvaluateTest method testHyphenInPropertyOfCollectionForAccessor.
@Test
public void testHyphenInPropertyOfCollectionForAccessor() {
MapBackedType compositeType = new MapBackedType().addField("Primary-Key", BuiltInType.STRING).addField("Value", BuiltInType.STRING);
CompilerContext ctx = feel.newCompilerContext();
ctx.addInputVariableType("my input", new GenListType(compositeType));
CompiledExpression compiledExpression = feel.compile("my input[1].Primary-Key", ctx);
assertTrue(errors.isEmpty());
Map<String, Object> inputs = new HashMap<>();
inputs.put("my input", Arrays.asList(prototype(entry("Primary-Key", "k987"))));
Object result = feel.evaluate(compiledExpression, inputs);
assertThat(result, is("k987"));
assertTrue(errors.isEmpty());
}
use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class CompileEvaluateTest method test_isDynamicResolution.
@Test
public void test_isDynamicResolution() {
CompilerContext ctx = feel.newCompilerContext();
ctx.addInputVariableType("Person List", BuiltInType.LIST);
CompiledExpression compiledExpression = feel.compile("Person List[My Variable 1 = \"A\"]", ctx);
assertThat(errors.toString(), errors.size(), is(0));
Map<String, Object> inputs = new HashMap<>();
List<Map<String, ?>> pList = new ArrayList<>();
inputs.put("Person List", pList);
pList.add(prototype(entry("Full Name", "Edson Tirelli"), entry("My Variable 1", "A")));
pList.add(prototype(entry("Full Name", "Matteo Mortari"), entry("My Variable 1", "B")));
Object result = feel.evaluate(compiledExpression, inputs);
assertThat(result, instanceOf(List.class));
assertThat((List<?>) result, hasSize(1));
assertThat(((Map<?, ?>) ((List<?>) result).get(0)).get("Full Name"), is("Edson Tirelli"));
}
use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class CompileEvaluateTest method testHyphenInPropertyOfCollectionForProjection.
@Test
public void testHyphenInPropertyOfCollectionForProjection() {
MapBackedType compositeType = new MapBackedType().addField("Primary-Key", BuiltInType.STRING).addField("Value", BuiltInType.STRING);
CompilerContext ctx = feel.newCompilerContext();
ctx.addInputVariableType("input", new GenListType(compositeType));
CompiledExpression compiledExpression = feel.compile("input.Primary-Key", ctx);
assertTrue(errors.isEmpty());
Map<String, Object> inputs = new HashMap<>();
inputs.put("input", Arrays.asList(prototype(entry("Primary-Key", "k987"))));
Object result = feel.evaluate(compiledExpression, inputs);
assertThat(result, is(Arrays.asList("k987")));
assertTrue(errors.isEmpty());
}
use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class TemporalConstantFoldingParserTest method testKie.
@Test
public void testKie() {
CompilerContext ctx = FEEL_KIE.newCompilerContext();
CompiledExpression compile = FEEL_KIE.compile(expression, ctx);
ASTNode ast = extractAST(compile);
assertThat(ast).isInstanceOf(FunctionInvocationNode.class);
assertThat(((FunctionInvocationNode) ast).getTcFolded()).isNotNull();
}
Aggregations