Skip to content

Commit a46509c

Browse files
committed
Add test cases demonstrating flaws with current completion
1 parent 76c8e10 commit a46509c

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,17 @@ describe('wordAtPoint', () => {
8686
it('returns current word at a given point', () => {
8787
analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
8888
expect(analyzer.wordAtPoint(CURRENT_URI, 25, 5)).toEqual('rm')
89-
// FIXME: seems like there is an issue here:
90-
// expect(analyzer.wordAtPoint(CURRENT_URI, 24, 4)).toEqual('else')
89+
90+
// FIXME: grammar issue: else is not found
91+
// expect(analyzer.wordAtPoint(CURRENT_URI, 24, 5)).toEqual('else')
92+
93+
expect(analyzer.wordAtPoint(CURRENT_URI, 30, 1)).toEqual(null)
94+
95+
expect(analyzer.wordAtPoint(CURRENT_URI, 30, 3)).toEqual('ret')
96+
expect(analyzer.wordAtPoint(CURRENT_URI, 30, 4)).toEqual('ret')
97+
expect(analyzer.wordAtPoint(CURRENT_URI, 30, 5)).toEqual('ret')
98+
99+
expect(analyzer.wordAtPoint(CURRENT_URI, 38, 5)).toEqual('configures')
91100
})
92101
})
93102

server/src/__tests__/server.test.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('server', () => {
130130
})
131131
})
132132

133-
it('responds to onCompletion when word is found', async () => {
133+
it('responds to onCompletion with filtered list when word is found', async () => {
134134
const { connection, server } = await initializeServer()
135135
server.register(connection)
136136

@@ -142,18 +142,61 @@ describe('server', () => {
142142
uri: FIXTURE_URI.INSTALL,
143143
},
144144
position: {
145+
// rm
145146
line: 25,
146147
character: 5,
147148
},
148149
},
149150
{} as any,
150151
)
151152

153+
expect(result).toMatchInlineSnapshot(`
154+
Array [
155+
Object {
156+
"data": Object {
157+
"name": "rm",
158+
"type": "executable",
159+
},
160+
"kind": 12,
161+
"label": "rm",
162+
},
163+
Object {
164+
"data": Object {
165+
"name": "rmdir",
166+
"type": "executable",
167+
},
168+
"kind": 12,
169+
"label": "rmdir",
170+
},
171+
]
172+
`)
173+
})
174+
175+
it('responds to onCompletion with entire list when no word is found', async () => {
176+
const { connection, server } = await initializeServer()
177+
server.register(connection)
178+
179+
const onCompletion = connection.onCompletion.mock.calls[0][0]
180+
181+
const result = await onCompletion(
182+
{
183+
textDocument: {
184+
uri: FIXTURE_URI.INSTALL,
185+
},
186+
position: {
187+
// else
188+
line: 24,
189+
character: 5,
190+
},
191+
},
192+
{} as any,
193+
)
194+
152195
// Entire list
153-
expect('length' in result && result.length > 50)
196+
expect('length' in result && result.length > 50).toBe(true)
154197
})
155198

156-
it('responds to onCompletion when no word is found', async () => {
199+
it('responds to onCompletion with empty list when word is a comment', async () => {
157200
const { connection, server } = await initializeServer()
158201
server.register(connection)
159202

@@ -165,14 +208,14 @@ describe('server', () => {
165208
uri: FIXTURE_URI.INSTALL,
166209
},
167210
position: {
211+
// inside comment
168212
line: 2,
169213
character: 1,
170214
},
171215
},
172216
{} as any,
173217
)
174218

175-
// Entire list
176-
expect('length' in result && result.length > 50)
219+
expect(result).toEqual([])
177220
})
178221
})

0 commit comments

Comments
 (0)