Skip to content

Commit

Permalink
test: replace forEach with for-of in test-url-relative
Browse files Browse the repository at this point in the history
PR-URL: #50788
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
vitosorriso authored and UlisesGascon committed Dec 15, 2023
1 parent 3c7dde3 commit 0ed5f2a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions test/parallel/test-url-relative.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ const relativeTests = [
['http://localhost', 'file://foo/Users', 'file://foo/Users'],
['https://registry.npmjs.org', '@foo/bar', 'https://registry.npmjs.org/@foo/bar'],
];
relativeTests.forEach(function(relativeTest) {
for (let i = 0; i < relativeTests.length; i++) {
const relativeTest = relativeTests[i];

const a = url.resolve(relativeTest[0], relativeTest[1]);
const e = relativeTest[2];
assert.strictEqual(a, e,
`resolve(${relativeTest[0]}, ${relativeTest[1]})` +
` == ${e}\n actual=${a}`);
});
}

//
// Tests below taken from Chiron
Expand Down Expand Up @@ -374,19 +376,23 @@ const relativeTests2 = [
// No path at all
['#hash1', '#hash2', '#hash1'],
];
relativeTests2.forEach(function(relativeTest) {
for (let i = 0; i < relativeTests2.length; i++) {
const relativeTest = relativeTests2[i];

const a = url.resolve(relativeTest[1], relativeTest[0]);
const e = url.format(relativeTest[2]);
assert.strictEqual(a, e,
`resolve(${relativeTest[0]}, ${relativeTest[1]})` +
` == ${e}\n actual=${a}`);
});
}

// If format and parse are inverse operations then
// resolveObject(parse(x), y) == parse(resolve(x, y))

// format: [from, path, expected]
relativeTests.forEach(function(relativeTest) {
for (let i = 0; i < relativeTests.length; i++) {
const relativeTest = relativeTests[i];

let actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]);
let expected = url.parse(relativeTest[2]);

Expand All @@ -399,7 +405,8 @@ relativeTests.forEach(function(relativeTest) {
assert.strictEqual(actual, expected,
`format(${actual}) == ${expected}\n` +
`actual: ${actual}`);
});

}

// format: [to, from, result]
// the test: ['.//g', 'f:/a', 'f://g'] is a fundamental problem
Expand All @@ -415,7 +422,9 @@ if (relativeTests2[181][0] === './/g' &&
relativeTests2[181][2] === 'f://g') {
relativeTests2.splice(181, 1);
}
relativeTests2.forEach(function(relativeTest) {
for (let i = 0; i < relativeTests2.length; i++) {
const relativeTest = relativeTests2[i];

let actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]);
let expected = url.parse(relativeTest[2]);

Expand All @@ -431,4 +440,4 @@ relativeTests2.forEach(function(relativeTest) {
assert.strictEqual(actual, expected,
`format(${relativeTest[1]}) == ${expected}\n` +
`actual: ${actual}`);
});
}

0 comments on commit 0ed5f2a

Please sign in to comment.