1
+ var should = require ( 'should' ) ;
2
+ var promisify = require ( "util" ) . promisify ;
3
+ let path = require ( 'path' ) ;
4
+
5
+ let hljs = require ( "highlightjs" ) ;
6
+ let iecst = require ( "../src/iecst" ) ;
7
+ hljs . registerLanguage ( "iecst" , iecst ) ;
8
+
9
+ const fs = require ( "fs" ) ;
10
+
11
+ const readdir = promisify ( fs . readdir ) ,
12
+ readFile = promisify ( fs . readFile ) ;
13
+
14
+ describe ( "IEC 61131-3 ST Tests" , ( ) => {
15
+ it ( "Test markup" , async ( ) => {
16
+ var files = await readdir ( path . join ( __dirname , "markup" ) ) ;
17
+ files = files . filter ( f => ! f . includes ( ".expect." ) ) ;
18
+ for ( var f of files ) {
19
+ let fn = path . join ( __dirname , "markup" , f ) ;
20
+ let expectFn = fn . replace ( ".txt" , ".expect.txt" ) ;
21
+ var code = await readFile ( fn , "utf-8" ) ;
22
+ var exp = await readFile ( expectFn , "utf-8" ) ;
23
+ var actual = hljs . highlight ( "iecst" , code ) . value ;
24
+ actual . trim ( ) . should . eql ( exp . trim ( ) , f ) ;
25
+ }
26
+ } ) ;
27
+
28
+ it ( "should be detected correctly" , async ( ) => {
29
+ var code = await readFile ( path . join ( __dirname , "detect/detect.txt" ) , "utf-8" ) ;
30
+ var actual = hljs . highlightAuto ( code , [ 'iecst' ] ) . language ;
31
+ actual . should . eql ( "iecst" ) ;
32
+ } ) ;
33
+ } ) ;
0 commit comments