@@ -3,35 +3,39 @@ import * as vscode from "vscode";
3
3
import * as fs from "fs" ;
4
4
import * as path from "path" ;
5
5
import * as os from 'os' ;
6
- import { getLispAndDclCompletions , getCmdAndVarsCompletionCandidates } from "../../completion/autocompletionProvider" ;
7
- import { ReadonlyDocument } from "../../project/readOnlyDocument" ;
6
+ import { getLispAndDclCompletions ,
7
+ getCmdAndVarsCompletionCandidates ,
8
+ getMatchingWord } from "../../completion/autocompletionProvider" ;
8
9
import { allCmdsAndSysvars } from "../../resources" ;
10
+ import { readFile2TextDocument } from "./helper" ;
9
11
let assert = chai . assert ;
10
12
const testDir = path . join ( __dirname + "/../../../extension/src/test" ) ;
11
13
const outputDir = path . join ( testDir + "/OutputFile" ) ;
12
- let LispFile = "" ;
13
- let DclFile = "" ;
14
- let lispdoc : vscode . TextDocument ;
15
- let dcldoc : vscode . TextDocument ;
14
+ const sourceDir = path . join ( testDir + "/SourceFile" ) ;
15
+ let getWordmatchLispFile = path . join ( sourceDir + "/getWordmatch.lsp" ) ;
16
+ let LispFile = path . join ( testDir + "/OutputFile/test.lsp" ) ,
17
+ DclFile = path . join ( testDir + "/OutputFile/test.dcl" ) ,
18
+ lispdoc : vscode . TextDocument ,
19
+ dcldoc : vscode . TextDocument ,
20
+ wordmatchDoc : vscode . TextDocument ;
16
21
17
22
fs . mkdir ( outputDir , { recursive : true } , ( err ) => {
18
23
if ( err ) {
19
24
return console . error ( err ) ;
20
25
}
21
26
} ) ;
22
27
23
- function createFakeTextDcoument ( ) {
24
- LispFile = path . join ( testDir + "/OutputFile/test.lsp" ) ;
25
- DclFile = path . join ( testDir + "/OutputFile/test.dcl" ) ;
28
+ async function createTextDcoument ( ) {
26
29
try {
27
30
if ( ! fs . existsSync ( LispFile ) ) {
28
31
fs . writeFileSync ( LispFile , "" ) ;
29
32
}
30
33
if ( ! fs . existsSync ( DclFile ) ) {
31
34
fs . writeFileSync ( DclFile , "" ) ;
32
35
}
33
- lispdoc = ReadonlyDocument . open ( LispFile ) ;
34
- dcldoc = ReadonlyDocument . open ( DclFile ) ;
36
+ lispdoc = await readFile2TextDocument ( LispFile ) ;
37
+ dcldoc = await readFile2TextDocument ( DclFile ) ;
38
+ wordmatchDoc = await readFile2TextDocument ( getWordmatchLispFile ) ;
35
39
} catch ( error ) {
36
40
console . log ( error ) ;
37
41
}
@@ -61,12 +65,10 @@ function getSuggestLabelCMD(cmd :string[] ,inputword : string,isupper :boolean){
61
65
62
66
suite ( "AutoCompletion Tests" , function ( ) {
63
67
// Windows only functions (vla-,vlax-,vlr-,vl-load-com,vl-load-reactors,vlisp-)
64
- suiteSetup ( ( ) => {
65
- createFakeTextDcoument ( ) ;
68
+ suiteSetup ( async ( ) => {
69
+ await createTextDcoument ( ) ;
66
70
} ) ;
67
71
test ( "AutoCompletion Test for de" , async function ( ) {
68
- // this.timeout(0);
69
- // await vscode.extensions.getExtension("Autodesk.autolispext").activate();
70
72
const inputword = "de" ;
71
73
try {
72
74
const isupper = false ;
@@ -268,4 +270,39 @@ suite("AutoCompletion Tests", function () {
268
270
}
269
271
} ) ;
270
272
273
+ //Test GetMatchingWord function
274
+ test ( "GetMatchingWord Test for [p,true]" , async function ( ) {
275
+ let fn = "GetMatchingWord Test for [p,true]" ;
276
+ try {
277
+ let cursorPos = new vscode . Position ( 0 , 0 ) ;
278
+ let expectedList = [ "p" , false ] ;
279
+ chai . expect ( getMatchingWord ( wordmatchDoc , cursorPos ) ) . to . eql ( expectedList ) ;
280
+ } catch ( err ) {
281
+ assert . fail ( `AutoCompletion test for ${ fn } failed` ) ;
282
+ }
283
+ } ) ;
284
+
285
+ test ( "GetMatchingWord Test for [A,false]" , async function ( ) {
286
+ let fn = "GetMatchingWord Test for [A,false]" ;
287
+ try {
288
+ let cursorPos = new vscode . Position ( 1 , 0 ) ;
289
+ let expectedList = [ "A" , true ] ;
290
+ chai . expect ( getMatchingWord ( wordmatchDoc , cursorPos ) ) . to . eql ( expectedList ) ;
291
+ } catch ( err ) {
292
+ assert . fail ( `AutoCompletion test for ${ fn } failed` ) ;
293
+ }
294
+ } ) ;
295
+
296
+ test ( "GetMatchingWord Test for [(,false]" , async function ( ) {
297
+ //Test wordSep = " &#^()[]|;'\".";
298
+ let fn = "GetMatchingWord Test for [(,false]" ;
299
+ try {
300
+ let cursorPos = new vscode . Position ( 2 , 3 ) ;
301
+ let expectedList = [ "(" , false ] ;
302
+ chai . expect ( getMatchingWord ( wordmatchDoc , cursorPos ) ) . to . eql ( expectedList ) ;
303
+ } catch ( err ) {
304
+ assert . fail ( `AutoCompletion test for ${ fn } failed` ) ;
305
+ }
306
+ } ) ;
307
+
271
308
} ) ;
0 commit comments