Skip to content

Commit 17a7bdb

Browse files
authored
Add snapshot / unit tests (#27)
Add snapshot / unit tests
2 parents 7ff15a6 + 93a7147 commit 17a7bdb

13 files changed

+3640
-4
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ stages:
1010
jobs:
1111
include:
1212
- stage: build
13-
script: yarn build
13+
script: yarn build && yarn test
1414
- stage: release
1515
script: bin/ci-release.sh
1616

.vscodeignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
tests/**
55
src/**
66
node_modules
7-
.gitkeep
7+
.gitkeep
8+
scripts

bin/ci-release.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ NEW_VERSION=${TRAVIS_TAG#"v"}
77
# Build the extension
88
yarn install
99
yarn build
10+
yarn test
1011

1112
# Update package.json and CHANGELOG.md
1213
set-up-ssh() {

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848
"ts-node": "^8.1.0",
4949
"tsc": "^1.20150623.0",
5050
"typescript": "^3.3.3",
51+
"vscode-tmgrammar-test": "0.0.5",
5152
"vsce": "^1.59.0"
5253
},
5354
"scripts": {
5455
"vscode:prepublish": "test -f ./syntaxes/Scala.tmLanguage.json",
5556
"vscode:publish": "vsce publish --yarn",
56-
"build": "ts-node src/typescript/GenerateTmLanguageFile.ts > ./syntaxes/Scala.tmLanguage.json"
57+
"build": "ts-node src/typescript/GenerateTmLanguageFile.ts > ./syntaxes/Scala.tmLanguage.json",
58+
"test": "node scripts/unit.js && node scripts/snap.js"
5759
}
5860
}

scripts/snap.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var cp = require('child_process')
2+
3+
try {
4+
cp.execSync("npx vscode-tmgrammar-snap -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/snap/**/*.test.scala'",
5+
{ stdio: 'inherit' })
6+
} catch(err) {
7+
console.debug(err.toString())
8+
process.exit(-1)
9+
}

scripts/unit.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var cp = require('child_process')
2+
3+
try {
4+
cp.execSync("npx vscode-tmgrammar-test -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/unit/**/*.test.scala'",
5+
{ stdio: 'inherit' })
6+
} catch(err) {
7+
console.debug(err.toString())
8+
process.exit(-1)
9+
}

tests/snap/lexical.test.scala

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
object ExampleIdentifiers {
3+
val x = 3
4+
val Object = 3
5+
val maxIndex = 3
6+
val p2p = 3
7+
val empty_? = 3
8+
val + = 3
9+
val `yield` = 3
10+
val αρετη = 3
11+
val _y = 3
12+
val dot_product_* = 3
13+
val __system = 3
14+
val _MAX_LEN_ = 3
15+
}
16+
17+
object IntegerLiterals {
18+
(0, 21, 0xFFFFFFFF, -42L)
19+
}
20+
21+
object FloatingPointLiterals {
22+
( 0.0, 1e30f, 3.14159f, 1.0e-100, .1 )
23+
}
24+
25+
object Boolean {
26+
(true, false)
27+
}
28+
29+
object CharacterLiterals {
30+
('a', '\u0041', '\n', '\t')
31+
}
32+
33+
object StringLiterals {
34+
("Hello,\nWorld!", "This string contains a \" character.")
35+
36+
"""the present string
37+
spans three
38+
lines."""
39+
40+
"""the present string
41+
|spans three
42+
|lines.""".stripMargin
43+
44+
45+
val escapeSequences = "\b\t\n\f\r\"\'\\"
46+
47+
s"$x plain ${val x = y}"
48+
custom"$x plain ${val x = y}"
49+
50+
s"""$x plain ${val x = y}"""
51+
custom"""$x plain ${val x = y}"""
52+
}
53+
54+
object Symbols {
55+
('x, 'X, 'αρετη, '=, '+ )
56+
}
57+
58+
// single line comment
59+
60+
/*
61+
62+
multiline comment*/
63+
64+
/**
65+
* Scaladoc comment
66+
* @scaladoc @param
67+
*/
68+
69+
/* nested /* multi-line */ comment */
70+
71+
72+
object Xml {
73+
val b = <book>
74+
<title>The Scala Language Specification</title>
75+
<version>{scalaBook.version}</version>
76+
<authors>{scalaBook.authors.mkList("", ", ", "")}</authors>
77+
</book>
78+
}

0 commit comments

Comments
 (0)