use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class TemporalConstantFoldingParserTest method testStrict.
@Test
public void testStrict() {
CompilerContext ctx = FEEL_STRICT.newCompilerContext();
CompiledExpression compile = FEEL_STRICT.compile(expression, ctx);
ASTNode ast = extractAST(compile);
assertThat(ast).isInstanceOf(FunctionInvocationNode.class);
assertThat(((FunctionInvocationNode) ast).getTcFolded()).isNotNull();
}
use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class FEELParserSeverityTest method parseSeverity.
private ASTNode parseSeverity(String input, FEELEvent.Severity severity) {
FEELEventListenersManager mgr = new FEELEventListenersManager();
CompilerContext ctx = new CompilerContextImpl(mgr);
final FEELEventListener listener = mock(FEELEventListener.class);
mgr.addListener(listener);
mgr.addListener(e -> LOG.info("{}", e));
ProcessedExpression processedExpression = new ProcessedExpression(input, ctx, ProcessedFEELUnit.DefaultMode.Interpreted, Collections.emptyList());
final ArgumentCaptor<FEELEvent> captor = ArgumentCaptor.forClass(FEELEvent.class);
verify(listener, atLeastOnce()).onEvent(captor.capture());
assertThat(captor.getValue().getSeverity(), is(severity));
return processedExpression.getInterpreted().getASTNode();
}
use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class FEELErrorMessagesTest method unknownVariable.
@Test
public void unknownVariable() {
final FEEL feel = FEEL.newInstance();
final FEELEventListener fel = Mockito.mock(FEELEventListener.class);
feel.addListener(fel);
final CompilerContext ctx = feel.newCompilerContext();
feel.compile("a variable name", ctx);
final ArgumentCaptor<FEELEvent> captor = ArgumentCaptor.forClass(FEELEvent.class);
verify(fel, times(2)).onEvent(captor.capture());
Assert.assertThat(captor.getAllValues().size(), is(2));
Assert.assertThat(captor.getAllValues().get(1), is(instanceOf(UnknownVariableErrorEvent.class)));
Assert.assertThat(((UnknownVariableErrorEvent) captor.getAllValues().get(1)).getOffendingSymbol(), is("a variable name"));
}
use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class FEELErrorMessagesTest method ifWithoutElse.
@Test
public void ifWithoutElse() {
final FEEL feel = FEEL.newInstance();
final FEELEventListener fel = Mockito.mock(FEELEventListener.class);
feel.addListener(fel);
final CompilerContext ctx = feel.newCompilerContext();
feel.compile("if true then 123", ctx);
final ArgumentCaptor<FEELEvent> captor = ArgumentCaptor.forClass(FEELEvent.class);
verify(fel, times(1)).onEvent(captor.capture());
Assert.assertThat(captor.getAllValues().size(), is(1));
Assert.assertThat(captor.getAllValues().get(0), is(instanceOf(SyntaxErrorEvent.class)));
Assert.assertThat(((SyntaxErrorEvent) captor.getAllValues().get(0)).getMessage(), startsWith("Detected 'if' expression without 'else' part"));
}
use of org.kie.dmn.feel.lang.CompilerContext in project drools by kiegroup.
the class FEELErrorMessagesTest method ifWithoutThen.
@Test
public void ifWithoutThen() {
final FEEL feel = FEEL.newInstance();
final FEELEventListener fel = Mockito.mock(FEELEventListener.class);
feel.addListener(fel);
final CompilerContext ctx = feel.newCompilerContext();
feel.compile("if true", ctx);
final ArgumentCaptor<FEELEvent> captor = ArgumentCaptor.forClass(FEELEvent.class);
verify(fel, times(1)).onEvent(captor.capture());
Assert.assertThat(captor.getAllValues().size(), is(1));
Assert.assertThat(captor.getAllValues().get(0), is(instanceOf(SyntaxErrorEvent.class)));
Assert.assertThat(((SyntaxErrorEvent) captor.getAllValues().get(0)).getMessage(), startsWith("Detected 'if' expression without 'then' part"));
}
Aggregations