Skip to content

Commit 99f3ddc

Browse files
Tests: Automatically normalize line ends (#2934)
1 parent 8e93c5d commit 99f3ddc

File tree

91 files changed

+1162
-834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1162
-834
lines changed

.gitattributes

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
* text=auto
2-
3-
# Test files should not have their line endings modified by git
4-
/tests/languages/**/*.test binary

components/prism-false.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
greedy: true
1414
},
1515
'character-code': {
16-
pattern: /'[\s\S]/,
16+
pattern: /'(?:[^\r]|\r\n?)/,
1717
alias: 'number'
1818
},
1919
'assembler-code': {

components/prism-false.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/helper/test-case.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ module.exports = {
6666

6767
function updateFile() {
6868
// change the file
69-
const lineEnd = (/\r\n/.test(testCase.code) || !/\n/.test(testCase.code)) ? '\r\n' : '\n';
7069
const separator = '\n\n----------------------------------------------------\n\n';
7170
const pretty = TokenStreamTransformer.prettyprint(tokenStream, '\t');
7271

@@ -75,7 +74,9 @@ module.exports = {
7574
content += separator + testCase.comment.trim();
7675
}
7776
content += '\n';
78-
content = content.replace(/\r?\n/g, lineEnd);
77+
78+
// convert line ends to the line ends of the file
79+
content = content.replace(/\r\n?|\n/g, testCase.lineEndOnDisk);
7980

8081
fs.writeFileSync(filePath, content, 'utf-8');
8182
}
@@ -202,14 +203,19 @@ module.exports = {
202203
* @returns {ParsedTestCase}
203204
*
204205
* @typedef ParsedTestCase
206+
* @property {string} lineEndOnDisk The EOL format used by the parsed file.
205207
* @property {string} code
206208
* @property {string} expectedJson
207209
* @property {number} expectedLineOffset
208210
* @property {Array | null} expectedTokenStream
209211
* @property {string} comment
210212
*/
211213
parseTestCaseFile(filePath) {
212-
const testCaseSource = fs.readFileSync(filePath, 'utf8');
214+
let testCaseSource = fs.readFileSync(filePath, 'utf8');
215+
const lineEndOnDisk = (/\r\n?|\n/.exec(testCaseSource) || ['\n'])[0];
216+
// normalize line ends to \r\n
217+
testCaseSource = testCaseSource.replace(/\r\n?|\n/g, '\r\n');
218+
213219
const testCaseParts = testCaseSource.split(/^-{10,}[ \t]*$/m);
214220

215221
if (testCaseParts.length > 3) {
@@ -221,9 +227,10 @@ module.exports = {
221227
const comment = (testCaseParts[2] || '').trimStart();
222228

223229
const testCase = {
230+
lineEndOnDisk,
224231
code,
225232
expectedJson: expected,
226-
expectedLineOffset: code.split(/\r\n?|\n/g).length,
233+
expectedLineOffset: code.split(/\r\n/g).length,
227234
expectedTokenStream: expected ? JSON.parse(expected) : null,
228235
comment
229236
};

tests/languages/agda/comment_feature.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
----------------------------------------------------
88

99
[
10-
["comment", "{-\n\tThis is a\n\tmultiline comment\n-}"],
10+
["comment", "{-\r\n\tThis is a\r\n\tmultiline comment\r\n-}"],
1111
["comment", "-- This is a singleline comment"]
1212
]
1313

tests/languages/agda/function_feature.test

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ merge xs@(x ∷ xs₁) ys@(y ∷ ys₁) =
2929
["operator", "→"],
3030
" List A ",
3131
["operator", "→"],
32-
" List A\nmerge xs [] ",
32+
" List A\r\nmerge xs [] ",
3333
["operator", "="],
34-
" xs\nmerge [] ys ",
34+
" xs\r\nmerge [] ys ",
3535
["operator", "="],
36-
" ys\nmerge xs",
36+
" ys\r\nmerge xs",
3737
["punctuation", "@"],
3838
["punctuation", "("],
3939
"x ∷ xs₁",
@@ -44,7 +44,8 @@ merge xs@(x ∷ xs₁) ys@(y ∷ ys₁) =
4444
"y ∷ ys₁",
4545
["punctuation", ")"],
4646
["operator", "="],
47-
"\n\tif x < y then x ∷ merge xs₁ ys\n\t\t\t\t\t else y ∷ merge xs ys₁"
47+
48+
"\r\n\tif x < y then x ∷ merge xs₁ ys\r\n\t\t\t\t\t else y ∷ merge xs ys₁"
4849
]
4950

5051
----------------------------------------------------

tests/languages/agda/module_feature.test

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎) renaming (begin_ to star
1111
["punctuation", "."],
1212
"test ",
1313
["keyword", "where"],
14+
1415
["keyword", "import"],
1516
" Relation",
1617
["punctuation", "."],
1718
"Binary",
1819
["punctuation", "."],
19-
"PropositionalEquality as Eq\n",
20+
"PropositionalEquality as Eq\r\n",
21+
2022
["keyword", "open"],
2123
" Eq ",
2224
["keyword", "hiding"],
@@ -25,6 +27,7 @@ open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎) renaming (begin_ to star
2527
["punctuation", ";"],
2628
" refl",
2729
["punctuation", ")"],
30+
2831
["keyword", "open"],
2932
" Eq",
3033
["punctuation", "."],

tests/languages/agda/record_feature.test

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ open Fin
1818
["operator", ":"],
1919
["keyword", "Set"],
2020
["keyword", "where"],
21+
2122
["keyword", "constructor"],
22-
" _[_]\n\t",
23+
" _[_]\r\n\t",
24+
2325
["keyword", "field"],
26+
2427
["function", "⟦_⟧ "],
2528
["operator", ":"],
26-
" Nat\n\t\t",
29+
" Nat\r\n\t\t",
30+
2731
["function", "proof "],
2832
["operator", ":"],
29-
" suc ⟦_⟧ ≤ n\n",
33+
" suc ⟦_⟧ ≤ n\r\n",
34+
3035
["keyword", "open"],
3136
" Fin"
3237
]

tests/languages/al/comment_feature.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[
1010
["comment", "// comment"],
1111
["comment", "/**/"],
12-
["comment", "/*\n comment\n*/"]
12+
["comment", "/*\r\n comment\r\n*/"]
1313
]
1414

1515
----------------------------------------------------

tests/languages/antlr4/action_feature.test

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ from LexerAdaptor import LexerAdaptor
2121
["content", " superClass = LexerAdaptor; "],
2222
["punctuation", "}"]
2323
]],
24+
2425
["annotation", "@lexer::header"],
2526
["action", [
2627
["punctuation", "{"],
27-
["content", "\n import { Token } from 'antlr4ts/Token';\n import { CommonToken } from 'antlr4ts/CommonToken';\n import { Python3Parser } from './Python3Parser';\n"],
28+
["content", "\r\n import { Token } from 'antlr4ts/Token';\r\n import { CommonToken } from 'antlr4ts/CommonToken';\r\n import { Python3Parser } from './Python3Parser';\r\n"],
2829
["punctuation", "}"]
2930
]],
31+
3032
["definition", "END"],
3133
["punctuation", ":"],
3234
["string", "'end'"],
@@ -36,10 +38,11 @@ from LexerAdaptor import LexerAdaptor
3638
["punctuation", "}"]
3739
]],
3840
["punctuation", ";"],
41+
3942
["annotation", "@header"],
4043
["action", [
4144
["punctuation", "{"],
42-
["content", "\nfrom LexerAdaptor import LexerAdaptor\n"],
45+
["content", "\r\nfrom LexerAdaptor import LexerAdaptor\r\n"],
4346
["punctuation", "}"]
4447
]]
4548
]

