Skip to content

Commit

Permalink
test: add test of completion provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sockmaster27 committed Apr 28, 2024
1 parent 1b68d13 commit 050a688
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/src/codeLenses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as assert from 'assert'
import * as vscode from 'vscode'
import { getTestDocUri, activate, open, copyFile, tryDeleteFile } from './util'
import { getTestDocUri, activate, open } from './util'

suite('Code lenses', () => {
const mainDocUri = getTestDocUri('src/Main.flix')
Expand Down
49 changes: 49 additions & 0 deletions test/src/completions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 Holger Dal Mogensen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as assert from 'assert'
import * as vscode from 'vscode'
import { getTestDocUri, activate, open, tryDeleteFile, addFile, typeText } from './util'

suite('Code lenses', () => {
const docUri = getTestDocUri('src/Temp.flix')

suiteSetup(async () => {
await activate()
})
teardown(async () => {
await tryDeleteFile(docUri)
})

test('Should propose completing mod', async () => {
await addFile(docUri, '')
await open(docUri)
await typeText('mo')

// TODO: Figure out why this returns all possible keywords, which is not what is shown in the editor
const position = new vscode.Position(0, 2)
const r = (await vscode.commands.executeCommand(
'vscode.executeCompletionItemProvider',
docUri,
position,
)) as vscode.CompletionList

assert.strictEqual(
r.items.some(i => i.label === 'mod'),
true,
)
})
})
7 changes: 7 additions & 0 deletions test/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export async function open(docUri: vscode.Uri) {
await vscode.window.showTextDocument(doc)
}

/**
* Types the given `text` in the editor at the current position.
*/
export async function typeText(text: string) {
await vscode.commands.executeCommand('type', { text })
}

function getTestDocPath(p: string) {
return path.resolve(__dirname, '../testWorkspace', p)
}
Expand Down

0 comments on commit 050a688

Please sign in to comment.