Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Apr 26, 2024
1 parent 7ef703d commit 7b0f5b5
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/src/qLangServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function isAssignable(token: Token) {
export default class QLangServer {
private declare connection: Connection;
private declare params: InitializeParams;
private declare documents: TextDocuments<TextDocument>;
public declare documents: TextDocuments<TextDocument>;

constructor(connection: Connection, params: InitializeParams) {
this.connection = connection;
Expand Down
20 changes: 16 additions & 4 deletions test/suite/linter.test.ts → test/suite/buildTools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
});
2 changes: 1 addition & 1 deletion test/suite/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
107 changes: 105 additions & 2 deletions test/suite/qLangServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 7b0f5b5

Please sign in to comment.