Skip to content

Commit 20d987f

Browse files
Ilja PostnovsIlja Postnovs
Ilja Postnovs
authored and
Ilja Postnovs
committed
add tests
1 parent 4fdd8cf commit 20d987f

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

.vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"request": "launch",
2626
"runtimeExecutable": "${execPath}",
2727
"args": [
28-
"--extensionDevelopmentPath=${workspaceFolder}/testproject",
28+
"--extensionDevelopmentPath=${workspaceFolder}/../VSCodeUI5PluginUsageExampleApp",
2929
"--extensionTestsPath=${workspaceFolder}/dist/test/suite/index",
30-
"--testWorkspace=${workspaceFolder}/testproject"
30+
"--testWorkspace=${workspaceFolder}/../VSCodeUI5PluginUsageExampleApp"
3131
],
3232
"outFiles": ["${workspaceFolder}/dist/test/**/*.js"],
3333
"sourceMaps": true,

src/classes/UI5Classes/JSParser/AcornSyntaxAnalyzer.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export class AcornSyntaxAnalyzer {
7070
innerNode = node.right;
7171
} else if (node.type === "BinaryExpression") {
7272
innerNode = node.right && this.findAcornNode([node.right], position);
73+
if (!innerNode && node.left) {
74+
innerNode = node.left && this.findAcornNode([node.left], position);
75+
}
7376
} else if (node.type === "LogicalExpression") {
7477
innerNode = node.right && this.findAcornNode([node.right], position);
7578

@@ -303,7 +306,7 @@ export class AcornSyntaxAnalyzer {
303306
const content = this.expandAllContent(acornMethod.value);
304307
const node = this._getCallExpressionNodeWhichIsArrayMethod(content, identifierNode.end);
305308
if (node) {
306-
const isFirstParamOfArrayMethod = node.arguments[0]?.params[0]?.name === identifierNode.name;
309+
const isFirstParamOfArrayMethod = node.arguments[0]?.params && node.arguments[0]?.params[0]?.name === identifierNode.name;
307310
if (isFirstParamOfArrayMethod) {
308311
const strategy = new FieldsAndMethodForPositionBeforeCurrentStrategy();
309312
className = strategy.acornGetClassName(currentClassName, node.callee.object.end + 1) || "";
@@ -505,6 +508,16 @@ export class AcornSyntaxAnalyzer {
505508
}
506509
} else if (node.type === "MemberExpression") {
507510
innerNodes.push(node.object);
511+
if (node.property) {
512+
innerNodes.push(node.property);
513+
}
514+
} else if (node.type === "BinaryExpression") {
515+
if (node.right) {
516+
innerNodes.push(node.right);
517+
}
518+
if (node.left) {
519+
innerNodes.push(node.left);
520+
}
508521
} else if (node.type === "ExpressionStatement") {
509522
innerNodes.push(node.expression);
510523
} else if (node.type === "ThisExpression") {

src/test/suite/data/TestData.json

+11
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,16 @@
146146
}
147147
},
148148
"type": "sap.ui.model.Model"
149+
},{
150+
"className": "com.test.controller.Master",
151+
"methodName": "_findDialog",
152+
"positionAddition": 1,
153+
"node": {
154+
"type": "MemberExpression",
155+
"property": {
156+
"name": "getTitle"
157+
}
158+
},
159+
"type": "sap.m.Dialog"
149160
}]
150161
}

src/test/suite/extension.test.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import assert = require("assert");
2-
import { after, describe, it, test } from "mocha";
3-
import * as path from "path";
4-
import * as fs from "fs";
5-
// You can import and use all API from the "vscode" module
6-
// as well as import your extension to test it
2+
import { after, test } from "mocha";
73
import * as vscode from "vscode";
84
import { AcornSyntaxAnalyzer } from "../../classes/UI5Classes/JSParser/AcornSyntaxAnalyzer";
95
import { UIClassFactory } from "../../classes/UI5Classes/UIClassFactory";
@@ -55,27 +51,30 @@ suite("Extension Test Suite", () => {
5551
return compareProperties(data.node, node);
5652
});
5753

58-
const position = searchedNode.property.start + data.positionAddition;
54+
if (!searchedNode) {
55+
throw new Error(`Node '${JSON.stringify(data.node)}' in '${data.methodName}' not found`);
56+
}
57+
58+
const position = searchedNode.property?.start || searchedNode.start + data.positionAddition;
5959
const positionBeforeCurrentStrategy = new FieldsAndMethodForPositionBeforeCurrentStrategy();
6060
const classNameAtPosition = positionBeforeCurrentStrategy.acornGetClassName(data.className, position);
6161
assert.strictEqual(data.type, classNameAtPosition, `${data.className} position ${position} type is ${classNameAtPosition} but expected ${data.type}`);
6262
});
6363
});
6464
});
6565

66-
function compareProperties(node1: any, node2: any) : boolean {
66+
function compareProperties(dataNode: any, node2: any) : boolean {
6767
let allInnerNodesExists = true;
68-
for (const i in node1) {
68+
for (const i in dataNode) {
6969
if (node2[i]) {
7070
if (typeof node2[i] === "object") {
71-
allInnerNodesExists = compareProperties(node1[i], node2[i]);
71+
allInnerNodesExists = compareProperties(dataNode[i], node2[i]);
7272
} else {
73-
allInnerNodesExists = allInnerNodesExists && node1[i] === node2[i];
73+
allInnerNodesExists = allInnerNodesExists && dataNode[i] === node2[i];
7474
}
7575
} else {
7676
allInnerNodesExists = false;
7777
}
78-
7978
}
8079

8180
return allInnerNodesExists;

0 commit comments

Comments
 (0)