Also fix an unused-var lint failure in completion-scope.test.js blocking the production gate. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
111 lines
2.7 KiB
JavaScript
111 lines
2.7 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert");
|
|
const Module = require("node:module");
|
|
|
|
// Mock the vscode module for unit tests
|
|
const originalLoad = Module._load;
|
|
Module._load = function load(request, parent, isMain) {
|
|
if (request === "vscode") {
|
|
return {
|
|
Position: class Position {
|
|
constructor(line, character) {
|
|
this.line = line;
|
|
this.character = character;
|
|
}
|
|
},
|
|
Range: class Range {
|
|
constructor(start, end) {
|
|
this.start = start;
|
|
this.end = end;
|
|
}
|
|
},
|
|
CompletionItem: class CompletionItem {
|
|
constructor(label, kind) {
|
|
this.label = label;
|
|
this.kind = kind;
|
|
}
|
|
},
|
|
CompletionItemKind: {
|
|
Event: 23,
|
|
Property: 10,
|
|
Function: 12,
|
|
Keyword: 14,
|
|
Variable: 13,
|
|
},
|
|
SnippetString: class SnippetString {
|
|
constructor(text) {
|
|
this.value = text;
|
|
}
|
|
},
|
|
MarkdownString: class MarkdownString {
|
|
constructor(text) {
|
|
this.value = text;
|
|
}
|
|
},
|
|
};
|
|
}
|
|
return originalLoad.call(this, request, parent, isMain);
|
|
};
|
|
const { isInsideViewBlock, provideCompletionItems } = require("../src/completion.js");
|
|
Module._load = originalLoad;
|
|
|
|
const PAGE = `page Home {
|
|
view {
|
|
<div>hello</div>
|
|
}
|
|
functions {
|
|
function go() {}
|
|
}
|
|
}
|
|
`;
|
|
|
|
test("a markup offset is inside a view block", () => {
|
|
assert.equal(isInsideViewBlock(PAGE, PAGE.indexOf("<div")), true);
|
|
});
|
|
|
|
test("a functions-block offset is not inside a view block", () => {
|
|
assert.equal(isInsideViewBlock(PAGE, PAGE.indexOf("function go")), false);
|
|
});
|
|
|
|
test("provideCompletionItems returns empty array when inside view block", () => {
|
|
const document = {
|
|
getText() {
|
|
return PAGE;
|
|
},
|
|
offsetAt() {
|
|
return PAGE.indexOf("<div");
|
|
},
|
|
lineAt() {
|
|
return { text: "<div>hello</div>" };
|
|
},
|
|
fileName: "test.wrn",
|
|
};
|
|
const position = { line: 2, character: 4 };
|
|
|
|
const result = provideCompletionItems(document, position);
|
|
assert.equal(Array.isArray(result), true);
|
|
assert.equal(result.length, 0);
|
|
});
|
|
|
|
test("provideCompletionItems returns non-empty array when inside functions block", () => {
|
|
const document = {
|
|
getText() {
|
|
return PAGE;
|
|
},
|
|
offsetAt() {
|
|
return PAGE.indexOf("function go");
|
|
},
|
|
lineAt() {
|
|
return { text: " function go() {}" };
|
|
},
|
|
fileName: "test.wrn",
|
|
};
|
|
const position = { line: 5, character: 4 };
|
|
|
|
const result = provideCompletionItems(document, position);
|
|
assert.equal(Array.isArray(result), true);
|
|
assert(result.length > 0, "should return non-empty completions outside view block");
|
|
});
|