tests/languages/antlr4/comment_feature.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[
99
["comment", "// comment"],
10-
["comment", "/*\n comment\n*/"]
10+
["comment", "/*\r\n comment\r\n*/"]
1111
]
1212

1313
----------------------------------------------------

tests/languages/bbcode/tag_feature.test

+17-6
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,25 @@
2929
]],
3030
["punctuation", "]"]
3131
]],
32+
3233
["tag", [
3334
["tag", [
3435
["punctuation", "["],
3536
"*"
3637
]],
3738
["punctuation", "]"]
3839
]],
39-
"Entry A\n ",
40+
"Entry A\r\n ",
41+
4042
["tag", [
4143
["tag", [
4244
["punctuation", "["],
4345
"*"
4446
]],
4547
["punctuation", "]"]
4648
]],
47-
"Entry B\n",
49+
"Entry B\r\n",
50+
4851
["tag", [
4952
["tag", [
5053
["punctuation", "[/"],
@@ -64,22 +67,25 @@
6467
]],
6568
["punctuation", "]"]
6669
]],
70+
6771
["tag", [
6872
["tag", [
6973
["punctuation", "["],
7074
"*"
7175
]],
7276
["punctuation", "]"]
7377
]],
74-
"Entry 1\n ",
78+
"Entry 1\r\n ",
79+
7580
["tag", [
7681
["tag", [
7782
["punctuation", "["],
7883
"*"
7984
]],
8085
["punctuation", "]"]
8186
]],
82-
"Entry 2\n",
87+
"Entry 2\r\n",
88+
8389
["tag", [
8490
["tag", [
8591
["punctuation", "[/"],
@@ -110,7 +116,8 @@
110116
]],
111117
["punctuation", "]"]
112118
]],
113-
" or\n",
119+
" or\r\n",
120+
114121
["tag", [
115122
["tag", [
116123
["punctuation", "["],
@@ -131,7 +138,8 @@
131138
]],
132139
["punctuation", "]"]
133140
]],
134-
" or\n",
141+
" or\r\n",
142+
135143
["tag", [
136144
["tag", [
137145
["punctuation", "["],
@@ -151,6 +159,7 @@
151159
]],
152160
["punctuation", "]"]
153161
]],
162+
154163
["tag", [
155164
["tag", [
156165
["punctuation", "["],
@@ -166,6 +175,7 @@
166175
]],
167176
["punctuation", "]"]
168177
]],
178+
169179
["tag", [
170180
["tag", [
171181
["punctuation", "["],
@@ -211,6 +221,7 @@
211221
]],
212222
["punctuation", "]"]
213223
]],
224+
214225
["tag", [
215226
["tag", [
216227
["punctuation", "["],

tests/languages/brightscript/property_feature.test

+3-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ a = { foo: 5, bar: 6, "foo bar": 7 }
99

1010
[
1111
["punctuation", "{"],
12-
["property", "foo"],
13-
["operator", ":"],
14-
["number", "4"],
15-
["property", "\"bar\""],
16-
["operator", ":"],
17-
["number", "5"],
12+
["property", "foo"], ["operator", ":"], ["number", "4"],
13+
["property", "\"bar\""], ["operator", ":"], ["number", "5"],
1814
["punctuation", "}"],
1915

20-
"\n\na ",
16+
"\r\n\r\na ",
2117
["operator", "="],
2218
["punctuation", "{"],
2319
["property", "foo"],

tests/languages/clojure/string_feature.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ string"
88
[
99
["string", "\"\""],
1010
["string", "\"Fo\\\"obar\""],
11-
["string", "\"multi-line\nstring\""]
11+
["string", "\"multi-line\r\nstring\""]
1212
]
1313

1414
----------------------------------------------------

tests/languages/cmake/string_feature.test

+22-12
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,39 @@ string"
1010

1111
[
1212
["string", ["\"This is a string\""]],
13-
["string", ["\"This is \nmulti\nline\nstring\""]],
13+
["string", ["\"This is \r\nmulti\r\nline\r\nstring\""]],
1414
["string", [
1515
"\"",
1616
["interpolation", [
17-
["punctuation", "${"], ["variable", "VAR"], ["punctuation", "}"]]
18-
],
17+
["punctuation", "${"],
18+
["variable", "VAR"],
19+
["punctuation", "}"]
20+
]],
1921
"with",
2022
["interpolation", [
21-
["punctuation", "${"], ["variable", "BAR"], ["punctuation", "}"]]
22-
], "\""]
23-
],
23+
["punctuation", "${"],
24+
["variable", "BAR"],
25+
["punctuation", "}"]
26+
]],
27+
"\""
28+
]],
2429
["string", [
2530
"\"",
2631
["interpolation", [
27-
["punctuation", "${"], ["variable", "FOO"], ["punctuation", "}"]]
28-
],
32+
["punctuation", "${"],
33+
["variable", "FOO"],
34+
["punctuation", "}"]
35+
]],
2936
" with ",
3037
["interpolation", [
31-
["punctuation", "${"], ["variable", "BAR"], ["punctuation", "}"]]
32-
], "\""]
33-
]
38+
["punctuation", "${"],
39+
["variable", "BAR"],
40+
["punctuation", "}"]
41+
]],
42+
"\""
43+
]]
3444
]
3545

3646
----------------------------------------------------
3747

38-
Checks for strings.
48+
Checks for strings.

tests/languages/cobol/class-name_feature.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ greeting pic x(12) value is "Hello World".
6969
]],
7070
["punctuation", "."],
7171

72-
"\n\ngreeting ",
72+
"\r\n\r\ngreeting ",
7373
["keyword", "pic"],
7474
["class-name", [
7575
"x",
@@ -81,4 +81,4 @@ greeting pic x(12) value is "Hello World".
8181
["keyword", "is"],
8282
["string", "\"Hello World\""],
8383
["punctuation", "."]
84-
]
84+
]

0 commit comments

Comments
 (0)