Skip to content

Commit 63a08e5

Browse files
committed
Create a testsuite for CodeLens provider
1 parent 942cceb commit 63a08e5

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import assert from 'assert';
2+
import { suite, test } from 'mocha';
3+
import { Uri, window, workspace } from 'vscode';
4+
import { adaExtState } from '../../../src/extension';
5+
import { activate } from '../utils';
6+
7+
suite('CodeLens', function () {
8+
this.beforeAll(async () => {
9+
await activate();
10+
});
11+
12+
test('in main file offer run & debug', async () => {
13+
assert(workspace.workspaceFolders !== undefined);
14+
const rootUri = workspace.workspaceFolders[0].uri;
15+
const mainUri = Uri.joinPath(rootUri, 'src', 'main1.adb');
16+
const textEditor = await window.showTextDocument(mainUri);
17+
const codelenses = await adaExtState.codelensProvider.provideCodeLenses(
18+
textEditor.document
19+
);
20+
assert.equal(
21+
/**
22+
* Check a string representation of the CodeLenses.
23+
*/
24+
toString(codelenses),
25+
`
26+
[
27+
{
28+
"command": "ada.buildAndRunMain",
29+
"title": "$(run) Run",
30+
"arguments": [
31+
"src/main1.adb"
32+
]
33+
},
34+
{
35+
"command": "ada.buildAndDebugMain",
36+
"title": "$(debug-alt-small) Debug",
37+
"arguments": [
38+
"src/main1.adb"
39+
]
40+
}
41+
]`.trim()
42+
);
43+
});
44+
45+
test("in non-main file don't offer run & debug", async () => {
46+
assert(workspace.workspaceFolders !== undefined);
47+
const rootUri = workspace.workspaceFolders[0].uri;
48+
const mainUri = Uri.joinPath(rootUri, 'src', 'foo.ads');
49+
const textEditor = await window.showTextDocument(mainUri);
50+
const codelenses = await adaExtState.codelensProvider.provideCodeLenses(
51+
textEditor.document
52+
);
53+
54+
if (codelenses) {
55+
/**
56+
* Assert that run and debug codelenses have not been provided
57+
*/
58+
assert(
59+
codelenses.every((cl) => {
60+
assert(cl.command?.command);
61+
return (
62+
!cl.command.command.toLowerCase().includes('run') &&
63+
!cl.command.command.toLowerCase().includes('debug')
64+
);
65+
})
66+
);
67+
}
68+
});
69+
});
70+
71+
function toString(codelenses: import('vscode').CodeLens[] | null | undefined): unknown {
72+
return JSON.stringify(
73+
codelenses?.map((cl) => ({
74+
command: cl.command?.command ?? '',
75+
title: cl.command?.title ?? '',
76+
arguments: cl.command?.arguments?.map((o) =>
77+
/**
78+
* If the argument is a URI, render it as a relative
79+
* path. Otherwise, keep the object as is.
80+
*/
81+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
82+
o instanceof Uri ? workspace.asRelativePath(o) : o
83+
),
84+
})),
85+
null,
86+
2
87+
);
88+
}

0 commit comments

Comments
 (0)