Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Sep 21, 2023
1 parent 96ffffb commit 985e237
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 35 deletions.
8 changes: 4 additions & 4 deletions test/suite/cpUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ import * as assert from "assert";
import * as cpUtils from "../../server/src/utils/cpUtils";

describe("cpUtils tests", () => {
it("wrapArgInQuotes should return quoted string", () => {
it("wrapArgInQuotes should return a quoted string", () => {
const result = cpUtils.wrapArgInQuotes("test");
assert.strictEqual(result.substring(1, 5), "test");
});

it("wrapArgInQuotes should return string value for boolean", () => {
it("wrapArgInQuotes should return a string value", () => {
const result = cpUtils.wrapArgInQuotes(true);
assert.strictEqual(result, "true");
});

it("wrapArgInQuotes should return string value for number", () => {
it("wrapArgInQuotes should return a string value", () => {
const result = cpUtils.wrapArgInQuotes(1);
assert.strictEqual(result, "1");
});

it("wrapArgInQuotes should return empty quoted string for none", () => {
it("wrapArgInQuotes should return an empty quoted string", () => {
const result = cpUtils.wrapArgInQuotes();
assert.strictEqual(result.length, 2);
});
Expand Down
81 changes: 50 additions & 31 deletions test/suite/qLangServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("qLangServer tests", () => {
assert.ok(ok);
});

it("onCompletion should return empty array for no keyword", () => {
it("onCompletion should return an empty array", () => {
const getKeywordStub = sinon.stub(server, <any>"getKeyword");
getKeywordStub.value(() => undefined);
const result = server["onCompletion"](<TextDocumentPositionParams>{
Expand All @@ -123,7 +123,7 @@ describe("qLangServer tests", () => {
assert.strictEqual(result.length, 0);
});

it("onCompletion should return a list of completions for a keyword", () => {
it("onCompletion should return a value", () => {
const doc = TextDocument.create("/test/test.q", "q", 1, "aco");
const textDocument = TextDocumentIdentifier.create("/test/test.q");
const position = Position.create(0, 3);
Expand All @@ -133,7 +133,7 @@ describe("qLangServer tests", () => {
textDocument,
position,
});
assert.strictEqual(result.length, 1);
assert.ok(result.length > 0);
});

it("onCompletionResolve should return a value", async () => {
Expand All @@ -142,7 +142,17 @@ describe("qLangServer tests", () => {
assert.strictEqual(result, item);
});

it("onHover should return null for no keyword", async () => {
it("onHover should return null", async () => {
const getKeywordStub = sinon.stub(server, <any>"getEntireKeyword");
getKeywordStub.value(() => undefined);
const result = await server["onHover"](<TextDocumentPositionParams>{
textDocument: TextDocumentIdentifier.create("/test/test.q"),
position: Position.create(0, 0),
});
assert.strictEqual(result, null);
});

it("onHover should return a value", async () => {
const doc = TextDocument.create("/test/test.q", "q", 1, "acos");
const textDocument = TextDocumentIdentifier.create("/test/test.q");
const position = Position.create(0, 1);
Expand All @@ -152,28 +162,19 @@ describe("qLangServer tests", () => {
textDocument,
position,
});
// TODO
assert.ok(result);
});

it("onHover should return a value for a keyword", async () => {
const getKeywordStub = sinon.stub(server, <any>"getEntireKeyword");
getKeywordStub.value(() => undefined);
const result = await server["onHover"](<TextDocumentPositionParams>{
textDocument: TextDocumentIdentifier.create("/test/test.q"),
position: Position.create(0, 0),
});
assert.strictEqual(result, null);
});

it("onDocumentHighlight should return empty array for no document", () => {
it("onDocumentHighlight should return an empty array", () => {
const result = server["onDocumentHighlight"](<TextDocumentPositionParams>{
textDocument: TextDocumentIdentifier.create("/test/test.q"),
position: Position.create(0, 0),
});
assert.strictEqual(result.length, 0);
});

it("onDefinition should return empty array for no document", () => {
it("onDefinition should return an empty array", () => {
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => undefined);
const result = server["onDefinition"](<TextDocumentPositionParams>{
Expand All @@ -188,21 +189,25 @@ describe("qLangServer tests", () => {
"/test/test.q",
"q",
1,
"test_var:1\ntest_var"
"test_func: {[x] x*x};\ntest_func[2];"
);
const textDocument = TextDocumentIdentifier.create("/test/test.q");
const position = Position.create(2, 1);
const position = Position.create(1, 1);
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => doc);
const valuesStub = sinon.stub(
server.analyzer["uriToTextDocument"],
"values"
);
valuesStub.value(() => [doc]);
const result = server["onDefinition"](<TextDocumentPositionParams>{
textDocument,
position,
});
// TODO
assert.strictEqual(result.length, 0);
assert.ok(result.length > 0);
});

it("onDocumentSymbol should return empty array for no document", () => {
it("onDocumentSymbol should return an empty array", () => {
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => undefined);
const result = server["onDocumentSymbol"](<TextDocumentPositionParams>{
Expand All @@ -226,7 +231,7 @@ describe("qLangServer tests", () => {
assert.strictEqual(result.length, 0);
});

it("onPrepareCallHierarchy should return empty array for no document", () => {
it("onPrepareCallHierarchy should return an empty array", () => {
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => undefined);
const result = server["onPrepareCallHierarchy"](<
Expand Down Expand Up @@ -254,7 +259,7 @@ describe("qLangServer tests", () => {
assert.strictEqual(result.length, 0);
});

it("onIncomingCallsCallHierarchy should return empty array for no item", () => {
it("onIncomingCallsCallHierarchy should return an empty array", () => {
const result = server.onIncomingCallsCallHierarchy(<
CallHierarchyIncomingCallsParams
>{
Expand All @@ -267,30 +272,43 @@ describe("qLangServer tests", () => {
const result = server.onOutgoingCallsCallHierarchy({
item: <CallHierarchyItem>{ uri: "test", name: "test" },
});
// TODO
assert.ok(result);
});

it("onReferences should return empty array for no document", () => {
it("onReferences should return an empty array", () => {
const textDocument = TextDocumentIdentifier.create("/test/test.q");
const position = Position.create(0, 0);
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => undefined);
const result = server["onReferences"](<ReferenceParams>{
textDocument: TextDocumentIdentifier.create("/test/test.q"),
position: Position.create(0, 0),
textDocument,
position,
});
assert.strictEqual(result.length, 0);
});

it("onReferences should return a value", () => {
const doc = TextDocument.create("/test/test.q", "q", 1, "a:1; b:2;");
const doc = TextDocument.create(
"/test/test.q",
"q",
1,
"test_func: {[x] x*x};\ntest_func[2];"
);
const textDocument = TextDocumentIdentifier.create("/test/test.q");
const position = Position.create(0, 0);
const position = Position.create(1, 1);
const getStub = sinon.stub(server.documents, "get");
getStub.value(() => doc);
const valuesStub = sinon.stub(
server.analyzer["uriToTextDocument"],
"values"
);
valuesStub.value(() => [doc]);
const result = server["onReferences"](<ReferenceParams>{
textDocument,
position,
});
// TODO
assert.strictEqual(result.length, 0);
assert.ok(result.length > 0);
});

it("onRenameRequest should return a value", () => {
Expand Down Expand Up @@ -328,10 +346,11 @@ describe("qLangServer tests", () => {
const result = server["onSemanticsTokens"](<SemanticTokensParams>{
textDocument,
});
// TODO
assert.strictEqual(result.data.length, 0);
});

it("validateTextDocument should return a value", async () => {
it("validateTextDocument should publish a diagnostic", async () => {
const sendDiagnosticsStub = sinon.stub(
server.connection,
"sendDiagnostics"
Expand Down

0 comments on commit 985e237

Please sign in to comment.