-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: split path tests into multiple files #15093
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
assert.strictEqual(path.basename(__filename), 'test-path-basename.js'); | ||
assert.strictEqual(path.basename(__filename, '.js'), 'test-path-basename'); | ||
assert.strictEqual(path.basename('.js', '.js'), ''); | ||
assert.strictEqual(path.basename(''), ''); | ||
assert.strictEqual(path.basename('/dir/basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.basename('/basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.basename('basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.basename('basename.ext/'), 'basename.ext'); | ||
assert.strictEqual(path.basename('basename.ext//'), 'basename.ext'); | ||
assert.strictEqual(path.basename('aaa/bbb', '/bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('aaa/bbb', 'a/bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('aaa/bbb', 'bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('aaa/bbb//', 'bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('aaa/bbb', 'bb'), 'b'); | ||
assert.strictEqual(path.basename('aaa/bbb', 'b'), 'bb'); | ||
assert.strictEqual(path.basename('/aaa/bbb', '/bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('/aaa/bbb', 'a/bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('/aaa/bbb', 'bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('/aaa/bbb//', 'bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('/aaa/bbb', 'bb'), 'b'); | ||
assert.strictEqual(path.basename('/aaa/bbb', 'b'), 'bb'); | ||
assert.strictEqual(path.basename('/aaa/bbb'), 'bbb'); | ||
assert.strictEqual(path.basename('/aaa/'), 'aaa'); | ||
assert.strictEqual(path.basename('/aaa/b'), 'b'); | ||
assert.strictEqual(path.basename('/a/b'), 'b'); | ||
assert.strictEqual(path.basename('//a'), 'a'); | ||
|
||
// On Windows a backslash acts as a path separator. | ||
assert.strictEqual(path.win32.basename('\\dir\\basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('\\basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('basename.ext\\'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('basename.ext\\\\'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('foo'), 'foo'); | ||
assert.strictEqual(path.win32.basename('aaa\\bbb', '\\bbb'), 'bbb'); | ||
assert.strictEqual(path.win32.basename('aaa\\bbb', 'a\\bbb'), 'bbb'); | ||
assert.strictEqual(path.win32.basename('aaa\\bbb', 'bbb'), 'bbb'); | ||
assert.strictEqual(path.win32.basename('aaa\\bbb\\\\\\\\', 'bbb'), 'bbb'); | ||
assert.strictEqual(path.win32.basename('aaa\\bbb', 'bb'), 'b'); | ||
assert.strictEqual(path.win32.basename('aaa\\bbb', 'b'), 'bb'); | ||
assert.strictEqual(path.win32.basename('C:'), ''); | ||
assert.strictEqual(path.win32.basename('C:.'), '.'); | ||
assert.strictEqual(path.win32.basename('C:\\'), ''); | ||
assert.strictEqual(path.win32.basename('C:\\dir\\base.ext'), 'base.ext'); | ||
assert.strictEqual(path.win32.basename('C:\\basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('C:basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('C:basename.ext\\'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('C:basename.ext\\\\'), 'basename.ext'); | ||
assert.strictEqual(path.win32.basename('C:foo'), 'foo'); | ||
assert.strictEqual(path.win32.basename('file:stream'), 'file:stream'); | ||
|
||
// On unix a backslash is just treated as any other character. | ||
assert.strictEqual(path.posix.basename('\\dir\\basename.ext'), | ||
'\\dir\\basename.ext'); | ||
assert.strictEqual(path.posix.basename('\\basename.ext'), '\\basename.ext'); | ||
assert.strictEqual(path.posix.basename('basename.ext'), 'basename.ext'); | ||
assert.strictEqual(path.posix.basename('basename.ext\\'), 'basename.ext\\'); | ||
assert.strictEqual(path.posix.basename('basename.ext\\\\'), 'basename.ext\\\\'); | ||
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}`), | ||
controlCharFilename); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
assert.strictEqual(path.dirname(__filename).substr(-13), | ||
common.isWindows ? 'test\\parallel' : 'test/parallel'); | ||
|
||
assert.strictEqual(path.posix.dirname('/a/b/'), '/a'); | ||
assert.strictEqual(path.posix.dirname('/a/b'), '/a'); | ||
assert.strictEqual(path.posix.dirname('/a'), '/'); | ||
assert.strictEqual(path.posix.dirname(''), '.'); | ||
assert.strictEqual(path.posix.dirname('/'), '/'); | ||
assert.strictEqual(path.posix.dirname('////'), '/'); | ||
assert.strictEqual(path.posix.dirname('//a'), '//'); | ||
assert.strictEqual(path.posix.dirname('foo'), '.'); | ||
|
||
assert.strictEqual(path.win32.dirname('c:\\'), 'c:\\'); | ||
assert.strictEqual(path.win32.dirname('c:\\foo'), 'c:\\'); | ||
assert.strictEqual(path.win32.dirname('c:\\foo\\'), 'c:\\'); | ||
assert.strictEqual(path.win32.dirname('c:\\foo\\bar'), 'c:\\foo'); | ||
assert.strictEqual(path.win32.dirname('c:\\foo\\bar\\'), 'c:\\foo'); | ||
assert.strictEqual(path.win32.dirname('c:\\foo\\bar\\baz'), 'c:\\foo\\bar'); | ||
assert.strictEqual(path.win32.dirname('\\'), '\\'); | ||
assert.strictEqual(path.win32.dirname('\\foo'), '\\'); | ||
assert.strictEqual(path.win32.dirname('\\foo\\'), '\\'); | ||
assert.strictEqual(path.win32.dirname('\\foo\\bar'), '\\foo'); | ||
assert.strictEqual(path.win32.dirname('\\foo\\bar\\'), '\\foo'); | ||
assert.strictEqual(path.win32.dirname('\\foo\\bar\\baz'), '\\foo\\bar'); | ||
assert.strictEqual(path.win32.dirname('c:'), 'c:'); | ||
assert.strictEqual(path.win32.dirname('c:foo'), 'c:'); | ||
assert.strictEqual(path.win32.dirname('c:foo\\'), 'c:'); | ||
assert.strictEqual(path.win32.dirname('c:foo\\bar'), 'c:foo'); | ||
assert.strictEqual(path.win32.dirname('c:foo\\bar\\'), 'c:foo'); | ||
assert.strictEqual(path.win32.dirname('c:foo\\bar\\baz'), 'c:foo\\bar'); | ||
assert.strictEqual(path.win32.dirname('file:stream'), '.'); | ||
assert.strictEqual(path.win32.dirname('dir\\file:stream'), 'dir'); | ||
assert.strictEqual(path.win32.dirname('\\\\unc\\share'), | ||
'\\\\unc\\share'); | ||
assert.strictEqual(path.win32.dirname('\\\\unc\\share\\foo'), | ||
'\\\\unc\\share\\'); | ||
assert.strictEqual(path.win32.dirname('\\\\unc\\share\\foo\\'), | ||
'\\\\unc\\share\\'); | ||
assert.strictEqual(path.win32.dirname('\\\\unc\\share\\foo\\bar'), | ||
'\\\\unc\\share\\foo'); | ||
assert.strictEqual(path.win32.dirname('\\\\unc\\share\\foo\\bar\\'), | ||
'\\\\unc\\share\\foo'); | ||
assert.strictEqual(path.win32.dirname('\\\\unc\\share\\foo\\bar\\baz'), | ||
'\\\\unc\\share\\foo\\bar'); | ||
assert.strictEqual(path.win32.dirname('/a/b/'), '/a'); | ||
assert.strictEqual(path.win32.dirname('/a/b'), '/a'); | ||
assert.strictEqual(path.win32.dirname('/a'), '/'); | ||
assert.strictEqual(path.win32.dirname(''), '.'); | ||
assert.strictEqual(path.win32.dirname('/'), '/'); | ||
assert.strictEqual(path.win32.dirname('////'), '/'); | ||
assert.strictEqual(path.win32.dirname('foo'), '.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
const failures = []; | ||
const slashRE = /\//g; | ||
|
||
[ | ||
[__filename, '.js'], | ||
['', ''], | ||
['/path/to/file', ''], | ||
['/path/to/file.ext', '.ext'], | ||
['/path.to/file.ext', '.ext'], | ||
['/path.to/file', ''], | ||
['/path.to/.file', ''], | ||
['/path.to/.file.ext', '.ext'], | ||
['/path/to/f.ext', '.ext'], | ||
['/path/to/..ext', '.ext'], | ||
['/path/to/..', ''], | ||
['file', ''], | ||
['file.ext', '.ext'], | ||
['.file', ''], | ||
['.file.ext', '.ext'], | ||
['/file', ''], | ||
['/file.ext', '.ext'], | ||
['/.file', ''], | ||
['/.file.ext', '.ext'], | ||
['.path/file.ext', '.ext'], | ||
['file.ext.ext', '.ext'], | ||
['file.', '.'], | ||
['.', ''], | ||
['./', ''], | ||
['.file.ext', '.ext'], | ||
['.file', ''], | ||
['.file.', '.'], | ||
['.file..', '.'], | ||
['..', ''], | ||
['../', ''], | ||
['..file.ext', '.ext'], | ||
['..file', '.file'], | ||
['..file.', '.'], | ||
['..file..', '.'], | ||
['...', '.'], | ||
['...ext', '.ext'], | ||
['....', '.'], | ||
['file.ext/', '.ext'], | ||
['file.ext//', '.ext'], | ||
['file/', ''], | ||
['file//', ''], | ||
['file./', '.'], | ||
['file.//', '.'], | ||
].forEach((test) => { | ||
const expected = test[1]; | ||
[path.posix.extname, path.win32.extname].forEach((extname) => { | ||
let input = test[0]; | ||
let os; | ||
if (extname === path.win32.extname) { | ||
input = input.replace(slashRE, '\\'); | ||
os = 'win32'; | ||
} else { | ||
os = 'posix'; | ||
} | ||
const actual = extname(input); | ||
const message = `path.${os}.extname(${JSON.stringify(input)})\n expect=${ | ||
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`; | ||
if (actual !== expected) | ||
failures.push(`\n${message}`); | ||
}); | ||
{ | ||
const input = `C:${test[0].replace(slashRE, '\\')}`; | ||
const actual = path.win32.extname(input); | ||
const message = `path.win32.extname(${JSON.stringify(input)})\n expect=${ | ||
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`; | ||
if (actual !== expected) | ||
failures.push(`\n${message}`); | ||
} | ||
}); | ||
assert.strictEqual(failures.length, 0, failures.join('')); | ||
|
||
// On Windows, backslash is a path separator. | ||
assert.strictEqual(path.win32.extname('.\\'), ''); | ||
assert.strictEqual(path.win32.extname('..\\'), ''); | ||
assert.strictEqual(path.win32.extname('file.ext\\'), '.ext'); | ||
assert.strictEqual(path.win32.extname('file.ext\\\\'), '.ext'); | ||
assert.strictEqual(path.win32.extname('file\\'), ''); | ||
assert.strictEqual(path.win32.extname('file\\\\'), ''); | ||
assert.strictEqual(path.win32.extname('file.\\'), '.'); | ||
assert.strictEqual(path.win32.extname('file.\\\\'), '.'); | ||
|
||
// On *nix, backslash is a valid name component like any other character. | ||
assert.strictEqual(path.posix.extname('.\\'), ''); | ||
assert.strictEqual(path.posix.extname('..\\'), '.\\'); | ||
assert.strictEqual(path.posix.extname('file.ext\\'), '.ext\\'); | ||
assert.strictEqual(path.posix.extname('file.ext\\\\'), '.ext\\\\'); | ||
assert.strictEqual(path.posix.extname('file\\'), ''); | ||
assert.strictEqual(path.posix.extname('file\\\\'), ''); | ||
assert.strictEqual(path.posix.extname('file.\\'), '.\\'); | ||
assert.strictEqual(path.posix.extname('file.\\\\'), '.\\\\'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
assert.strictEqual(path.win32.isAbsolute('/'), true); | ||
assert.strictEqual(path.win32.isAbsolute('//'), true); | ||
assert.strictEqual(path.win32.isAbsolute('//server'), true); | ||
assert.strictEqual(path.win32.isAbsolute('//server/file'), true); | ||
assert.strictEqual(path.win32.isAbsolute('\\\\server\\file'), true); | ||
assert.strictEqual(path.win32.isAbsolute('\\\\server'), true); | ||
assert.strictEqual(path.win32.isAbsolute('\\\\'), true); | ||
assert.strictEqual(path.win32.isAbsolute('c'), false); | ||
assert.strictEqual(path.win32.isAbsolute('c:'), false); | ||
assert.strictEqual(path.win32.isAbsolute('c:\\'), true); | ||
assert.strictEqual(path.win32.isAbsolute('c:/'), true); | ||
assert.strictEqual(path.win32.isAbsolute('c://'), true); | ||
assert.strictEqual(path.win32.isAbsolute('C:/Users/'), true); | ||
assert.strictEqual(path.win32.isAbsolute('C:\\Users\\'), true); | ||
assert.strictEqual(path.win32.isAbsolute('C:cwd/another'), false); | ||
assert.strictEqual(path.win32.isAbsolute('C:cwd\\another'), false); | ||
assert.strictEqual(path.win32.isAbsolute('directory/directory'), false); | ||
assert.strictEqual(path.win32.isAbsolute('directory\\directory'), false); | ||
|
||
assert.strictEqual(path.posix.isAbsolute('/home/foo'), true); | ||
assert.strictEqual(path.posix.isAbsolute('/home/foo/..'), true); | ||
assert.strictEqual(path.posix.isAbsolute('bar/'), false); | ||
assert.strictEqual(path.posix.isAbsolute('./baz'), false); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe new files don't need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even when the content is entirely copied from a file with the licence header? I would be more than happy to remove those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, the way we've been handling it is keeping it only in the preexisting files