Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: change forEach to for...of in path extname #50667

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions test/parallel/test-path-extname.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');
const failures = [];
const slashRE = /\//g;

[
const testPaths = [
[__filename, '.js'],
['', ''],
['/path/to/file', ''],
Expand Down Expand Up @@ -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, '\\');
Expand All @@ -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.
Expand Down