use of org.kie.workbench.common.dmn.client.widgets.codecompletion.feel.FEELLanguageService.Position in project kie-wb-common by kiegroup.
the class FEELLanguageServiceTest method testGetCandidatesForNumberScenario.
@Test
public void testGetCandidatesForNumberScenario() {
final String expression = "2 + |";
final Position position = new Position(1, expression.indexOf("|"));
final String expressionToParse = expression.replace("|", "");
final List<Variable> variables = asList(new Variable("Decision-1", BuiltInType.STRING), new Variable("Decision-2", BuiltInType.NUMBER), new Variable("Decision-3", BuiltInType.BOOLEAN), new Variable("Decision-4", BuiltInType.NUMBER), new Variable("Decision-5", BuiltInType.DATE));
final List<Candidate> actualCandidates = service.getCandidates(expressionToParse, variables, position);
Assertions.assertThat(actualCandidates).containsExactly(new Candidate("Decision-2", "Decision-2", CompletionItemKind.Variable), new Candidate("Decision-4", "Decision-4", CompletionItemKind.Variable), new Candidate("abs(duration)", "abs($1)", CompletionItemKind.Function), new Candidate("abs(number)", "abs($1)", CompletionItemKind.Function), new Candidate("sum(list)", "sum($1)", CompletionItemKind.Function), new Candidate("not", "not", CompletionItemKind.Keyword), new Candidate("for", "for", CompletionItemKind.Keyword), new Candidate("if", "if", CompletionItemKind.Keyword), new Candidate("some", "some", CompletionItemKind.Keyword), new Candidate("every", "every", CompletionItemKind.Keyword), new Candidate("function", "function", CompletionItemKind.Keyword));
}
use of org.kie.workbench.common.dmn.client.widgets.codecompletion.feel.FEELLanguageService.Position in project kie-wb-common by kiegroup.
the class FEELLanguageServiceTest method testGetCandidatesForVariableScenario.
@Test
@Ignore("DROOLS-6210")
public void testGetCandidatesForVariableScenario() {
final String expression = "Decision-2 + |";
final Position position = new Position(1, expression.indexOf("|"));
final String expressionToParse = expression.replace("|", "");
final List<Variable> variables = asList(new Variable("Decision-1", BuiltInType.STRING), new Variable("Decision-2", BuiltInType.NUMBER), new Variable("Decision-3", BuiltInType.BOOLEAN), new Variable("Decision-4", BuiltInType.NUMBER), new Variable("Decision-5", BuiltInType.DATE));
final List<Candidate> actualCandidates = service.getCandidates(expressionToParse, variables, position);
Assertions.assertThat(actualCandidates).containsExactly(new Candidate("Decision-2", "Decision-2", CompletionItemKind.Variable), new Candidate("Decision-4", "Decision-4", CompletionItemKind.Variable), new Candidate("abs(duration)", "abs($1)", CompletionItemKind.Function), new Candidate("abs(number)", "abs($1)", CompletionItemKind.Function), new Candidate("sum(list)", "sum($1)", CompletionItemKind.Function), new Candidate("not", "not", CompletionItemKind.Keyword), new Candidate("for", "for", CompletionItemKind.Keyword), new Candidate("if", "if", CompletionItemKind.Keyword), new Candidate("some", "some", CompletionItemKind.Keyword), new Candidate("every", "every", CompletionItemKind.Keyword), new Candidate("function", "function", CompletionItemKind.Keyword));
}
use of org.kie.workbench.common.dmn.client.widgets.codecompletion.feel.FEELLanguageService.Position in project kie-wb-common by kiegroup.
the class FEELLanguageServiceTest method testGetCandidatesForStringScenario.
@Test
public void testGetCandidatesForStringScenario() {
final String expression = "\"\" + |";
final Position position = new Position(1, expression.indexOf("|"));
final String expressionToParse = expression.replace("|", "");
final List<Variable> variables = asList(new Variable("Decision-1", BuiltInType.STRING), new Variable("Decision-2", BuiltInType.NUMBER), new Variable("Decision-3", BuiltInType.BOOLEAN), new Variable("Decision-4", BuiltInType.NUMBER), new Variable("Decision-5", BuiltInType.DATE));
final List<Candidate> actualCandidates = service.getCandidates(expressionToParse, variables, position);
Assertions.assertThat(actualCandidates).containsExactly(new Candidate("Decision-1", "Decision-1", CompletionItemKind.Variable), new Candidate("string(number)", "string($1)", CompletionItemKind.Function), new Candidate("not", "not", CompletionItemKind.Keyword), new Candidate("for", "for", CompletionItemKind.Keyword), new Candidate("if", "if", CompletionItemKind.Keyword), new Candidate("some", "some", CompletionItemKind.Keyword), new Candidate("every", "every", CompletionItemKind.Keyword), new Candidate("function", "function", CompletionItemKind.Keyword));
}
use of org.kie.workbench.common.dmn.client.widgets.codecompletion.feel.FEELLanguageService.Position in project kie-wb-common by kiegroup.
the class FEELLanguageServiceTest method testGetCandidatesWhenTypeDoesNotMatch.
@Test
public void testGetCandidatesWhenTypeDoesNotMatch() {
final String expression = "[1..10] |";
final Position position = new Position(1, expression.indexOf("|"));
final String expressionToParse = expression.replace("|", "");
final List<Variable> variables = asList(new Variable("Decision-1", BuiltInType.STRING), new Variable("Decision-2", BuiltInType.NUMBER), new Variable("Decision-3", BuiltInType.BOOLEAN), new Variable("Decision-4", BuiltInType.NUMBER), new Variable("Decision-5", BuiltInType.DATE));
final List<Candidate> actualCandidates = service.getCandidates(expressionToParse, variables, position);
Assertions.assertThat(actualCandidates).containsExactly(new Candidate("not", "not", CompletionItemKind.Keyword), new Candidate("for", "for", CompletionItemKind.Keyword), new Candidate("if", "if", CompletionItemKind.Keyword), new Candidate("some", "some", CompletionItemKind.Keyword), new Candidate("every", "every", CompletionItemKind.Keyword), new Candidate("function", "function", CompletionItemKind.Keyword));
}
use of org.kie.workbench.common.dmn.client.widgets.codecompletion.feel.FEELLanguageService.Position in project kie-wb-common by kiegroup.
the class MonacoFEELSuggestionsTest method getSuggestions.
@Test
public void getSuggestions() {
final String expectedNodeName1 = "Decision-1";
final String expectedNodeName2 = "Decision-2";
final String expectedNodeName3 = "Decision-3";
final String expectedNodeName4 = "Decision-4";
final String expectedNodeName5 = "Decision-5";
final String expectedNodeName6 = "Decision-6";
final String expression = "1 +";
final Position position = new Position(1, 1);
final List<Candidate> expectedCandidates = new ArrayList<>();
final Stream<Node> nodeStream = Stream.of(makeDecisionNode(expectedNodeName1, BuiltInType.NUMBER), makeDecisionNode(expectedNodeName2, BuiltInType.STRING), makeDecisionNode(expectedNodeName3, BuiltInType.DATE), makeDecisionNode(expectedNodeName4, BuiltInType.BOOLEAN), makeDecisionNode(expectedNodeName5, BuiltInType.CONTEXT), makeDecisionNode(expectedNodeName6, null));
when(dmnGraphUtils.getNodeStream()).thenReturn(nodeStream);
when(feelLanguageService.getCandidates(any(), any(), any())).thenReturn(expectedCandidates);
final List<Candidate> actualSuggestions = monacoFEELSuggestions.getCandidates(expression, position);
verify(feelLanguageService).getCandidates(eq(expression), variablesArgumentCaptor.capture(), eq(position));
final List<Variable> actualVariables = variablesArgumentCaptor.getValue();
assertSame(expectedCandidates, actualSuggestions);
assertEquals(6, actualVariables.size());
assertEquals(expectedNodeName1, actualVariables.get(0).getName());
assertEquals(expectedNodeName2, actualVariables.get(1).getName());
assertEquals(expectedNodeName3, actualVariables.get(2).getName());
assertEquals(expectedNodeName4, actualVariables.get(3).getName());
assertEquals(expectedNodeName5, actualVariables.get(4).getName());
assertEquals(expectedNodeName6, actualVariables.get(5).getName());
assertEquals(org.kie.dmn.feel.lang.types.BuiltInType.NUMBER, actualVariables.get(0).getType());
assertEquals(org.kie.dmn.feel.lang.types.BuiltInType.STRING, actualVariables.get(1).getType());
assertEquals(org.kie.dmn.feel.lang.types.BuiltInType.DATE, actualVariables.get(2).getType());
assertEquals(org.kie.dmn.feel.lang.types.BuiltInType.BOOLEAN, actualVariables.get(3).getType());
assertEquals(org.kie.dmn.feel.lang.types.BuiltInType.CONTEXT, actualVariables.get(4).getType());
assertEquals(org.kie.dmn.feel.lang.types.BuiltInType.UNKNOWN, actualVariables.get(5).getType());
}
Aggregations