|
|
@ -4,28 +4,33 @@ const assert = require('assert'); |
|
|
|
const path = require('path'); |
|
|
|
|
|
|
|
const winPaths = [ |
|
|
|
'C:\\path\\dir\\index.html', |
|
|
|
'C:\\another_path\\DIR\\1\\2\\33\\\\index', |
|
|
|
'another_path\\DIR with spaces\\1\\2\\33\\index', |
|
|
|
'\\foo\\C:', |
|
|
|
'file', |
|
|
|
'.\\file', |
|
|
|
'C:\\', |
|
|
|
'C:', |
|
|
|
'\\', |
|
|
|
'', |
|
|
|
// [path, root]
|
|
|
|
['C:\\path\\dir\\index.html', 'C:\\'], |
|
|
|
['C:\\another_path\\DIR\\1\\2\\33\\\\index', 'C:\\'], |
|
|
|
['another_path\\DIR with spaces\\1\\2\\33\\index', ''], |
|
|
|
['\\', '\\'], |
|
|
|
['\\foo\\C:', '\\'], |
|
|
|
['file', ''], |
|
|
|
['file:stream', ''], |
|
|
|
['.\\file', ''], |
|
|
|
['C:', 'C:'], |
|
|
|
['C:.', 'C:'], |
|
|
|
['C:..', 'C:'], |
|
|
|
['C:abc', 'C:'], |
|
|
|
['C:\\', 'C:\\'], |
|
|
|
['C:\\abc', 'C:\\' ], |
|
|
|
['', ''], |
|
|
|
|
|
|
|
// unc
|
|
|
|
'\\\\server\\share\\file_path', |
|
|
|
'\\\\server two\\shared folder\\file path.zip', |
|
|
|
'\\\\teela\\admin$\\system32', |
|
|
|
'\\\\?\\UNC\\server\\share' |
|
|
|
['\\\\server\\share\\file_path', '\\\\server\\share\\'], |
|
|
|
['\\\\server two\\shared folder\\file path.zip', |
|
|
|
'\\\\server two\\shared folder\\'], |
|
|
|
['\\\\teela\\admin$\\system32', '\\\\teela\\admin$\\'], |
|
|
|
['\\\\?\\UNC\\server\\share', '\\\\?\\UNC\\'] |
|
|
|
]; |
|
|
|
|
|
|
|
const winSpecialCaseParseTests = [ |
|
|
|
['/foo/bar', { root: '/' }], |
|
|
|
['C:', { root: 'C:', dir: 'C:', base: '' }], |
|
|
|
['C:\\', { root: 'C:\\', dir: 'C:\\', base: '' }] |
|
|
|
]; |
|
|
|
|
|
|
|
const winSpecialCaseFormatTests = [ |
|
|
@ -39,26 +44,27 @@ const winSpecialCaseFormatTests = [ |
|
|
|
]; |
|
|
|
|
|
|
|
const unixPaths = [ |
|
|
|
'/home/user/dir/file.txt', |
|
|
|
'/home/user/a dir/another File.zip', |
|
|
|
'/home/user/a dir//another&File.', |
|
|
|
'/home/user/a$$$dir//another File.zip', |
|
|
|
'user/dir/another File.zip', |
|
|
|
'file', |
|
|
|
'.\\file', |
|
|
|
'./file', |
|
|
|
'C:\\foo', |
|
|
|
'/', |
|
|
|
'', |
|
|
|
'.', |
|
|
|
'..', |
|
|
|
'/foo', |
|
|
|
'/foo.', |
|
|
|
'/foo.bar', |
|
|
|
'/.', |
|
|
|
'/.foo', |
|
|
|
'/.foo.bar', |
|
|
|
'/foo/bar.baz', |
|
|
|
// [path, root]
|
|
|
|
['/home/user/dir/file.txt', '/'], |
|
|
|
['/home/user/a dir/another File.zip', '/'], |
|
|
|
['/home/user/a dir//another&File.', '/'], |
|
|
|
['/home/user/a$$$dir//another File.zip', '/'], |
|
|
|
['user/dir/another File.zip', ''], |
|
|
|
['file', ''], |
|
|
|
['.\\file', ''], |
|
|
|
['./file', ''], |
|
|
|
['C:\\foo', ''], |
|
|
|
['/', '/'], |
|
|
|
['', ''], |
|
|
|
['.', ''], |
|
|
|
['..', ''], |
|
|
|
['/foo', '/'], |
|
|
|
['/foo.', '/'], |
|
|
|
['/foo.bar', '/'], |
|
|
|
['/.', '/'], |
|
|
|
['/.foo', '/'], |
|
|
|
['/.foo.bar', '/'], |
|
|
|
['/foo/bar.baz', '/'] |
|
|
|
]; |
|
|
|
|
|
|
|
const unixSpecialCaseFormatTests = [ |
|
|
@ -169,7 +175,7 @@ function checkErrors(path) { |
|
|
|
} |
|
|
|
|
|
|
|
function checkParseFormat(path, paths) { |
|
|
|
paths.forEach(function(element) { |
|
|
|
paths.forEach(function([element, root]) { |
|
|
|
const output = path.parse(element); |
|
|
|
assert.strictEqual(typeof output.root, 'string'); |
|
|
|
assert.strictEqual(typeof output.dir, 'string'); |
|
|
@ -177,6 +183,8 @@ function checkParseFormat(path, paths) { |
|
|
|
assert.strictEqual(typeof output.ext, 'string'); |
|
|
|
assert.strictEqual(typeof output.name, 'string'); |
|
|
|
assert.strictEqual(path.format(output), element); |
|
|
|
assert.strictEqual(output.root, root); |
|
|
|
assert(output.dir.startsWith(output.root)); |
|
|
|
assert.strictEqual(output.dir, output.dir ? path.dirname(element) : ''); |
|
|
|
assert.strictEqual(output.base, path.basename(element)); |
|
|
|
assert.strictEqual(output.ext, path.extname(element)); |
|
|
|