Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Sep 19, 2023
1 parent 84a2081 commit f2a6719
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 99 deletions.
6 changes: 4 additions & 2 deletions server/src/qLangServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export default class QLangServer {
return null;
}

public onSignatureHelp({
private onSignatureHelp({
textDocument,
position,
}: SignatureHelpParams): SignatureHelp | undefined {
Expand Down Expand Up @@ -394,7 +394,9 @@ export default class QLangServer {
return tokens ?? { data: [] };
}

public async validateTextDocument(textDocument: TextDocument): Promise<void> {
private 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
180 changes: 83 additions & 97 deletions test/suite/qLangServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
import * as assert from "assert";
import * as sinon from "sinon";
import {
EndOfLine,
Position,
Range,
TextDocument,
TextLine,
Uri,
} from "vscode";
CallHierarchyIncomingCallsParams,
CompletionItem,
Connection,
InitializeParams,
ReferenceParams,
TextDocumentPositionParams,
} from "vscode-languageserver";
import QLangServer from "../../server/src/qLangServer";

describe("qLangServer tests", () => {
let server: QLangServer;

beforeEach(async () => {
const connectionMock = {
const connection = <Connection>(<unknown>{
listen() {},
onDidOpenTextDocument() {},
onDidChangeTextDocument() {},
Expand Down Expand Up @@ -59,17 +59,17 @@ describe("qLangServer tests", () => {
warn() {},
info() {},
},
};
});

const paramsMock = {
processId: 0,
rootUri: "",
capabilities: {},
workspaceFolders: [],
const params = <InitializeParams>{
workspaceFolders: null,
};

// @ts-ignore
server = await QLangServer.initialize(connectionMock, paramsMock);
server = await QLangServer.initialize(connection, params);
});

afterEach(() => {
sinon.restore();
});

it("capabilities should return a value", () => {
Expand Down Expand Up @@ -100,108 +100,94 @@ describe("qLangServer tests", () => {
assert.ok(ok);
});

it("onCompletion should return empty array for no keyword", () => {
const getKeywordStub = sinon.stub(server, <any>"getKeyword");
getKeywordStub.value(() => undefined);
const result = server.onCompletion(<TextDocumentPositionParams>{
textDocument: { uri: undefined },
position: undefined,
});
assert.strictEqual(result.length, 0);
});

it("onCompletionResolve should return a value", async () => {
const item = { label: "test" };
const item = <CompletionItem>{ label: "test" };
const result = await server.onCompletionResolve(item);
assert.strictEqual(result, item);
});

it("onDocumentHighlight should return empty array", async () => {
const result = server.onDocumentHighlight({
position: null,
textDocument: null,
it("onHover should return null for no keyword", async () => {
const getKeywordStub = sinon.stub(server, <any>"getEntireKeyword");
getKeywordStub.value(() => undefined);
const result = await server.onHover(<TextDocumentPositionParams>{
textDocument: { uri: undefined },
position: undefined,
});
assert.strictEqual(result.length, 0);
assert.strictEqual(result, null);
});

// TODO
it("onCompletion should return empty array for no keyword", () => {});

// TODO
it("onDefinition should return empty array for no document", async () => {
const getKeywordStub = sinon.stub(server.documents, "get");
getKeywordStub.value(() => undefined);
const result = server.onDefinition({
textDocument: { uri: "" },
it("onDocumentHighlight should return empty array for no document", () => {
const result = server.onDocumentHighlight(<TextDocumentPositionParams>{
textDocument: { uri: undefined },
position: undefined,
});
assert.strictEqual(result.length, 0);
});

// TODO
it("onHover should return null for no keyword", async () => {});

// TODO
it("onDocumentSymbol should return empty array for no document", async () => {});

// TODO
it("onPrepareCallHierarchy", async () => {});
it("onDefinition should return empty array for no document", () => {
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => undefined);
const result = server.onDefinition(<TextDocumentPositionParams>{
textDocument: { uri: undefined },
position: undefined,
});
assert.strictEqual(result.length, 0);
});

// TODO
it("onIncomingCallsCallHierarchy", async () => {});
it("onDocumentSymbol should return empty array for no document", () => {
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => undefined);
const result = server.onDocumentSymbol(<TextDocumentPositionParams>{
textDocument: { uri: undefined },
position: undefined,
});
assert.strictEqual(result.length, 0);
});

// TODO
it("onOutgoingCallsCallHierarchy", async () => {});
it("onPrepareCallHierarchy should return empty array for no document", () => {
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => undefined);
const result = server.onPrepareCallHierarchy(<TextDocumentPositionParams>{
textDocument: { uri: undefined },
position: undefined,
});
assert.strictEqual(result.length, 0);
});

// TODO
it("onReferences", async () => {});
it("onIncomingCallsCallHierarchy should return empty array for no item", () => {
const result = server.onIncomingCallsCallHierarchy(<
CallHierarchyIncomingCallsParams
>{
item: { name: undefined },
});
assert.strictEqual(result.length, 0);
});

// TODO
it("onRenameRequest", async () => {});
it("onOutgoingCallsCallHierarchy", () => {});

// TODO
it("onSignatureHelp", async () => {});
it("onReferences should return empty array for no document", () => {
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => undefined);
const result = server.onReferences(<ReferenceParams>{
textDocument: { uri: undefined },
});
assert.strictEqual(result.length, 0);
});

// TODO
it("onSemanticsTokens", async () => {});
it("onRenameRequest", () => {});

// TODO
it("validateTextDocument", async () => {});
it("onSemanticsTokens", () => {});
});

class TextDocumentMock implements TextDocument {
fileName!: string;
isUntitled!: boolean;
languageId!: string;
version!: number;
isDirty!: boolean;
isClosed!: boolean;
eol!: EndOfLine;
lineCount!: number;
text: string;

uri = Uri.parse("/test/test.q");

constructor(text: string) {
this.text = text;
}

getText(range?: Range): string {
return this.text;
}

save(): Thenable<boolean> {
throw new Error("Method not implemented.");
}
lineAt(position: Position | number | any): TextLine {
throw new Error("Method not implemented.");
}
offsetAt(position: Position): number {
throw new Error("Method not implemented.");
}
positionAt(offset: number): Position {
throw new Error("Method not implemented.");
}
getWordRangeAtPosition(
position: Position,
regex?: RegExp
): Range | undefined {
throw new Error("Method not implemented.");
}
validateRange(range: Range): Range {
throw new Error("Method not implemented.");
}
validatePosition(position: Position): Position {
throw new Error("Method not implemented.");
}
}

0 comments on commit f2a6719

Please sign in to comment.