Skip to content

Commit 80f0138

Browse files
Add new test for detecting data types from variables
1 parent 1ab677e commit 80f0138

4 files changed

Lines changed: 112 additions & 1 deletion

File tree

apps/test-tokenizer/src/test-maker/cache/cache.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

apps/test-tokenizer/src/test-maker/tests/auto-token-definition-tests.interface.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ export const AUTO_TOKEN_DEFINITION_TESTS: ITokenDefTests[] = [
4242
},
4343
],
4444
},
45+
{
46+
suiteName: `Correctly get routine definition for`,
47+
fileName: `change-detection-dynamic.2.spec.ts`,
48+
tests: [
49+
{
50+
name: `change detection with proper type`,
51+
files: [
52+
`idl/test/change-detection/dynamic/use_leap.pro`,
53+
// purposely out of order
54+
`idl/test/change-detection/dynamic/leap2.pro`,
55+
`idl/test/change-detection/dynamic/leap.pro`,
56+
`idl/test/change-detection/dynamic/leap3.pro`,
57+
`idl/test/change-detection/dynamic/leap4.pro`,
58+
],
59+
position: [
60+
{
61+
line: 2,
62+
character: 1,
63+
},
64+
],
65+
},
66+
],
67+
},
4568
{
4669
suiteName: `Correctly get routine definition for`,
4770
fileName: `def-files.1.spec.ts`,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
compile_opt idl2
2+
3+
aaa = leap4()
4+
5+
end
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { LogManager } from '@idl/logger';
2+
import { IDL_INDEX_OPTIONS, IDLIndex } from '@idl/parsing/index';
3+
import { GetExtensionPath } from '@idl/shared';
4+
import { readFile } from 'fs/promises';
5+
import { Position } from 'vscode-languageserver/node';
6+
7+
IDL_INDEX_OPTIONS.IS_TEST = true;
8+
9+
describe(`[auto generated] Correctly get routine definition for`, () => {
10+
it(`[auto generated] change detection with proper type`, async () => {
11+
// create index
12+
const index = new IDLIndex(
13+
new LogManager({
14+
alert: () => {
15+
// do nothing
16+
},
17+
}),
18+
0
19+
);
20+
21+
// specify reference filepath
22+
const filepath = GetExtensionPath(
23+
'idl/test/change-detection/dynamic/use_leap.pro'
24+
);
25+
26+
// parse file for tests
27+
await index.indexFile(
28+
GetExtensionPath('idl/test/change-detection/dynamic/use_leap.pro')
29+
);
30+
31+
// parse file for tests
32+
await index.indexFile(
33+
GetExtensionPath('idl/test/change-detection/dynamic/leap2.pro')
34+
);
35+
36+
// parse file for tests
37+
await index.indexFile(
38+
GetExtensionPath('idl/test/change-detection/dynamic/leap.pro')
39+
);
40+
41+
// parse file for tests
42+
await index.indexFile(
43+
GetExtensionPath('idl/test/change-detection/dynamic/leap3.pro')
44+
);
45+
46+
// parse file for tests
47+
await index.indexFile(
48+
GetExtensionPath('idl/test/change-detection/dynamic/leap4.pro')
49+
);
50+
51+
// define position
52+
const position_0: Position = { line: 2, character: 1 };
53+
54+
// define expected token we extract
55+
const expectedFound_0 = {
56+
type: 'v',
57+
name: 'aaa',
58+
pos: [2, 0, 3],
59+
meta: {
60+
display: 'aaa',
61+
isDefined: true,
62+
canReset: true,
63+
usage: [[2, 0, 3]],
64+
docs: '',
65+
source: 'user',
66+
type: [{ name: 'Plot', display: 'Plot', args: [], meta: {} }],
67+
},
68+
};
69+
70+
// get expected and remove file
71+
const found_0 = await index.getTokenDef(
72+
filepath,
73+
await readFile(filepath, 'utf-8'),
74+
position_0
75+
);
76+
if (found_0 !== undefined) {
77+
delete found_0.file;
78+
}
79+
80+
// verify results
81+
expect(expectedFound_0).toEqual(found_0);
82+
});
83+
});

0 commit comments

Comments
 (0)