Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4bde54b

Browse files
committedMay 22, 2019
Add vscode-tmgrammar-test module, include tests in ci, add unit and snapshot tests for lexical constructs
1 parent 7ff15a6 commit 4bde54b

File tree

10 files changed

+4190
-3
lines changed

10 files changed

+4190
-3
lines changed
 

‎.vscodeignore

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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.4",
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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/sample.test.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SYNTAX TEST "source.scala"
2+
3+
// line which start with a <comment token> but don't have valid assertions are ignored
4+
5+
class Stack[A] {
6+
// <----- keyword.declaration.scala
7+
// ^ - keyword.declaration.scala entity.name.class.declaration
8+
// ^^^^^ entity.name.class.declaration
9+
// ^ source.scala meta.bracket.scala
10+
// ^ entity.name.class
11+
// ^ meta.bracket.scala
12+
// ^ punctuation.section.block.begin.scala
13+
private var elements: List[A] = Nil
14+
def push(x: A) { elements = x :: elements }
15+
def peek: A = elements.head
16+
def pop(): A = {
17+
val currentTop = peek
18+
elements = elements.tail
19+
currentTop
20+
}
21+
// <~~- punctuation.section.block.end.scala
22+
}
23+

‎tests/snap/lexical.test.scala

Lines changed: 78 additions & 0 deletions
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+
}

‎tests/snap/lexical.test.scala.snap

Lines changed: 3845 additions & 0 deletions
Large diffs are not rendered by default.

