mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
test: change forEach to for...of in path extname
PR-URL: https://github.com/nodejs/node/pull/50667 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
1 parent
8ce6403230
commit
bb7d764c8e
1 file changed
+15
-14
@@ -6,7 +6,7 @@ const path = require('path');
|
||||
const failures = [];
|
||||
const slashRE = /\//g;
|
||||
|
||||
[
|
||||
const testPaths = [
|
||||
[__filename, '.js'],
|
||||
['', ''],
|
||||
['/path/to/file', ''],
|
||||
@@ -50,10 +50,13 @@ const slashRE = /\//g;
|
||||
['file//', ''],
|
||||
['file./', '.'],
|
||||
['file.//', '.'],
|
||||
].forEach((test) => {
|
||||
const expected = test[1];
|
||||
[path.posix.extname, path.win32.extname].forEach((extname) => {
|
||||
let input = test[0];
|
||||
];
|
||||
|
||||
for (const testPath of testPaths) {
|
||||
const expected = testPath[1];
|
||||
const extNames = [path.posix.extname, path.win32.extname];
|
||||
for (const extname of extNames) {
|
||||
let input = testPath[0];
|
||||
let os;
|
||||
if (extname === path.win32.extname) {
|
||||
input = input.replace(slashRE, '\\');
|
||||
@@ -66,16 +69,14 @@ const slashRE = /\//g;
|
||||
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
|
||||
if (actual !== expected)
|
||||
failures.push(`\n${message}`);
|
||||
});
|
||||
{
|
||||
const input = `C:${test[0].replace(slashRE, '\\')}`;
|
||||
const actual = path.win32.extname(input);
|
||||
const message = `path.win32.extname(${JSON.stringify(input)})\n expect=${
|
||||
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
|
||||
if (actual !== expected)
|
||||
failures.push(`\n${message}`);
|
||||
}
|
||||
});
|
||||
const input = `C:${testPath[0].replace(slashRE, '\\')}`;
|
||||
const actual = path.win32.extname(input);
|
||||
const message = `path.win32.extname(${JSON.stringify(input)})\n expect=${
|
||||
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
|
||||
if (actual !== expected)
|
||||
failures.push(`\n${message}`);
|
||||
}
|
||||
assert.strictEqual(failures.length, 0, failures.join(''));
|
||||
|
||||
// On Windows, backslash is a path separator.
|
||||
|
||||
Reference in new issue
Block a user