|
| 1 | +/** |
| 2 | + * Copyright (c) HashiCorp, Inc. |
| 3 | + * SPDX-License-Identifier: MPL-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import * as vscode from 'vscode'; |
| 7 | +import { assert } from 'chai'; |
| 8 | +import { activateExtension, getDocUri, open, testCompletion } from '../../helper'; |
| 9 | + |
| 10 | +suite('search (.tfquery.hcl)', () => { |
| 11 | + suite('root', function suite() { |
| 12 | + const docUri = getDocUri('main.tfquery.hcl'); |
| 13 | + |
| 14 | + this.beforeAll(async () => { |
| 15 | + await open(docUri); |
| 16 | + await activateExtension(); |
| 17 | + }); |
| 18 | + |
| 19 | + this.afterAll(async () => { |
| 20 | + await vscode.commands.executeCommand('workbench.action.closeAllEditors'); |
| 21 | + }); |
| 22 | + |
| 23 | + test('language is registered', async () => { |
| 24 | + const doc = await vscode.workspace.openTextDocument(docUri); |
| 25 | + assert.equal(doc.languageId, 'terraform-search', 'document language should be `terraform-search`'); |
| 26 | + }); |
| 27 | + |
| 28 | + test('completes blocks available for search files', async () => { |
| 29 | + const expected = [ |
| 30 | + new vscode.CompletionItem('list', vscode.CompletionItemKind.Class), |
| 31 | + new vscode.CompletionItem('locals', vscode.CompletionItemKind.Class), |
| 32 | + new vscode.CompletionItem('provider', vscode.CompletionItemKind.Class), |
| 33 | + new vscode.CompletionItem('variable', vscode.CompletionItemKind.Class), |
| 34 | + ]; |
| 35 | + |
| 36 | + await testCompletion(docUri, new vscode.Position(1, 0), { |
| 37 | + items: expected, |
| 38 | + }); |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + suite('list', function suite() { |
| 43 | + const docUri = getDocUri('main.tfquery.hcl'); |
| 44 | + |
| 45 | + this.beforeAll(async () => { |
| 46 | + await open(docUri); |
| 47 | + await activateExtension(); |
| 48 | + }); |
| 49 | + |
| 50 | + this.afterAll(async () => { |
| 51 | + await vscode.commands.executeCommand('workbench.action.closeAllEditors'); |
| 52 | + }); |
| 53 | + |
| 54 | + this.afterEach(async () => { |
| 55 | + // revert any changes made to the document after each test |
| 56 | + await vscode.commands.executeCommand('workbench.action.files.revert'); |
| 57 | + }); |
| 58 | + |
| 59 | + test('language is registered', async () => { |
| 60 | + const doc = await vscode.workspace.openTextDocument(docUri); |
| 61 | + assert.equal(doc.languageId, 'terraform-search', 'document language should be `terraform-search`'); |
| 62 | + }); |
| 63 | + |
| 64 | + test('completes attributes of list block - provider', async () => { |
| 65 | + const expected = [ |
| 66 | + new vscode.CompletionItem('aws.this', vscode.CompletionItemKind.Variable), |
| 67 | + new vscode.CompletionItem('azurerm.this', vscode.CompletionItemKind.Variable), |
| 68 | + ]; |
| 69 | + |
| 70 | + await testCompletion(docUri, new vscode.Position(24, 21), { |
| 71 | + items: expected, |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + test('completes attributes of list block - number variable', async () => { |
| 76 | + const expected = [ |
| 77 | + new vscode.CompletionItem('count.index', vscode.CompletionItemKind.Variable), |
| 78 | + new vscode.CompletionItem('local.number_local', vscode.CompletionItemKind.Variable), |
| 79 | + new vscode.CompletionItem('var.number_variable', vscode.CompletionItemKind.Variable), |
| 80 | + ]; |
| 81 | + |
| 82 | + await testCompletion(docUri, new vscode.Position(25, 21), { |
| 83 | + items: expected, |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + test('completes attributes of list block - boolean variable', async () => { |
| 88 | + const expected = [ |
| 89 | + new vscode.CompletionItem('false', vscode.CompletionItemKind.EnumMember), |
| 90 | + new vscode.CompletionItem('true', vscode.CompletionItemKind.EnumMember), |
| 91 | + new vscode.CompletionItem('var.boolean_variable', vscode.CompletionItemKind.Variable), |
| 92 | + ]; |
| 93 | + |
| 94 | + await testCompletion(docUri, new vscode.Position(26, 21), { |
| 95 | + items: expected, |
| 96 | + }); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments