Fix determineSelectedQuery tests
This commit is contained in:
0
extensions/ql-vscode/test/data/textfile.txt
Normal file
0
extensions/ql-vscode/test/data/textfile.txt
Normal file
@@ -1,7 +1,10 @@
|
||||
import { resolve, join } from "path";
|
||||
import * as vscode from "vscode";
|
||||
import { Uri } from "vscode";
|
||||
import { determineSelectedQuery } from "../../../src/run-queries-shared";
|
||||
import {
|
||||
getQuickEvalContext,
|
||||
validateQueryUri,
|
||||
} from "../../../src/run-queries-shared";
|
||||
|
||||
async function showQlDocument(name: string): Promise<vscode.TextDocument> {
|
||||
const folderPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
|
||||
@@ -14,43 +17,47 @@ async function showQlDocument(name: string): Promise<vscode.TextDocument> {
|
||||
export function run() {
|
||||
describe("Determining selected query", () => {
|
||||
it("should allow ql files to be queried", async () => {
|
||||
const q = await determineSelectedQuery(
|
||||
const queryPath = validateQueryUri(
|
||||
Uri.parse("file:///tmp/queryname.ql"),
|
||||
false,
|
||||
);
|
||||
expect(q.queryPath).toBe(join("/", "tmp", "queryname.ql"));
|
||||
expect(q.quickEvalPosition).toBeUndefined();
|
||||
expect(queryPath).toBe(join("/", "tmp", "queryname.ql"));
|
||||
});
|
||||
|
||||
it("should allow ql files to be quick-evaled", async () => {
|
||||
const doc = await showQlDocument("query.ql");
|
||||
const q = await determineSelectedQuery(doc.uri, true);
|
||||
await showQlDocument("query.ql");
|
||||
const q = await getQuickEvalContext(undefined);
|
||||
expect(
|
||||
q.queryPath.endsWith(join("ql-vscode", "test", "data", "query.ql")),
|
||||
q.quickEvalPosition.fileName.endsWith(
|
||||
join("ql-vscode", "test", "data", "query.ql"),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("should allow qll files to be quick-evaled", async () => {
|
||||
const doc = await showQlDocument("library.qll");
|
||||
const q = await determineSelectedQuery(doc.uri, true);
|
||||
await showQlDocument("library.qll");
|
||||
const q = await getQuickEvalContext(undefined);
|
||||
expect(
|
||||
q.queryPath.endsWith(join("ql-vscode", "test", "data", "library.qll")),
|
||||
q.quickEvalPosition.fileName.endsWith(
|
||||
join("ql-vscode", "test", "data", "library.qll"),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("should reject non-ql files when running a query", async () => {
|
||||
await expect(
|
||||
determineSelectedQuery(Uri.parse("file:///tmp/queryname.txt"), false),
|
||||
).rejects.toThrow("The selected resource is not a CodeQL query file");
|
||||
await expect(
|
||||
determineSelectedQuery(Uri.parse("file:///tmp/queryname.qll"), false),
|
||||
).rejects.toThrow("The selected resource is not a CodeQL query file");
|
||||
expect(() =>
|
||||
validateQueryUri(Uri.parse("file:///tmp/queryname.txt"), false),
|
||||
).toThrow("The selected resource is not a CodeQL query file");
|
||||
expect(() =>
|
||||
validateQueryUri(Uri.parse("file:///tmp/queryname.qll"), false),
|
||||
).toThrow("The selected resource is not a CodeQL query file");
|
||||
});
|
||||
|
||||
it("should reject non-ql[l] files when running a quick eval", async () => {
|
||||
await expect(
|
||||
determineSelectedQuery(Uri.parse("file:///tmp/queryname.txt"), true),
|
||||
).rejects.toThrow("The selected resource is not a CodeQL file");
|
||||
await showQlDocument("textfile.txt");
|
||||
await expect(getQuickEvalContext(undefined)).rejects.toThrow(
|
||||
"The selected resource is not a CodeQL file",
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user