Skip to content

Commit

Permalink
fixed windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaWise committed Feb 1, 2024
1 parent c716527 commit d1119a0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions test/toml-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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');
}
Expand Down Expand Up @@ -104,8 +120,3 @@ function format(table) {
}
return clone;
}

function normalizeLines(str) {
if (EOL === '\n') return str;
return str.replace(/\n/g, EOL);
}

0 comments on commit d1119a0

Please sign in to comment.