11import { resolve , join } from "path" ;
22import * as vscode from "vscode" ;
33import { Uri } from "vscode" ;
4- import { determineSelectedQuery } from "../../../src/run-queries-shared" ;
4+ import {
5+ getQuickEvalContext ,
6+ validateQueryUri ,
7+ } from "../../../src/run-queries-shared" ;
58
69async function showQlDocument ( name : string ) : Promise < vscode . TextDocument > {
710 const folderPath = vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath ;
@@ -14,43 +17,47 @@ async function showQlDocument(name: string): Promise<vscode.TextDocument> {
1417export function run ( ) {
1518 describe ( "Determining selected query" , ( ) => {
1619 it ( "should allow ql files to be queried" , async ( ) => {
17- const q = await determineSelectedQuery (
20+ const queryPath = validateQueryUri (
1821 Uri . parse ( "file:///tmp/queryname.ql" ) ,
1922 false ,
2023 ) ;
21- expect ( q . queryPath ) . toBe ( join ( "/" , "tmp" , "queryname.ql" ) ) ;
22- expect ( q . quickEvalPosition ) . toBeUndefined ( ) ;
24+ expect ( queryPath ) . toBe ( join ( "/" , "tmp" , "queryname.ql" ) ) ;
2325 } ) ;
2426
2527 it ( "should allow ql files to be quick-evaled" , async ( ) => {
26- const doc = await showQlDocument ( "query.ql" ) ;
27- const q = await determineSelectedQuery ( doc . uri , true ) ;
28+ await showQlDocument ( "query.ql" ) ;
29+ const q = await getQuickEvalContext ( undefined ) ;
2830 expect (
29- q . queryPath . endsWith ( join ( "ql-vscode" , "test" , "data" , "query.ql" ) ) ,
31+ q . quickEvalPosition . fileName . endsWith (
32+ join ( "ql-vscode" , "test" , "data" , "query.ql" ) ,
33+ ) ,
3034 ) . toBe ( true ) ;
3135 } ) ;
3236
3337 it ( "should allow qll files to be quick-evaled" , async ( ) => {
34- const doc = await showQlDocument ( "library.qll" ) ;
35- const q = await determineSelectedQuery ( doc . uri , true ) ;
38+ await showQlDocument ( "library.qll" ) ;
39+ const q = await getQuickEvalContext ( undefined ) ;
3640 expect (
37- q . queryPath . endsWith ( join ( "ql-vscode" , "test" , "data" , "library.qll" ) ) ,
41+ q . quickEvalPosition . fileName . endsWith (
42+ join ( "ql-vscode" , "test" , "data" , "library.qll" ) ,
43+ ) ,
3844 ) . toBe ( true ) ;
3945 } ) ;
4046
4147 it ( "should reject non-ql files when running a query" , async ( ) => {
42- await expect (
43- determineSelectedQuery ( Uri . parse ( "file:///tmp/queryname.txt" ) , false ) ,
44- ) . rejects . toThrow ( "The selected resource is not a CodeQL query file" ) ;
45- await expect (
46- determineSelectedQuery ( Uri . parse ( "file:///tmp/queryname.qll" ) , false ) ,
47- ) . rejects . toThrow ( "The selected resource is not a CodeQL query file" ) ;
48+ expect ( ( ) =>
49+ validateQueryUri ( Uri . parse ( "file:///tmp/queryname.txt" ) , false ) ,
50+ ) . toThrow ( "The selected resource is not a CodeQL query file" ) ;
51+ expect ( ( ) =>
52+ validateQueryUri ( Uri . parse ( "file:///tmp/queryname.qll" ) , false ) ,
53+ ) . toThrow ( "The selected resource is not a CodeQL query file" ) ;
4854 } ) ;
4955
5056 it ( "should reject non-ql[l] files when running a quick eval" , async ( ) => {
51- await expect (
52- determineSelectedQuery ( Uri . parse ( "file:///tmp/queryname.txt" ) , true ) ,
53- ) . rejects . toThrow ( "The selected resource is not a CodeQL file" ) ;
57+ await showQlDocument ( "textfile.txt" ) ;
58+ await expect ( getQuickEvalContext ( undefined ) ) . rejects . toThrow (
59+ "The selected resource is not a CodeQL file" ,
60+ ) ;
5461 } ) ;
5562 } ) ;
5663}
0 commit comments