Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Sep 19, 2023
1 parent f2a6719 commit 08fa3f8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
4 changes: 1 addition & 3 deletions server/src/qLangServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ export default class QLangServer {
return tokens ?? { data: [] };
}

private async validateTextDocument(
textDocument: TextDocument
): Promise<void> {
public async validateTextDocument(textDocument: TextDocument): Promise<void> {
const settings = await this.getDocumentSettings(textDocument.uri);
const text = textDocument.getText();
const pattern = /\b[A-Z]{2,}\b/g;
Expand Down
62 changes: 56 additions & 6 deletions test/suite/qLangServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ import * as assert from "assert";
import * as sinon from "sinon";
import {
CallHierarchyIncomingCallsParams,
CallHierarchyItem,
CompletionItem,
Connection,
InitializeParams,
Position,
PublishDiagnosticsParams,
ReferenceParams,
RenameParams,
SemanticTokensParams,
TextDocumentIdentifier,
TextDocumentPositionParams,
} from "vscode-languageserver";
import { TextDocument } from "vscode-languageserver-textdocument";
import QLangServer from "../../server/src/qLangServer";

describe("qLangServer tests", () => {
Expand All @@ -44,6 +51,7 @@ describe("qLangServer tests", () => {
onDocumentSymbol() {},
onReferences() {},
onRenameRequest() {},
sendDiagnostics() {},
languages: {
semanticTokens: {
on() {},
Expand All @@ -59,6 +67,9 @@ describe("qLangServer tests", () => {
warn() {},
info() {},
},
workspace: {
getConfiguration() {},
},
});

const params = <InitializeParams>{
Expand Down Expand Up @@ -173,8 +184,12 @@ describe("qLangServer tests", () => {
assert.strictEqual(result.length, 0);
});

// TODO
it("onOutgoingCallsCallHierarchy", () => {});
it("onOutgoingCallsCallHierarchy should return a value", () => {
const result = server.onOutgoingCallsCallHierarchy({
item: <CallHierarchyItem>{ uri: "test", name: "test" },
});
assert.ok(result);
});

it("onReferences should return empty array for no document", () => {
const getStub = sinon.stub(server.documents, "get");
Expand All @@ -185,9 +200,44 @@ describe("qLangServer tests", () => {
assert.strictEqual(result.length, 0);
});

// TODO
it("onRenameRequest", () => {});
it("onRenameRequest should return a value", () => {
const doc = TextDocument.create("/test/test.q", "q", 1, "SOMEVAR:1");
const textDocument = TextDocumentIdentifier.create("/test/test.q");
const position = Position.create(0, 0);
const newName = "CHANGEDVAR";
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => doc);
const result = server.onRenameRequest(<RenameParams>{
textDocument,
position,
newName,
});
// TODO
assert.strictEqual(result, null);
});

it("onSemanticsTokens should return a value", () => {
const doc = TextDocument.create("/test/test.q", "q", 1, "TOKEN:1");
const textDocument = TextDocumentIdentifier.create("/test/test.q");
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => doc);
const result = server.onSemanticsTokens(<SemanticTokensParams>{
textDocument,
});
assert.strictEqual(result.data.length, 0);
});

// TODO
it("onSemanticsTokens", () => {});
it("validateTextDocument should report uppercase identifiers", async () => {
const sendDiagnosticsStub = sinon.stub(
server.connection,
"sendDiagnostics"
);
let result: PublishDiagnosticsParams;
sendDiagnosticsStub.value(
async (params: PublishDiagnosticsParams) => (result = params)
);
const doc = TextDocument.create("/test/test.q", "q", 1, "SOMEVAR:1");
await server.validateTextDocument(doc);
assert.strictEqual(result.diagnostics.length, 1);
});
});

0 comments on commit 08fa3f8

Please sign in to comment.