Skip to content

Commit

Permalink
Add test cases demonstrating flaws with current completion
Browse files Browse the repository at this point in the history
  • Loading branch information
domnewkirk committed Mar 4, 2020
1 parent 3091311 commit 2e5f91d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
13 changes: 11 additions & 2 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

Expand Down
53 changes: 48 additions & 5 deletions server/src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -142,18 +142,61 @@ describe('server', () => {
uri: FIXTURE_URI.INSTALL,
},
position: {
// rm
line: 25,
character: 5,
},
},
{} 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)

Expand All @@ -165,14 +208,14 @@ describe('server', () => {
uri: FIXTURE_URI.INSTALL,
},
position: {
// inside comment
line: 2,
character: 1,
},
},
{} as any,
)

// Entire list
expect('length' in result && result.length > 50)
expect(result).toEqual([])
})
})

0 comments on commit 2e5f91d

Please sign in to comment.