Skip to content

Commit 2f40a7e

Browse files
committed
Tests
1 parent c9ab1b7 commit 2f40a7e

File tree

12 files changed

+818
-48
lines changed

12 files changed

+818
-48
lines changed

package-lock.json

Lines changed: 727 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "src/iecst.js",
66
"scripts": {
77
"postpublish": "PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag v$PACKAGE_VERSION && git push --tags",
8-
"test": "jasmine"
8+
"test": "./node_modules/.bin/mocha --reporter spec"
99
},
1010
"files": [
1111
"src/iecst.js",
@@ -35,5 +35,11 @@
3535
"devDependencies": {
3636
"highlight.js": "^10.4.1",
3737
"jasmine": "^3.5.0"
38+
},
39+
"dependencies": {
40+
"highlightjs": "^9.16.2",
41+
"mocha": "^8.3.2",
42+
"should": "^13.2.3",
43+
"user": "0.0.0"
3844
}
3945
}

spec/iecst-spec.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

spec/support/jasmine.json

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
CONFIGURATION DefaultCfg
2-
VAR_GLOBAL
3-
Start_Stop AT %IX0.0: BOOL; (* This is comment *)
4-
END_VAR
1+
CONFIGURATION DefaultCfg
2+
VAR_GLOBAL
3+
Start_Stop AT %IX0.0: BOOL; (* This is comment *)
4+
END_VAR
55
END_CONFIGURATION

test/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
});
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<span class="hljs-title">CONFIGURATION</span> DefaultCfg
2-
<span class="hljs-title">VAR_GLOBAL</span>
3-
Start_Stop <span class="hljs-keyword">AT</span> <span class="hljs-symbol">%IX0.0</span>: <span class="hljs-built_in">BOOL</span>; <span class="hljs-comment">(* This is comment *)</span>
4-
<span class="hljs-title">END_VAR</span>
1+
<span class="hljs-title">CONFIGURATION</span> DefaultCfg
2+
<span class="hljs-title">VAR_GLOBAL</span>
3+
Start_Stop <span class="hljs-keyword">AT</span> <span class="hljs-symbol">%IX0.0</span>: <span class="hljs-built_in">BOOL</span>; <span class="hljs-comment">(* This is comment *)</span>
4+
<span class="hljs-title">END_VAR</span>
55
<span class="hljs-title">END_CONFIGURATION</span>

test/markup/sample.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIGURATION DefaultCfg
2+
VAR_GLOBAL
3+
Start_Stop AT %IX0.0: BOOL; (* This is comment *)
4+
END_VAR
5+
END_CONFIGURATION

test/markup/sample2.expect.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<span class="hljs-title">TYPE</span> StructName : <span class="hljs-title">STRUCT</span>
2+
xStart : <span class="hljs-built_in">BOOL</span>; <span class="hljs-comment">(* Start *)</span>
3+
xStop : <span class="hljs-built_in">BOOL</span>; <span class="hljs-comment">(* Stop *)</span>
4+
<span class="hljs-title">END_STRUCT</span>
5+
<span class="hljs-title">END_TYPE</span>

test/markup/sample2.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
TYPE StructName : STRUCT
2+
xStart : BOOL; (* Start *)
3+
xStop : BOOL; (* Stop *)
4+
END_STRUCT
5+
END_TYPE

0 commit comments

Comments
 (0)