Skip to content

Commit 87488ba

Browse files
hiroppyMylesBorins
authored andcommitted
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: #11063 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 232664a commit 87488ba

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

‎test/parallel/test-path.js‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ assert.strictEqual(path.posix.basename('foo'), 'foo');
6060

6161
// POSIX filenames may include control characters
6262
// c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html
63-
constcontrolCharFilename='Icon'+String.fromCharCode(13);
64-
assert.strictEqual(path.posix.basename('/a/b/'+controlCharFilename),
63+
constcontrolCharFilename=`Icon${String.fromCharCode(13)}`;
64+
assert.strictEqual(path.posix.basename(`/a/b/${controlCharFilename}`),
6565
controlCharFilename);
6666

6767

@@ -162,8 +162,8 @@ assert.strictEqual(path.win32.dirname('foo'), '.');
162162
['file//',''],
163163
['file./','.'],
164164
['file.//','.'],
165-
].forEach(function(test){
166-
[path.posix.extname,path.win32.extname].forEach(function(extname){
165+
].forEach((test)=>{
166+
[path.posix.extname,path.win32.extname].forEach((extname)=>{
167167
letinput=test[0];
168168
letos;
169169
if(extname===path.win32.extname){
@@ -210,6 +210,7 @@ const joinTests = [
210210
[[path.posix.join,path.win32.join],
211211
// arguments result
212212
[[['.','x/b','..','/b/c.js'],'x/b/c.js'],
213+
[[],'.'],
213214
[['/.','x/b','..','/b/c.js'],'/x/b/c.js'],
214215
[['/foo','../../../bar'],'/bar'],
215216
[['foo','../../../bar'],'../../bar'],
@@ -312,11 +313,11 @@ joinTests.push([
312313
]
313314
)
314315
]);
315-
joinTests.forEach(function(test){
316+
joinTests.forEach((test)=>{
316317
if(!Array.isArray(test[0]))
317318
test[0]=[test[0]];
318-
test[0].forEach(function(join){
319-
test[1].forEach(function(test){
319+
test[0].forEach((join)=>{
320+
test[1].forEach((test)=>{
320321
constactual=join.apply(null,test[0]);
321322
constexpected=test[1];
322323
// For non-Windows specific tests with the Windows join(), we need to try
@@ -335,7 +336,7 @@ joinTests.forEach(function(test) {
335336
'\n expect='+JSON.stringify(expected)+
336337
'\n actual='+JSON.stringify(actual);
337338
if(actual!==expected&&actualAlt!==expected)
338-
failures.push('\n'+message);
339+
failures.push(`\n${message}`);
339340
});
340341
});
341342
});
@@ -346,15 +347,15 @@ assert.strictEqual(failures.length, 0, failures.join(''));
346347
consttypeErrorTests=[true,false,7,null,{},undefined,[],NaN];
347348

348349
functionfail(fn){
349-
constargs=Array.prototype.slice.call(arguments,1);
350+
constargs=Array.from(arguments).slice(1);
350351

351-
assert.throws(function(){
352+
assert.throws(()=>{
352353
fn.apply(null,args);
353354
},TypeError);
354355
}
355356

356-
typeErrorTests.forEach(function(test){
357-
[path.posix,path.win32].forEach(function(namespace){
357+
typeErrorTests.forEach((test)=>{
358+
[path.posix,path.win32].forEach((namespace)=>{
358359
fail(namespace.join,test);
359360
fail(namespace.resolve,test);
360361
fail(namespace.normalize,test);
@@ -398,7 +399,7 @@ assert.strictEqual(path.posix.normalize('///..//./foo/.//bar'), '/foo/bar');
398399
// path.resolve tests
399400
constresolveTests=[
400401
[path.win32.resolve,
401-
// arguments result
402+
// arguments result
402403
[[['c:/blah\\blah','d:/games','c:../a'],'c:\\blah\\a'],
403404
[['c:/ignore','d:\\a/b\\c/d','\\e.exe'],'d:\\e.exe'],
404405
[['c:/ignore','c:/some/file'],'c:\\some\\file'],
@@ -415,7 +416,7 @@ const resolveTests = [
415416
]
416417
],
417418
[path.posix.resolve,
418-
// arguments result
419+
// arguments result
419420
[[['/var/lib','../','file/'],'/var/file'],
420421
[['/var/lib','/../','file/'],'/file'],
421422
[['a/b/c/','../../..'],process.cwd()],
@@ -425,9 +426,9 @@ const resolveTests = [
425426
]
426427
]
427428
];
428-
resolveTests.forEach(function(test){
429+
resolveTests.forEach((test)=>{
429430
constresolve=test[0];
430-
test[1].forEach(function(test){
431+
test[1].forEach((test)=>{
431432
constactual=resolve.apply(null,test[0]);
432433
letactualAlt;
433434
constos=resolve===path.win32.resolve ? 'win32' : 'posix';
@@ -516,7 +517,7 @@ const relativeTests = [
516517
]
517518
],
518519
[path.posix.relative,
519-
// arguments result
520+
// arguments result
520521
[['/var/lib','/var','..'],
521522
['/var/lib','/bin','../../bin'],
522523
['/var/lib','/var/lib',''],
@@ -532,9 +533,9 @@ const relativeTests = [
532533
]
533534
]
534535
];
535-
relativeTests.forEach(function(test){
536+
relativeTests.forEach((test)=>{
536537
constrelative=test[0];
537-
test[1].forEach(function(test){
538+
test[1].forEach((test)=>{
538539
constactual=relative(test[0],test[1]);
539540
constexpected=test[2];
540541
constos=relative===path.win32.relative ? 'win32' : 'posix';
@@ -545,7 +546,7 @@ relativeTests.forEach(function(test) {
545546
'\n expect='+JSON.stringify(expected)+
546547
'\n actual='+JSON.stringify(actual);
547548
if(actual!==expected)
548-
failures.push('\n'+message);
549+
failures.push(`\n${message}`);
549550
});
550551
});
551552
assert.strictEqual(failures.length,0,failures.join(''));
@@ -577,14 +578,14 @@ if (common.isWindows) {
577578
// These tests cause resolve() to insert the cwd, so we cannot test them from
578579
// non-Windows platforms (easily)
579580
assert.strictEqual(path.win32._makeLong('foo\\bar').toLowerCase(),
580-
'\\\\?\\'+process.cwd().toLowerCase()+'\\foo\\bar');
581+
`\\\\?\\${process.cwd().toLowerCase()}\\foo\\bar`);
581582
assert.strictEqual(path.win32._makeLong('foo/bar').toLowerCase(),
582-
'\\\\?\\'+process.cwd().toLowerCase()+'\\foo\\bar');
583+
`\\\\?\\${process.cwd().toLowerCase()}\\foo\\bar`);
583584
constcurrentDeviceLetter=path.parse(process.cwd()).root.substring(0,2);
584585
assert.strictEqual(path.win32._makeLong(currentDeviceLetter).toLowerCase(),
585-
'\\\\?\\'+process.cwd().toLowerCase());
586+
`\\\\?\\${process.cwd().toLowerCase()}`);
586587
assert.strictEqual(path.win32._makeLong('C').toLowerCase(),
587-
'\\\\?\\'+process.cwd().toLowerCase()+'\\c');
588+
`\\\\?\\${process.cwd().toLowerCase()}\\c`);
588589
}
589590
assert.strictEqual(path.win32._makeLong('C:\\foo'),'\\\\?\\C:\\foo');
590591
assert.strictEqual(path.win32._makeLong('C:/foo'),'\\\\?\\C:\\foo');

0 commit comments

Comments
 (0)