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

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

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/helper/test-case.js

Lines changed: 11 additions & 4 deletions
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

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

Lines changed: 5 additions & 4 deletions
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

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

Lines changed: 8 additions & 3 deletions
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

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

Lines changed: 5 additions & 2 deletions
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
]

0 commit comments

Comments
 (0)