Browse Source

test: add path.join's test

Add test when the argument is empty.
Adjust the position of the comment.
Make use of Arrow Function, Template Literals and `Array.from`.

PR-URL: https://github.com/nodejs/node/pull/11063
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
v6.x
Yuta Hiroto 8 years ago
committed by Myles Borins
parent
commit
87488ba2ff
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 49
      test/parallel/test-path.js

49
test/parallel/test-path.js

@ -60,8 +60,8 @@ assert.strictEqual(path.posix.basename('foo'), 'foo');
// POSIX filenames may include control characters
// c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html
const controlCharFilename = 'Icon' + String.fromCharCode(13);
assert.strictEqual(path.posix.basename('/a/b/' + controlCharFilename),
const controlCharFilename = `Icon${String.fromCharCode(13)}`;
assert.strictEqual(path.posix.basename(`/a/b/${controlCharFilename}`),
controlCharFilename);
@ -162,8 +162,8 @@ assert.strictEqual(path.win32.dirname('foo'), '.');
['file//', ''],
['file./', '.'],
['file.//', '.'],
].forEach(function(test) {
[path.posix.extname, path.win32.extname].forEach(function(extname) {
].forEach((test) => {
[path.posix.extname, path.win32.extname].forEach((extname) => {
let input = test[0];
let os;
if (extname === path.win32.extname) {
@ -210,6 +210,7 @@ const joinTests = [
[ [path.posix.join, path.win32.join],
// arguments result
[[['.', 'x/b', '..', '/b/c.js'], 'x/b/c.js'],
[[], '.'],
[['/.', 'x/b', '..', '/b/c.js'], '/x/b/c.js'],
[['/foo', '../../../bar'], '/bar'],
[['foo', '../../../bar'], '../../bar'],
@ -312,11 +313,11 @@ joinTests.push([
]
)
]);
joinTests.forEach(function(test) {
joinTests.forEach((test) => {
if (!Array.isArray(test[0]))
test[0] = [test[0]];
test[0].forEach(function(join) {
test[1].forEach(function(test) {
test[0].forEach((join) => {
test[1].forEach((test) => {
const actual = join.apply(null, test[0]);
const expected = test[1];
// For non-Windows specific tests with the Windows join(), we need to try
@ -335,7 +336,7 @@ joinTests.forEach(function(test) {
'\n expect=' + JSON.stringify(expected) +
'\n actual=' + JSON.stringify(actual);
if (actual !== expected && actualAlt !== expected)
failures.push('\n' + message);
failures.push(`\n${message}`);
});
});
});
@ -346,15 +347,15 @@ assert.strictEqual(failures.length, 0, failures.join(''));
const typeErrorTests = [true, false, 7, null, {}, undefined, [], NaN];
function fail(fn) {
const args = Array.prototype.slice.call(arguments, 1);
const args = Array.from(arguments).slice(1);
assert.throws(function() {
assert.throws(() => {
fn.apply(null, args);
}, TypeError);
}
typeErrorTests.forEach(function(test) {
[path.posix, path.win32].forEach(function(namespace) {
typeErrorTests.forEach((test) => {
[path.posix, path.win32].forEach((namespace) => {
fail(namespace.join, test);
fail(namespace.resolve, test);
fail(namespace.normalize, test);
@ -398,7 +399,7 @@ assert.strictEqual(path.posix.normalize('///..//./foo/.//bar'), '/foo/bar');
// path.resolve tests
const resolveTests = [
[ path.win32.resolve,
// arguments result
// arguments result
[[['c:/blah\\blah', 'd:/games', 'c:../a'], 'c:\\blah\\a'],
[['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'],
[['c:/ignore', 'c:/some/file'], 'c:\\some\\file'],
@ -415,7 +416,7 @@ const resolveTests = [
]
],
[ path.posix.resolve,
// arguments result
// arguments result
[[['/var/lib', '../', 'file/'], '/var/file'],
[['/var/lib', '/../', 'file/'], '/file'],
[['a/b/c/', '../../..'], process.cwd()],
@ -425,9 +426,9 @@ const resolveTests = [
]
]
];
resolveTests.forEach(function(test) {
resolveTests.forEach((test) => {
const resolve = test[0];
test[1].forEach(function(test) {
test[1].forEach((test) => {
const actual = resolve.apply(null, test[0]);
let actualAlt;
const os = resolve === path.win32.resolve ? 'win32' : 'posix';
@ -516,7 +517,7 @@ const relativeTests = [
]
],
[ path.posix.relative,
// arguments result
// arguments result
[['/var/lib', '/var', '..'],
['/var/lib', '/bin', '../../bin'],
['/var/lib', '/var/lib', ''],
@ -532,9 +533,9 @@ const relativeTests = [
]
]
];
relativeTests.forEach(function(test) {
relativeTests.forEach((test) => {
const relative = test[0];
test[1].forEach(function(test) {
test[1].forEach((test) => {
const actual = relative(test[0], test[1]);
const expected = test[2];
const os = relative === path.win32.relative ? 'win32' : 'posix';
@ -545,7 +546,7 @@ relativeTests.forEach(function(test) {
'\n expect=' + JSON.stringify(expected) +
'\n actual=' + JSON.stringify(actual);
if (actual !== expected)
failures.push('\n' + message);
failures.push(`\n${message}`);
});
});
assert.strictEqual(failures.length, 0, failures.join(''));
@ -577,14 +578,14 @@ if (common.isWindows) {
// These tests cause resolve() to insert the cwd, so we cannot test them from
// non-Windows platforms (easily)
assert.strictEqual(path.win32._makeLong('foo\\bar').toLowerCase(),
'\\\\?\\' + process.cwd().toLowerCase() + '\\foo\\bar');
`\\\\?\\${process.cwd().toLowerCase()}\\foo\\bar`);
assert.strictEqual(path.win32._makeLong('foo/bar').toLowerCase(),
'\\\\?\\' + process.cwd().toLowerCase() + '\\foo\\bar');
`\\\\?\\${process.cwd().toLowerCase()}\\foo\\bar`);
const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 2);
assert.strictEqual(path.win32._makeLong(currentDeviceLetter).toLowerCase(),
'\\\\?\\' + process.cwd().toLowerCase());
`\\\\?\\${process.cwd().toLowerCase()}`);
assert.strictEqual(path.win32._makeLong('C').toLowerCase(),
'\\\\?\\' + process.cwd().toLowerCase() + '\\c');
`\\\\?\\${process.cwd().toLowerCase()}\\c`);
}
assert.strictEqual(path.win32._makeLong('C:\\foo'), '\\\\?\\C:\\foo');
assert.strictEqual(path.win32._makeLong('C:/foo'), '\\\\?\\C:\\foo');

Loading…
Cancel
Save