‎tests/unit/lexical.test.scala

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// SYNTAX TEST "source.scala"
2+
3+
object ExampleIdentifiers {
4+
val x = 3
5+
// ^ variable.other.declaration.scala
6+
val Object = 3
7+
val maxIndex = 3
8+
// ^^^^^^^^ variable.other.declaration.scala
9+
val p2p = 3
10+
// ^^^ variable.other.declaration.scala
11+
val empty_? = 3
12+
// ^^^^^^^ variable.other.declaration.scala
13+
val + = 3
14+
// ^ variable.other.declaration.scala
15+
val `yield` = 3
16+
// ^^^^^^^ variable.other.declaration.scala
17+
val αρετη = 3
18+
val _y = 3
19+
// ^^ variable.other.declaration.scala
20+
val dot_product_* = 3
21+
// ^^^^^^^^^^^^^ variable.other.declaration.scala
22+
val __system = 3
23+
// ^^^^^^^^ variable.other.declaration.scala
24+
val _MAX_LEN_ = 3
25+
// ^^^^^^^^^ variable.other.declaration.scala
26+
}
27+
28+
object IntegerLiterals {
29+
(0, 21, 0xFFFFFFFF, -42L)
30+
// ^ constant.numeric.scala
31+
// ^^ constant.numeric.scala
32+
// ^^^^^^^^^^ constant.numeric.scala
33+
// ^ keyword.operator.arithmetic.scala
34+
// ^^^ constant.numeric.scala
35+
}
36+
37+
object FloatingPointLiterals {
38+
( 0.0, 1e30f, 3.14159f, 1.0e-100, .1 )
39+
// ^^^ constant.numeric.scala
40+
// ^^^^^^^^ constant.numeric.scala
41+
// ^^^^^^^^ constant.numeric.scala
42+
// ^ constant.numeric.scala
43+
}
44+
45+
object Boolean {
46+
(true, false)
47+
// ^^^^ constant.language.scala
48+
// ^^^^^ constant.language.scala
49+
}
50+
51+
object CharacterLiterals {
52+
('a', '\u0041', '\n', '\t')
53+
// ^ punctuation.definition.character.begin.scala
54+
// ^^^ constant.character.literal.scala
55+
// ^ punctuation.definition.character.end.scala
56+
// ^^^^^^^^ constant.character.literal.scala
57+
// ^^^^^^ constant.character.escape.scala
58+
// ^^ constant.character.escape.scala
59+
// ^^ constant.character.escape.scala
60+
}
61+
62+
object StringLiterals {
63+
("Hello,\nWorld!", "This string contains a \" character.")
64+
// ^ punctuation.definition.string.begin.scala
65+
// ^^^^^^^^^^^^^^^^ string.quoted.double.scala
66+
// ^^ constant.character.escape.scala
67+
// ^ punctuation.definition.string.end.scala
68+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.scala
69+
"""the present string
70+
// ^^^ punctuation.definition.string.begin.scala
71+
// ^^^^^^^^^^^^^^^^^^^^^ string.quoted.triple.scala
72+
spans three
73+
// ^^^^^^^^^^^ string.quoted.triple.scala
74+
lines."""
75+
// ^^^^^^^^^ string.quoted.triple.scala
76+
// ^^^ punctuation.definition.string.end.scala
77+
78+
"""the present string
79+
|spans three
80+
|lines.""".stripMargin
81+
82+
83+
val escapeSequences = "\b\t\n\f\r\"\'\\"
84+
// ^^^^^^^^^^^^^^^^^^ string.quoted.double.scala
85+
// ^^^^^^^^^^^^^^^^ constant.character.escape.scala
86+
87+
s"$x plain ${val x = y}"
88+
//^ keyword.interpolation.scala
89+
// ^ punctuation.definition.string.begin.scala
90+
// ^ punctuation.definition.template-expression.begin.scala
91+
// ^ - string.quoted.double.interpolated.scala string.quoted.double.scala
92+
// ^^^^^^^ string.quoted.double.interpolated.scala
93+
// ^^ punctuation.definition.template-expression.begin.scala
94+
// ^^^ keyword.declaration.stable.scala
95+
// ^^^^^^^^^ - string.quoted.double.interpolated.scala string.quoted.double.scala
96+
// ^ punctuation.definition.template-expression.scala punctuation.definition.template-expression.end.scala
97+
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
98+
99+
custom"$x plain ${val x = y}"
100+
//^^^^^^ keyword.interpolation.scala
101+
// ^ punctuation.definition.string.begin.scala
102+
// ^ punctuation.definition.template-expression.begin.scala
103+
// ^ - string.quoted.double.interpolated.scala string.quoted.double.scala
104+
// ^^^^^^^ string.quoted.double.interpolated.scala
105+
// ^^ punctuation.definition.template-expression.begin.scala
106+
// ^^^ keyword.declaration.stable.scala
107+
// ^^^^^^^^^ - string.quoted.double.interpolated.scala string.quoted.double.scala
108+
// ^ punctuation.definition.template-expression.scala punctuation.definition.template-expression.end.scala
109+
// ^ string.quoted.double.interpolated.scala punctuation.definition.string.end.scala
110+
111+
s"""$x plain ${val x = y}"""
112+
//^ keyword.interpolation.scala
113+
// ^^^ punctuation.definition.string.begin.scala
114+
// ^ punctuation.definition.template-expression.begin.scala
115+
// ^ - string.quoted.triple.interpolated.scala string.quoted.triple.scala
116+
// ^^^^^^^ string.quoted.triple.interpolated.scala
117+
// ^^ punctuation.definition.template-expression.begin.scala
118+
// ^^^ keyword.declaration.stable.scala
119+
// ^^^^^^^^^ - string.quoted.triple.interpolated.scala string.quoted.triple.scala
120+
// ^ punctuation.definition.template-expression.scala punctuation.definition.template-expression.end.scala
121+
// ^^^ string.quoted.triple.interpolated.scala punctuation.definition.string.end.scala
122+
custom"""$x plain ${val x = y}"""
123+
//^^^^^^ keyword.interpolation.scala
124+
// ^^^ punctuation.definition.string.begin.scala
125+
// ^ punctuation.definition.template-expression.begin.scala
126+
// ^ - string.quoted.triple.interpolated.scala string.quoted.triple.scala
127+
// ^^^^^^^ string.quoted.triple.interpolated.scala
128+
// ^^ punctuation.definition.template-expression.begin.scala
129+
// ^^^ keyword.declaration.stable.scala
130+
// ^^^^^^^^^ - string.quoted.triple.interpolated.scala string.quoted.triple.scala
131+
// ^ punctuation.definition.template-expression.scala punctuation.definition.template-expression.end.scala
132+
// ^^^ string.quoted.triple.interpolated.scala punctuation.definition.string.end.scala
133+
}
134+
135+
object Symbols {
136+
('x, 'X, 'αρετη, '=, '+ )
137+
// ^^ constant.other.symbol.scala
138+
// ^^ constant.other.symbol.scala
139+
// ^^^^^^ constant.other.symbol.scala
140+
}
141+
142+
// single line comment
143+
// ^^ punctuation.definition.comment.scala
144+
// ^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.scala
145+
146+
/*
147+
// ^^ punctuation.definition.comment.scala
148+
multiline comment*/
149+
// ^^^^^^^^^^^^^^^^^^^ comment.block.scala
150+
/**
151+
* Scaladoc comment
152+
* @scaladoc @param
153+
*/
154+
155+
/* nested /* multi-line */ comment */
156+
157+
158+
object Xml {
159+
val b = <book>
160+
// ^ punctuation.definition.tag.xml
161+
// ^^^^ entity.name.tag.localname.xml
162+
// ^ punctuation.definition.tag.xml
163+
// ^^^^^^ meta.tag.xml
164+
<title>The Scala Language Specification</title>
165+
// ^^^ entity.name.class
166+
// ^^^^^ entity.name.class
167+
// ^^^^^^^^ entity.name.class
168+
// ^^^^^^^^^^^^^ entity.name.class
169+
<version>{scalaBook.version}</version>
170+
<authors>{scalaBook.authors.mkList("", ", ", "")}</authors>
171+
</book>
172+
}

‎yarn.lock

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ combined-stream@~0.0.4:
161161
dependencies:
162162
delayed-stream "0.0.5"
163163

164-
commander@^2.8.1:
164+
commander@^2.20.0, commander@^2.8.1:
165165
version "2.20.0"
166166
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
167167
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==
@@ -223,6 +223,11 @@ diff@^3.1.0:
223223
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
224224
integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==
225225

226+
diff@^4.0.1:
227+
version "4.0.1"
228+
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff"
229+
integrity sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==
230+
226231
dom-serializer@0, dom-serializer@~0.1.1:
227232
version "0.1.1"
228233
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.1.tgz#1ec4059e284babed36eec2941d4a970a189ce7c0"
@@ -371,6 +376,18 @@ glob@^7.0.6:
371376
once "^1.3.0"
372377
path-is-absolute "^1.0.0"
373378

379+
glob@^7.1.4:
380+
version "7.1.4"
381+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
382+
integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==
383+
dependencies:
384+
fs.realpath "^1.0.0"
385+
inflight "^1.0.4"
386+
inherits "2"
387+
minimatch "^3.0.4"
388+
once "^1.3.0"
389+
path-is-absolute "^1.0.0"
390+
374391
has-flag@^3.0.0:
375392
version "3.0.0"
376393
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
@@ -552,6 +569,11 @@ mute-stream@~0.0.4:
552569
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
553570
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==
554571

572+
nan@^2.12.1:
573+
version "2.14.0"
574+
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
575+
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==
576+
555577
node-uuid@~1.4.0:
556578
version "1.4.8"
557579
resolved "https://registry.yarnpkg.com/node-uuid/-/node-uuid-1.4.8.tgz#b040eb0923968afabf8d32fb1f17f1167fdab907"
@@ -593,6 +615,13 @@ once@^1.3.0:
593615
dependencies:
594616
wrappy "1"
595617

618+
oniguruma@^7.0.0:
619+
version "7.1.0"
620+
resolved "https://registry.yarnpkg.com/oniguruma/-/oniguruma-7.1.0.tgz#106ddf7eb42507d0442ac68b187c4f7fdf052c83"
621+
integrity sha512-mV+6HcDNQ38vM8HVKM+MJyXO4EtSigwIZhq023A4rA8Am4dMlGhUkPwudDykExYR45oLrssR/Ep7PZCQ1OM3pA==
622+
dependencies:
623+
nan "^2.12.1"
624+
596625
os-homedir@^1.0.0:
597626
version "1.0.2"
598627
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
@@ -890,6 +919,24 @@ vsce@^1.59.0:
890919
yauzl "^2.3.1"
891920
yazl "^2.2.2"
892921

922+
vscode-textmate@^4.1.1:
923+
version "4.1.1"
924+
resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-4.1.1.tgz#857e836fbc13a376ec624242437e1747d79610a9"
925+
integrity sha512-xBjq9LH6fMhWDhIVkbKlB1JeCu6lT3FI/QKN24Xi4RKPBUm16IhHTqs6Q6SUGewkNsFZGkb1tJdZsuMnlmVpgw==
926+
dependencies:
927+
oniguruma "^7.0.0"
928+
929+
vscode-tmgrammar-test@0.0.4:
930+
version "0.0.4"
931+
resolved "https://registry.yarnpkg.com/vscode-tmgrammar-test/-/vscode-tmgrammar-test-0.0.4.tgz#8909e002fd3d2264a15fb06dfe36341145e7d799"
932+
integrity sha512-3OBRgd0oDDegMcLd0yeJnsPlw7kIwWjO3GUI3YDH2OgOFz/d9ObVu9dCaf6EHsAYHExADYwdW9vqZOF8uL/+nQ==
933+
dependencies:
934+
chalk "^2.4.2"
935+
commander "^2.20.0"
936+
diff "^4.0.1"
937+
glob "^7.1.4"
938+
vscode-textmate "^4.1.1"
939+
893940
vso-node-api@6.1.2-preview:
894941
version "6.1.2-preview"
895942
resolved "https://registry.yarnpkg.com/vso-node-api/-/vso-node-api-6.1.2-preview.tgz#aab3546df2451ecd894e071bb99b5df19c5fa78f"

0 commit comments

Comments
 (0)
Please sign in to comment.