From 7b0f5b55032bd4d8ea4dbcbc0b2f4e8f2c56eeac Mon Sep 17 00:00:00 2001 From: ecmel Date: Fri, 26 Apr 2024 11:59:48 +0300 Subject: [PATCH] added tests --- server/src/qLangServer.ts | 2 +- .../{linter.test.ts => buildTools.test.ts} | 20 +++- test/suite/parser.test.ts | 2 +- test/suite/qLangServer.test.ts | 107 +++++++++++++++++- 4 files changed, 123 insertions(+), 8 deletions(-) rename test/suite/{linter.test.ts => buildTools.test.ts} (53%) diff --git a/server/src/qLangServer.ts b/server/src/qLangServer.ts index 1a9a05e8..7fad1f14 100644 --- a/server/src/qLangServer.ts +++ b/server/src/qLangServer.ts @@ -84,7 +84,7 @@ function isAssignable(token: Token) { export default class QLangServer { private declare connection: Connection; private declare params: InitializeParams; - private declare documents: TextDocuments; + public declare documents: TextDocuments; constructor(connection: Connection, params: InitializeParams) { this.connection = connection; diff --git a/test/suite/linter.test.ts b/test/suite/buildTools.test.ts similarity index 53% rename from test/suite/linter.test.ts rename to test/suite/buildTools.test.ts index de30fe1d..2e3491f1 100644 --- a/test/suite/linter.test.ts +++ b/test/suite/buildTools.test.ts @@ -12,11 +12,23 @@ */ import * as assert from "assert"; +import * as tools from "../../src/commands/buildToolsCommand"; +import { workspace } from "vscode"; -describe("Parser", () => { - describe("Feature", () => { - it("should", () => { - assert.strictEqual(1, 1); +describe("buildTools", () => { + describe("connectBuildTools", () => { + it("should connect build tools", async () => { + await assert.doesNotReject(async () => tools.connectBuildTools()); + }); + }); + + describe("lintCommand", () => { + it("should lint", async () => { + const document = await workspace.openTextDocument({ + language: "q", + content: "a;a:1", + }); + await assert.doesNotReject(async () => tools.lintCommand(document)); }); }); }); diff --git a/test/suite/parser.test.ts b/test/suite/parser.test.ts index 4a46808b..296fcfd6 100644 --- a/test/suite/parser.test.ts +++ b/test/suite/parser.test.ts @@ -14,7 +14,7 @@ import * as assert from "assert"; import { generateTextMateGrammar } from "../../server/src/parser"; -describe("Parser", () => { +describe("QParser", () => { describe("language", () => { it("should generate TextMate grammar file", () => { const grammar = generateTextMateGrammar(); diff --git a/test/suite/qLangServer.test.ts b/test/suite/qLangServer.test.ts index fa2318a2..1969cda0 100644 --- a/test/suite/qLangServer.test.ts +++ b/test/suite/qLangServer.test.ts @@ -11,13 +11,19 @@ * specific language governing permissions and limitations under the License. */ -/* eslint @typescript-eslint/no-explicit-any: 0 */ /* eslint @typescript-eslint/no-empty-function: 0 */ import * as assert from "assert"; import * as sinon from "sinon"; -import { Connection, InitializeParams } from "vscode-languageserver"; +import { + Connection, + InitializeParams, + Position, + Range, + TextDocumentIdentifier, +} from "vscode-languageserver"; import QLangServer from "../../server/src/qLangServer"; +import { TextDocument } from "vscode-languageserver-textdocument"; describe("qLangServer", () => { let server: QLangServer; @@ -60,4 +66,101 @@ describe("qLangServer", () => { assert.ok(capabilities.completionProvider); }); }); + + describe("onDocumentSymbol", () => { + it("should return golobals", () => { + const textDocument = TextDocumentIdentifier.create("test.q"); + sinon + .stub(server.documents, "get") + .value(() => TextDocument.create("test.q", "q", 1, "a:1")); + const result = server.onDocumentSymbol({ textDocument }); + assert.strictEqual(result.length, 1); + assert.strictEqual(result[0].name, "a"); + }); + }); + + describe("onReferences", () => { + it("should return golobal references", () => { + const position = Position.create(0, 5); + const context = { + includeDeclaration: true, + }; + const textDocument = TextDocumentIdentifier.create("test.q"); + sinon + .stub(server.documents, "get") + .value(() => TextDocument.create("test.q", "q", 1, "a:1;a")); + const result = server.onReferences({ + textDocument, + position, + context, + }); + assert.strictEqual(result.length, 2); + assert.deepStrictEqual(result[0].range, Range.create(0, 0, 0, 1)); + assert.deepStrictEqual(result[1].range, Range.create(0, 4, 0, 5)); + }); + }); + + describe("onDefinition", () => { + it("should return golobal definition", () => { + const position = Position.create(0, 5); + const textDocument = TextDocumentIdentifier.create("test.q"); + sinon + .stub(server.documents, "get") + .value(() => TextDocument.create("test.q", "q", 1, "a:1;a")); + const result = server.onDefinition({ + textDocument, + position, + }); + assert.strictEqual(result.length, 1); + assert.deepStrictEqual(result[0].range, Range.create(0, 0, 0, 1)); + }); + }); + + describe("onRenameRequest", () => { + it("should rename golobal identifiers", () => { + const position = Position.create(0, 5); + const newName = "b"; + const textDocument = TextDocumentIdentifier.create("test.q"); + sinon + .stub(server.documents, "get") + .value(() => TextDocument.create("test.q", "q", 1, "a:1;a")); + const result = server.onRenameRequest({ + textDocument, + position, + newName, + }); + assert.ok(result); + assert.strictEqual(result.changes[textDocument.uri].length, 2); + }); + }); + + describe("onCompletion", () => { + it("should complete golobal identifiers", () => { + const position = Position.create(0, 5); + const textDocument = TextDocumentIdentifier.create("test.q"); + sinon + .stub(server.documents, "get") + .value(() => TextDocument.create("test.q", "q", 1, "a:1;a")); + const result = server.onCompletion({ + textDocument, + position, + }); + assert.strictEqual(result.length, 1); + }); + }); + + describe("onCompletion", () => { + it("should complete golobal variables", () => { + const position = Position.create(0, 5); + const textDocument = TextDocumentIdentifier.create("test.q"); + sinon + .stub(server.documents, "get") + .value(() => TextDocument.create("test.q", "q", 1, "a:1;a")); + const result = server.onCompletion({ + textDocument, + position, + }); + assert.strictEqual(result.length, 1); + }); + }); });