diff options
author | Brian White <mscdex@mscdex.net> | 2016-02-05 22:28:01 -0500 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-02-09 20:35:41 -0800 |
commit | 5a54e4554ae0ff9788812c88ae05dfdd6088ffe1 (patch) | |
tree | db9a247539646a5da57341f93039bbd0002b1e36 /test/parallel/test-path-parse-format.js | |
parent | e1348b0819d4d2aeb9a93c98dd31b9cacd951214 (diff) | |
download | android-node-v8-5a54e4554ae0ff9788812c88ae05dfdd6088ffe1.tar.gz android-node-v8-5a54e4554ae0ff9788812c88ae05dfdd6088ffe1.tar.bz2 android-node-v8-5a54e4554ae0ff9788812c88ae05dfdd6088ffe1.zip |
test: improve path tests
This commit adds new tests, executes tests for other platforms
instead of limiting platform-specific tests to those platforms,
and fixes a few style/formatting inconsistencies.
PR-URL: https://github.com/nodejs/node/pull/5123
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-path-parse-format.js')
-rw-r--r-- | test/parallel/test-path-parse-format.js | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index a28444cd3b..21bebfedee 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -41,7 +41,16 @@ const unixPaths = [ './file', 'C:\\foo', '/', - '' + '', + '.', + '..', + '/foo', + '/foo.', + '/foo.bar', + '/.', + '/.foo', + '/.foo.bar', + '/foo/bar.baz', ]; const unixSpecialCaseFormatTests = [ @@ -82,6 +91,67 @@ checkErrors(path.posix); checkFormat(path.win32, winSpecialCaseFormatTests); checkFormat(path.posix, unixSpecialCaseFormatTests); +// Test removal of trailing path separators +const trailingTests = [ + [ path.win32.parse, + [['.\\', { root: '', dir: '', base: '.', ext: '', name: '.' }], + ['\\\\', { root: '\\', dir: '\\', base: '', ext: '', name: '' }], + ['\\\\', { root: '\\', dir: '\\', base: '', ext: '', name: '' }], + ['c:\\foo\\\\\\', + { root: 'c:\\', dir: 'c:\\', base: 'foo', ext: '', name: 'foo' }], + ['D:\\foo\\\\\\bar.baz', + { root: 'D:\\', + dir: 'D:\\foo\\\\', + base: 'bar.baz', + ext: '.baz', + name: 'bar' + } + ] + ] + ], + [ path.posix.parse, + [['./', { root: '', dir: '', base: '.', ext: '', name: '.' }], + ['//', { root: '/', dir: '/', base: '', ext: '', name: '' }], + ['///', { root: '/', dir: '/', base: '', ext: '', name: '' }], + ['/foo///', { root: '/', dir: '/', base: 'foo', ext: '', name: 'foo' }], + ['/foo///bar.baz', + { root: '/', dir: '/foo//', base: 'bar.baz', ext: '.baz', name: 'bar' } + ] + ] + ] +]; +const failures = []; +trailingTests.forEach(function(test) { + const parse = test[0]; + test[1].forEach(function(test) { + const actual = parse(test[0]); + const expected = test[1]; + const fn = 'path.' + + (parse === path.win32.parse ? 'win32' : 'posix') + + '.parse('; + const message = fn + + JSON.stringify(test[0]) + + ')' + + '\n expect=' + JSON.stringify(expected) + + '\n actual=' + JSON.stringify(actual); + const actualKeys = Object.keys(actual); + const expectedKeys = Object.keys(expected); + let failed = (actualKeys.length !== expectedKeys.length); + if (!failed) { + for (let i = 0; i < actualKeys.length; ++i) { + const key = actualKeys[i]; + if (expectedKeys.indexOf(key) === -1 || actual[key] !== expected[key]) { + failed = true; + break; + } + } + } + if (failed) + failures.push('\n' + message); + }); +}); +assert.equal(failures.length, 0, failures.join('')); + function checkErrors(path) { errors.forEach(function(errorCase) { try { |