|
| 1 | +import { expect } from 'chai'; |
| 2 | +import * as path from 'path'; |
| 3 | +import * as vscode from 'vscode'; |
| 4 | +import { Uri } from 'vscode'; |
| 5 | +import { determineSelectedQuery } from '../../run-queries'; |
| 6 | + |
| 7 | +async function showQlDocument(name: string): Promise<vscode.TextDocument> { |
| 8 | + const folderPath = vscode.workspace.workspaceFolders![0].uri.fsPath; |
| 9 | + const documentPath = path.resolve(folderPath, name); |
| 10 | + const document = await vscode.workspace.openTextDocument(documentPath); |
| 11 | + await vscode.window.showTextDocument(document!); |
| 12 | + return document; |
| 13 | +} |
| 14 | + |
| 15 | +export function run() { |
| 16 | + describe('Determining selected query', async () => { |
| 17 | + it('should allow ql files to be queried', async () => { |
| 18 | + const q = await determineSelectedQuery(Uri.parse('file:///tmp/queryname.ql'), false); |
| 19 | + expect(q.queryPath).to.equal('/tmp/queryname.ql'); |
| 20 | + expect(q.quickEvalPosition).to.equal(undefined); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should allow ql files to be quick-evaled', async () => { |
| 24 | + const doc = await showQlDocument('query.ql'); |
| 25 | + const q = await determineSelectedQuery(doc.uri, true); |
| 26 | + expect(q.queryPath).to.match(new RegExp('ql-vscode/test/data/query\.ql$')); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should allow qll files to be quick-evaled', async () => { |
| 30 | + const doc = await showQlDocument('library.qll'); |
| 31 | + const q = await determineSelectedQuery(doc.uri, true); |
| 32 | + expect(q.queryPath).to.match(new RegExp('ql-vscode/test/data/library\.qll$')); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should reject non-ql files when running a query', async () => { |
| 36 | + await expect(determineSelectedQuery(Uri.parse('file:///tmp/queryname.txt'), false)).to.be.rejectedWith(Error, 'The selected resource is not a CodeQL query file'); |
| 37 | + await expect(determineSelectedQuery(Uri.parse('file:///tmp/queryname.qll'), false)).to.be.rejectedWith(Error, 'The selected resource is not a CodeQL query file'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should reject non-ql[l] files when running a quick eval', async () => { |
| 41 | + await expect(determineSelectedQuery(Uri.parse('file:///tmp/queryname.txt'), true)).to.be.rejectedWith(Error, 'The selected resource is not a CodeQL file'); |
| 42 | + }); |
| 43 | + }); |
| 44 | +} |
0 commit comments