From 2e5f91d078e79d81fc4353e008d8a97f565f4cd0 Mon Sep 17 00:00:00 2001 From: Dominique Newkirk Date: Tue, 3 Mar 2020 15:36:04 +0100 Subject: [PATCH] Add test cases demonstrating flaws with current completion --- server/src/__tests__/analyzer.test.ts | 13 ++++++- server/src/__tests__/server.test.ts | 53 ++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/server/src/__tests__/analyzer.test.ts b/server/src/__tests__/analyzer.test.ts index 09e3fe9..ea539fe 100644 --- a/server/src/__tests__/analyzer.test.ts +++ b/server/src/__tests__/analyzer.test.ts @@ -86,8 +86,17 @@ describe('wordAtPoint', () => { it('returns current word at a given point', () => { analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL) expect(analyzer.wordAtPoint(CURRENT_URI, 25, 5)).toEqual('rm') - // FIXME: seems like there is an issue here: - // expect(analyzer.wordAtPoint(CURRENT_URI, 24, 4)).toEqual('else') + + // FIXME: grammar issue: else is not found + // expect(analyzer.wordAtPoint(CURRENT_URI, 24, 5)).toEqual('else') + + expect(analyzer.wordAtPoint(CURRENT_URI, 30, 1)).toEqual(null) + + expect(analyzer.wordAtPoint(CURRENT_URI, 30, 3)).toEqual('ret') + expect(analyzer.wordAtPoint(CURRENT_URI, 30, 4)).toEqual('ret') + expect(analyzer.wordAtPoint(CURRENT_URI, 30, 5)).toEqual('ret') + + expect(analyzer.wordAtPoint(CURRENT_URI, 38, 5)).toEqual('configures') }) }) diff --git a/server/src/__tests__/server.test.ts b/server/src/__tests__/server.test.ts index 8fc7498..93f4e0e 100644 --- a/server/src/__tests__/server.test.ts +++ b/server/src/__tests__/server.test.ts @@ -130,7 +130,7 @@ describe('server', () => { }) }) - it('responds to onCompletion when word is found', async () => { + it('responds to onCompletion with filtered list when word is found', async () => { const { connection, server } = await initializeServer() server.register(connection) @@ -142,6 +142,7 @@ describe('server', () => { uri: FIXTURE_URI.INSTALL, }, position: { + // rm line: 25, character: 5, }, @@ -149,11 +150,53 @@ describe('server', () => { {} as any, ) + expect(result).toMatchInlineSnapshot(` + Array [ + Object { + "data": Object { + "name": "rm", + "type": "executable", + }, + "kind": 12, + "label": "rm", + }, + Object { + "data": Object { + "name": "rmdir", + "type": "executable", + }, + "kind": 12, + "label": "rmdir", + }, + ] + `) + }) + + it('responds to onCompletion with entire list when no word is found', async () => { + const { connection, server } = await initializeServer() + server.register(connection) + + const onCompletion = connection.onCompletion.mock.calls[0][0] + + const result = await onCompletion( + { + textDocument: { + uri: FIXTURE_URI.INSTALL, + }, + position: { + // else + line: 24, + character: 5, + }, + }, + {} as any, + ) + // Entire list - expect('length' in result && result.length > 50) + expect('length' in result && result.length > 50).toBe(true) }) - it('responds to onCompletion when no word is found', async () => { + it('responds to onCompletion with empty list when word is a comment', async () => { const { connection, server } = await initializeServer() server.register(connection) @@ -165,6 +208,7 @@ describe('server', () => { uri: FIXTURE_URI.INSTALL, }, position: { + // inside comment line: 2, character: 1, }, @@ -172,7 +216,6 @@ describe('server', () => { {} as any, ) - // Entire list - expect('length' in result && result.length > 50) + expect(result).toEqual([]) }) })