danielzhe commented on code in PR #2684:
URL:
https://github.com/apache/incubator-kie-tools/pull/2684#discussion_r1814085019
##########
packages/feel-input-component/tests/semanticTokensProvider.test.ts:
##########
@@ -286,6 +290,149 @@ ThatShouldFailWhenBreakLine`,
}
});
});
+
+ describe("variables inside Decision Tables", () => {
+ const dmnModelWithInclude =
"../tests-data/variables-inside-decision-tables/modelWithInclude.dmn";
+ const includedDmnModel =
"../tests-data/variables-inside-decision-tables/included.dmn";
+ test("should recognize local nodes", async () => {
+ const expression = "LocalInput + LocalDecision";
+ const id = "_AEC3EEB0-8436-4767-A214-20FF5E5CB7BE";
+ const modelMock = createModelMockForExpression(expression);
+
+ const localModel = getDmnModelFromFilePath(dmnModelWithInclude);
+ const includedModel = getDmnModelFromFilePath(includedDmnModel);
+
+ const feelVariables = new FeelVariables(
+ localModel.definitions,
+ new Map([[includedModel.definitions["@_namespace"] ?? "",
includedModel]])
+ );
+
+ const semanticTokensProvider = new SemanticTokensProvider(feelVariables,
id, () => {});
+
+ const semanticMonacoTokens = await
semanticTokensProvider.provideDocumentSemanticTokens(
+ modelMock as unknown as Monaco.editor.ITextModel,
+ null,
+ cancellationTokenMock
+ );
+
+ const expected = [
+ ...getMonacoSemanticToken({
+ startLineRelativeToPreviousLine: 0,
+ startIndexRelativeToPreviousStartIndex: 0,
+ tokenLength: "LocalInput".length,
+ }),
+ ...getMonacoSemanticToken({
+ startLineRelativeToPreviousLine: 0,
+ startIndexRelativeToPreviousStartIndex: "LocalInput".length + 3, //
+3 because of the " + "
+ tokenLength: "LocalDecision".length,
+ }),
+ ];
+
+ for (let i = 0; i < expected.length; i++) {
+ expect(semanticMonacoTokens?.data[i]).toEqual(expected[i]);
+ }
+ });
+
+ test("should recognize included nodes", async () => {
+ const expression = "MyIncludedModel.MyDS(LocalInput) +
MyIncludedModel.RemoteInput";
+ const id = "_206131ED-0B81-4013-980A-4BB2539A53D0";
+ const modelMock = createModelMockForExpression(expression);
+
+ const localModel = getDmnModelFromFilePath(dmnModelWithInclude);
+ const includedModel = getDmnModelFromFilePath(includedDmnModel);
+
+ const feelVariables = new FeelVariables(
+ localModel.definitions,
+ new Map([[includedModel.definitions["@_namespace"] ?? "",
includedModel]])
+ );
+
+ const semanticTokensProvider = new SemanticTokensProvider(feelVariables,
id, () => {});
+
+ const semanticMonacoTokens = await
semanticTokensProvider.provideDocumentSemanticTokens(
+ modelMock as unknown as Monaco.editor.ITextModel,
+ null,
+ cancellationTokenMock
+ );
+
+ const expected = [
+ ...getMonacoSemanticToken({
+ startLineRelativeToPreviousLine: 0,
+ startIndexRelativeToPreviousStartIndex: 0,
+ tokenLength: "MyIncludedModel.MyDS".length,
+ tokenType: Element.FunctionCall,
+ }),
+ ...getMonacoSemanticToken({
+ startLineRelativeToPreviousLine: 0,
+ startIndexRelativeToPreviousStartIndex:
"MyIncludedModel.MyDS".length + 1, // +1 because of the "("
+ tokenLength: "LocalInput".length,
+ }),
+ ...getMonacoSemanticToken({
+ startLineRelativeToPreviousLine: 0,
+ startIndexRelativeToPreviousStartIndex: "LocalInput".length + ") +
".length,
+ tokenLength: "MyIncludedModel.RemoteInput".length,
+ }),
+ ];
+
+ for (let i = 0; i < expected.length; i++) {
+ expect(semanticMonacoTokens?.data[i]).toEqual(expected[i]);
+ }
Review Comment:
No, their types are different and it fails if we do this way:
```
Error: expect(received).toEqual(expected) // deep equality
Expected: [0, 0, 20, 6, 0, 0, 21, 10, 5, 0, …]
Received: serializes to the same string
<Click to see difference>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]