1
1
import * as assert from 'assert' ;
2
2
import * as vscode from 'vscode' ;
3
3
import * as fs from 'fs' ;
4
- import * as paths from 'path' ;
4
+ import * as path from 'path' ;
5
5
import * as vsctm from 'vscode-textmate' ;
6
+ import * as oniguruma from 'vscode-oniguruma' ;
6
7
import { suite , test } from 'mocha' ;
8
+ import { IRawGrammar } from 'vscode-textmate/release/rawGrammar' ;
7
9
8
10
/**
9
11
* Resolves a package relative path (relative to root folder / package.json folder) to the actual path
10
- * @param path the package relative path to resolve to an actual path
12
+ * @param pathStr the package relative path to resolve to an actual path
11
13
*/
12
- function res ( path : string ) : string {
13
- return paths . join ( __dirname , "../../../" , path ) ;
14
+ function res ( pathStr : string ) : string {
15
+ return path . join ( __dirname , "../../../" , pathStr ) ;
14
16
}
15
17
16
- function readFile ( path : string ) : Promise < Buffer > {
18
+ const wasmBin = fs . readFileSync ( res ( 'node_modules/vscode-oniguruma/release/onig.wasm' ) ) . buffer ;
19
+ const vscodeOnigurumaLib = oniguruma . loadWASM ( wasmBin ) . then ( ( ) => {
20
+ return {
21
+ createOnigScanner : function ( patterns : any ) { return new oniguruma . OnigScanner ( patterns ) ; } ,
22
+ createOnigString : function ( s : any ) { return new oniguruma . OnigString ( s ) ; }
23
+ } ;
24
+ } ) ;
25
+
26
+ function readFile ( pathStr : string ) : Promise < Buffer > {
17
27
return new Promise ( ( resolve , reject ) => {
18
- fs . readFile ( res ( path ) , ( error , data ) => error ? reject ( error ) : resolve ( data ) ) ;
28
+ fs . readFile ( res ( pathStr ) , ( error , data ) => error ? reject ( error ) : resolve ( data ) ) ;
19
29
} ) ;
20
30
}
21
31
22
32
const registry = new vsctm . Registry ( {
23
- loadGrammar : async ( scopeName ) : Promise < vsctm . IRawGrammar | undefined | null > => {
33
+ onigLib : vscodeOnigurumaLib ,
34
+ loadGrammar : async ( scopeName ) : Promise < IRawGrammar | undefined | null > => {
24
35
if ( scopeName === 'source.diet' ) {
25
36
const data = await readFile ( 'syntaxes/diet.json' ) ;
26
37
return vsctm . parseRawGrammar ( data . toString ( ) , 'syntaxes/diet.json' ) ;
@@ -60,7 +71,7 @@ function testSyntaxes(grammar: vsctm.IGrammar, folder: string, ext: string) {
60
71
61
72
let ruleStack = vsctm . INITIAL ;
62
73
63
- const text = await readFile ( paths . join ( folder , file ) ) ;
74
+ const text = await readFile ( path . join ( folder , file ) ) ;
64
75
const lines = text . toString ( ) . split ( / \r ? \n / g) ;
65
76
const tokens = lines . map ( line => grammar . tokenizeLine ( line , ruleStack ) . tokens . map ( a => {
66
77
return {
@@ -71,9 +82,9 @@ function testSyntaxes(grammar: vsctm.IGrammar, folder: string, ext: string) {
71
82
} ) ) ;
72
83
73
84
const actual = tokens . map ( line => JSON . stringify ( line ) ) . join ( "\n" ) ;
74
- fs . writeFileSync ( res ( paths . join ( folder , file ) + ".actual" ) , actual ) ;
85
+ fs . writeFileSync ( res ( path . join ( folder , file ) + ".actual" ) , actual ) ;
75
86
76
- const expectedText = await readFile ( paths . join ( folder , file ) + ".expected" ) ;
87
+ const expectedText = await readFile ( path . join ( folder , file ) + ".expected" ) ;
77
88
const expectedLines = expectedText . toString ( ) . split ( / \r ? \n / g) ;
78
89
const expectedTokens = expectedLines . map ( line => JSON . parse ( line ) ) ;
79
90
@@ -113,4 +124,4 @@ suite("syntax tests", () => {
113
124
return testSyntaxes ( grammar , "src/test/ci/syntax/dml" , ".dml" ) ;
114
125
} ) ;
115
126
} ) ;
116
- } ) ;
127
+ } ) ;
0 commit comments