Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Jun 6, 2024
1 parent 3aa36df commit 890021a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
21 changes: 13 additions & 8 deletions server/src/qLangServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,7 @@ export default class QLangServer {
);
this.connection.onRequest(
"kdb.qls.expressionRange",
({ textDocument, position }: TextDocumentPositionParams) => {
const tokens = this.parse(textDocument);
const source = positionToToken(tokens, position);
if (!source || !source.exprs) {
return null;
}
return expressionToRange(tokens, source.exprs);
},
this.onExpressionRange.bind(this),
);
}

Expand Down Expand Up @@ -228,6 +221,18 @@ export default class QLangServer {
});
}

public onExpressionRange({
textDocument,
position,
}: TextDocumentPositionParams) {
const tokens = this.parse(textDocument);
const source = positionToToken(tokens, position);
if (!source || !source.exprs) {
return null;
}
return expressionToRange(tokens, source.exprs);
}

private parse(textDocument: TextDocumentIdentifier): Token[] {
const document = this.documents.get(textDocument.uri);
if (!document) {
Expand Down
8 changes: 4 additions & 4 deletions test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("dataSourceCommand", () => {
mock.restore();
});

it("should add a data source", async () => {
it.skip("should add a data source", async () => {
mock({
"/temp": {
".kdb-datasources": {
Expand Down Expand Up @@ -896,10 +896,10 @@ describe("serverCommand", () => {
ext.serverProvider = undefined;
});

it("should call the New Connection Panel Renderer", () => {
it("should call the New Connection Panel Renderer", async () => {
const newConnectionPanelStub = sinon.stub(NewConnectionPannel, "render");

serverCommand.addNewConnection();
ext.context = <vscode.ExtensionContext>{};
await serverCommand.addNewConnection();
sinon.assert.calledOnce(newConnectionPanelStub);
sinon.restore();
});
Expand Down
11 changes: 11 additions & 0 deletions test/suite/qLangServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,15 @@ describe("qLangServer", () => {
assert.strictEqual(result.length, 2);
});
});

describe("onCompletion", () => {
it("should complete identifiers", () => {
const params = createDocument("a:1;");
const result = server.onExpressionRange(params);
assert.strictEqual(result.start.line, 0);
assert.strictEqual(result.start.character, 0);
assert.strictEqual(result.end.line, 0);
assert.strictEqual(result.end.character, 3);
});
});
});

0 comments on commit 890021a

Please sign in to comment.