Search in sources :

Example 6 with CompilerContext

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();
}
Also used : CompilerContext(org.kie.dmn.feel.lang.CompilerContext) ASTNode(org.kie.dmn.feel.lang.ast.ASTNode) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 7 with CompilerContext

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();
}
Also used : CompilerContext(org.kie.dmn.feel.lang.CompilerContext) FEELEventListenersManager(org.kie.dmn.feel.lang.impl.FEELEventListenersManager) ProcessedExpression(org.kie.dmn.feel.codegen.feel11.ProcessedExpression) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) CompilerContextImpl(org.kie.dmn.feel.lang.impl.CompilerContextImpl) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent)

Example 8 with CompilerContext

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"));
}
Also used : FEEL(org.kie.dmn.feel.FEEL) CompilerContext(org.kie.dmn.feel.lang.CompilerContext) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) Test(org.junit.Test)

Example 9 with CompilerContext

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"));
}
Also used : FEEL(org.kie.dmn.feel.FEEL) CompilerContext(org.kie.dmn.feel.lang.CompilerContext) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) Test(org.junit.Test)

Example 10 with CompilerContext

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"));
}
Also used : FEEL(org.kie.dmn.feel.FEEL) CompilerContext(org.kie.dmn.feel.lang.CompilerContext) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) Test(org.junit.Test)

Aggregations

CompilerContext (org.kie.dmn.feel.lang.CompilerContext)21 Test (org.junit.Test)13 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)12 HashMap (java.util.HashMap)10 FEELEvent (org.kie.dmn.api.feel.runtime.events.FEELEvent)6 FEELEventListener (org.kie.dmn.api.feel.runtime.events.FEELEventListener)6 FEEL (org.kie.dmn.feel.FEEL)5 MapBackedType (org.kie.dmn.feel.lang.impl.MapBackedType)5 Map (java.util.Map)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DMNType (org.kie.dmn.api.core.DMNType)2 Type (org.kie.dmn.feel.lang.Type)2 ASTNode (org.kie.dmn.feel.lang.ast.ASTNode)2 FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)2 GenListType (org.kie.dmn.feel.lang.types.GenListType)2 CompiledNetwork (org.drools.ancompiler.CompiledNetwork)1 CompiledNetworkSources (org.drools.ancompiler.CompiledNetworkSources)1 ObjectTypeNodeCompiler (org.drools.ancompiler.ObjectTypeNodeCompiler)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1