-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathHoverProcessor.spec.ts
More file actions
157 lines (132 loc) · 5.57 KB
/
HoverProcessor.spec.ts
File metadata and controls
157 lines (132 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { expect } from 'chai';
import { Program } from '../../Program';
import util, { standardizePath as s } from '../../util';
import { createSandbox } from 'sinon';
let sinon = createSandbox();
let rootDir = s`${process.cwd()}/.tmp/rootDir`;
describe('HoverProcessor', () => {
let program: Program;
beforeEach(() => {
program = new Program({ rootDir: rootDir, sourceMap: true });
});
afterEach(() => {
sinon.restore();
program.dispose();
});
it('does not short-circuit the event since our plugin is the base plugin', () => {
const mock = sinon.mock();
program.plugins.add({
name: 'test-plugin',
onGetHover: mock
});
const file = program.addOrReplaceFile('source/main.brs', `
sub main()
end sub
`);
//get the hover
program.getHover(file.pathAbsolute, util.createPosition(1, 20));
//the onGetHover function from `test-plugin` should always get called because
//BscPlugin should never short-circuit the event
expect(mock.called).to.be.true;
});
describe('BrsFile', () => {
it('works for param types', () => {
const file = program.addOrReplaceFile('source/main.brs', `
sub DoSomething(name as string)
name = 1
sayMyName = function(name as string)
end function
end sub
`);
//hover over the `name = 1` line
let hover = program.getHover(file.pathAbsolute, util.createPosition(2, 24));
expect(hover).to.exist;
expect(hover.range).to.eql(util.createRange(2, 20, 2, 24));
//hover over the `name` parameter declaration
hover = program.getHover(file.pathAbsolute, util.createPosition(1, 34));
expect(hover).to.exist;
expect(hover.range).to.eql(util.createRange(1, 32, 1, 36));
});
//ignore this for now...it's not a huge deal
it('does not match on keywords or data types', () => {
let file = program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main(name as string)
end sub
sub as()
end sub
`);
//hover over the `as`
expect(program.getHover(file.pathAbsolute, util.createPosition(1, 31))).not.to.exist;
//hover over the `string`
expect(program.getHover(file.pathAbsolute, util.createPosition(1, 36))).not.to.exist;
});
it('finds declared function', () => {
let file = program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
function Main(count = 1)
firstName = "bob"
age = 21
shoeSize = 10
end function
`);
let hover = program.getHover(file.pathAbsolute, util.createPosition(1, 28));
expect(hover).to.exist;
expect(hover.range).to.eql(util.createRange(1, 25, 1, 29));
expect(hover.contents).to.eql({
language: 'brighterscript',
value: 'function Main(count? as dynamic) as dynamic'
});
});
it('finds variable function hover in same scope', () => {
let file = program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
sayMyName = sub(name as string)
end sub
sayMyName()
end sub
`);
let hover = program.getHover(file.pathAbsolute, util.createPosition(5, 24));
expect(hover.range).to.eql(util.createRange(5, 20, 5, 29));
expect(hover.contents).to.eql({
language: 'brighterscript',
value: 'sub sayMyName(name as string) as void'
});
});
it('finds function hover in file scope', () => {
let file = program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
sayMyName()
end sub
sub sayMyName()
end sub
`);
let hover = program.getHover(file.pathAbsolute, util.createPosition(2, 25));
expect(hover.range).to.eql(util.createRange(2, 20, 2, 29));
expect(hover.contents).to.eql({
language: 'brighterscript',
value: 'sub sayMyName() as void'
});
});
it('finds function hover in scope', () => {
let rootDir = process.cwd();
program = new Program({
rootDir: rootDir
});
let mainFile = program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
sayMyName()
end sub
`);
program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `
sub sayMyName(name as string)
end sub
`);
let hover = program.getHover(mainFile.pathAbsolute, util.createPosition(2, 25));
expect(hover).to.exist;
expect(hover.range).to.eql(util.createRange(2, 20, 2, 29));
expect(hover.contents).to.eql({
language: 'brighterscript',
value: 'sub sayMyName(name as string) as void'
});
});
});
});