Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #372 from prabushi/master
Browse files Browse the repository at this point in the history
Update tests for alpha4 dist
  • Loading branch information
prabushi committed Apr 21, 2021
2 parents 63f68a5 + e46120a commit 3dabb78
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/core/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export class BallerinaExtension {
});
});
const cmdOutput = await any([balPromise, ballerinaPromise]);
this.ballerinaCmd = distPath + ballerinaExecutor + exeExtension;
this.ballerinaCmd = (distPath + ballerinaExecutor + exeExtension).trim();
try {
debug(`Ballerina version output: ${cmdOutput}`);
const implVersionLine = cmdOutput.split('\n')[0];
Expand Down
3 changes: 3 additions & 0 deletions src/editor-support/split-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { BallerinaExtension } from "../core";
import { Disposable, Position, Range, TextDocumentChangeEvent, TextDocumentContentChangeEvent, window, workspace } from "vscode";
import { CMP_STRING_SPLIT, sendTelemetryEvent, TM_EVENT_STRING_SPLIT } from "../telemetry";

const newLine: string = process.platform === "win32" ? '\r\n' : '\n';
const STRING_LITERAL: string = 'STRING_LITERAL';
Expand Down Expand Up @@ -50,6 +51,7 @@ export class StringSplitter {
if (!this.langClient) {
return;
}
const extension: BallerinaExtension = this;
this.langClient.getSyntaxTreeNode({
documentIdentifier: {
uri: editor.document.uri.toString()
Expand All @@ -69,6 +71,7 @@ export class StringSplitter {
return;
}
if (response.kind === STRING_LITERAL) {
sendTelemetryEvent(extension, TM_EVENT_STRING_SPLIT, CMP_STRING_SPLIT);
editor.edit(editBuilder => {
const startPosition = new Position(range.start.line, range.start.character);
const nextLinePosition = new Position(range.start.line + 1, documentChange!.text.length - 1);
Expand Down
1 change: 1 addition & 0 deletions src/telemetry/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export const CMP_PROJECT_CLOUD = "component.project.cloud.runner";
export const CMP_TRACE_LOGS = "component.trace.logs";
export const CMP_DEBUGGER = "component.debugger";
export const CMP_PACKAGE_VIEW = "component.package.view";
export const CMP_STRING_SPLIT = "component.string.split";
3 changes: 3 additions & 0 deletions src/telemetry/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ export const TM_EVENT_PROJECT_CLOUD = "execute.project.cloud";
export const TM_EVENT_LANG_SERVER = "ballerina.langserver.event";
export const TM_ERROR_LANG_SERVER = "ballerina.langserver.error";
export const TM_FEATURE_USAGE_LANG_SERVER = "ballerina.langserver.feature.usage";

// events related to editor support features
export const TM_EVENT_STRING_SPLIT = "ballerina.string.split";
97 changes: 50 additions & 47 deletions test/language-server/lang-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,48 +69,48 @@ suite("Language Server Tests", function () {
});
});

test("Test getBallerinaProject - Ballerina project", (done) => {
const projectPath = path.join(PROJECT_ROOT, 'helloPackage');
const uri = Uri.file(path.join(projectPath, 'main.bal').toString());
commands.executeCommand('vscode.open', uri).then(() => {
langClient.onReady().then(() => {
const projectPath = path.join(PROJECT_ROOT, 'helloPackage');
const documentIdentifier = {
documentIdentifier: {
uri: uri.toString()
}
};
langClient.getBallerinaProject(documentIdentifier).then((response) => {
assert.equal(response.packageName, 'helloproject', "Invalid package name.");
process.platform !== 'win32' ? assert.equal(response.path, projectPath, 'Invalid project path') :
assert.equal(response.path!.toLowerCase(), projectPath.toLowerCase(), 'Invalid project path');
assert.equal(response.kind, 'BUILD_PROJECT', 'Invalid project kind.');
done();
}, (reason) => {
done(reason);
});
});
});
});

test("Test getBallerinaProject - Single file", (done) => {
const uri = Uri.file(path.join(PROJECT_ROOT, 'hello_world.bal'));
commands.executeCommand('vscode.open', uri).then(() => {
langClient.onReady().then(() => {
const documentIdentifier = {
documentIdentifier: {
uri: uri.toString()
}
};
langClient.getBallerinaProject(documentIdentifier).then((response) => {
assert.equal(response.kind, 'SINGLE_FILE_PROJECT', 'Invalid project kind.');
done();
}, (reason) => {
done(reason);
});
});
});
});
// test("Test getBallerinaProject - Ballerina project", (done) => {
// const projectPath = path.join(PROJECT_ROOT, 'helloPackage');
// const uri = Uri.file(path.join(projectPath, 'main.bal').toString());
// commands.executeCommand('vscode.open', uri).then(() => {
// langClient.onReady().then(() => {
// const projectPath = path.join(PROJECT_ROOT, 'helloPackage');
// const documentIdentifier = {
// documentIdentifier: {
// uri: uri.toString()
// }
// };
// langClient.getBallerinaProject(documentIdentifier).then((response) => {
// assert.equal(response.packageName, 'helloproject', "Invalid package name.");
// process.platform !== 'win32' ? assert.equal(response.path, projectPath, 'Invalid project path') :
// assert.equal(response.path!.toLowerCase(), projectPath.toLowerCase(), 'Invalid project path');
// assert.equal(response.kind, 'BUILD_PROJECT', 'Invalid project kind.');
// done();
// }, (reason) => {
// done(reason);
// });
// });
// });
// });

// test("Test getBallerinaProject - Single file", (done) => {
// const uri = Uri.file(path.join(PROJECT_ROOT, 'hello_world.bal'));
// commands.executeCommand('vscode.open', uri).then(() => {
// langClient.onReady().then(() => {
// const documentIdentifier = {
// documentIdentifier: {
// uri: uri.toString()
// }
// };
// langClient.getBallerinaProject(documentIdentifier).then((response) => {
// assert.equal(response.kind, 'SINGLE_FILE_PROJECT', 'Invalid project kind.');
// done();
// }, (reason) => {
// done(reason);
// });
// });
// });
// });

test("Test fetchExamples", (done) => {
langClient.onReady().then(() => {
Expand Down Expand Up @@ -548,9 +548,11 @@ suite("Language Server Tests", function () {
};

langClient.sendRequest('textDocument/codeAction', actionParam).then((response: any) => {
assert.equal(response.length, 1, 'Invalid number of code actions.');
assert.equal(response.length, 2, 'Invalid number of code actions.');
assert.equal(response[0].title, "Add type cast to assignment", 'Invalid type cast action.');
assert.equal(response[0].kind, "quickfix", "Invalid code action kind - 1st.");
assert.equal(response[0].kind, "quickfix", "Invalid code action kind - 0th.");
assert.equal(response[1].title, "Change variable 'piValue' type to 'string'", 'Invalid change variable action.');
assert.equal(response[1].kind, "quickfix", "Invalid code action kind - 1st.");
done();
});
});
Expand Down Expand Up @@ -674,9 +676,10 @@ suite("Language Server Tests", function () {
};

langClient.sendRequest('textDocument/codeAction', actionParam).then((response: any) => {
assert.equal(response.length, 1, 'Invalid number of code actions.');
assert.equal(response[0].title, 'Update documentation', 'Invalid update documentation action.');
assert.equal(response[0].kind, "quickfix", "Invalid code action kind - 0th.");
assert.equal(response.length, 3, 'Invalid number of code actions.');
assert.equal(response[0].title, 'Document this', 'Invalid document this action.');
assert.equal(response[1].title, 'Document all', 'Invalid document all action.');
assert.equal(response[2].title, 'Update documentation', 'Invalid update documentation action.');
done();
});
});
Expand Down

0 comments on commit 3dabb78

Please sign in to comment.