From a8d8ac386fd2e92a57a0ef55f6c58f7704082bbf Mon Sep 17 00:00:00 2001 From: Ajay Ghanwat Date: Tue, 18 Aug 2026 21:28:38 +0530 Subject: [PATCH] test(vscode): add integration tests for completion provider guard --- editors/vscode/test/completion-scope.test.js | 82 +++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/editors/vscode/test/completion-scope.test.js b/editors/vscode/test/completion-scope.test.js index b8033608..db143c19 100644 --- a/editors/vscode/test/completion-scope.test.js +++ b/editors/vscode/test/completion-scope.test.js @@ -7,10 +7,48 @@ 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 {}; + 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 } = require("../src/completion.js"); +const { isInsideViewBlock, provideCompletionItems } = require("../src/completion.js"); Module._load = originalLoad; const PAGE = `page Home { @@ -30,3 +68,43 @@ test("a markup offset is inside a view block", () => { 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(position) { + return PAGE.indexOf("hello" }; + }, + 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(position) { + 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"); +});