diff --git a/test/toml-test.js b/test/toml-test.js index bc8cc8c..959fa0a 100644 --- a/test/toml-test.js +++ b/test/toml-test.js @@ -16,6 +16,18 @@ const EXPECT_FAILURE = [ 'invalid/encoding/bad-utf8-in-string-literal', // We parse strings, not raw buffers ]; +const WINDOWS_NEWLINES = [ + 'valid/array/string-with-comma-2', + 'valid/comment/tricky', + 'valid/inline-table/multiline', + 'valid/spec/string-1', + 'valid/spec/string-6', + 'valid/string/ends-in-whitespace-escape', + 'valid/string/multiline', + 'valid/string/multiline-quotes', + 'valid/string/raw-multiline', +]; + const MISNAMED_FILES = new Map([ ['invalid/inline-table/overwrite-1.toml', 'invalid/inline-table/overwrite-01.toml'], ['invalid/inline-table/overwrite-2.toml', 'invalid/inline-table/overwrite-02.toml'], @@ -42,7 +54,11 @@ describe('Official TOML test suite', function () { let json; if (testName.startsWith('valid/')) { - json = JSON.parse(normalizeLines(fs.readFileSync(completePath.slice(0, -5) + '.json', 'utf8'))); + let jsonString = fs.readFileSync(completePath.slice(0, -5) + '.json', 'utf8'); + if (EOL === '\r\n' && WINDOWS_NEWLINES.includes(testName)) { + jsonString = jsonString.replace(/\\n/g, '\\r\\n'); + } + json = JSON.parse(jsonString); } else if (!testName.startsWith('invalid/')) { throw new TypeError('Unexpected test name'); } @@ -104,8 +120,3 @@ function format(table) { } return clone; } - -function normalizeLines(str) { - if (EOL === '\n') return str; - return str.replace(/\n/g, EOL); -}