Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright Joyent, Inc. and other Node contributors. |
michael@0 | 2 | // |
michael@0 | 3 | // Permission is hereby granted, free of charge, to any person obtaining a |
michael@0 | 4 | // copy of this software and associated documentation files (the |
michael@0 | 5 | // "Software"), to deal in the Software without restriction, including |
michael@0 | 6 | // without limitation the rights to use, copy, modify, merge, publish, |
michael@0 | 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit |
michael@0 | 8 | // persons to whom the Software is furnished to do so, subject to the |
michael@0 | 9 | // following conditions: |
michael@0 | 10 | // |
michael@0 | 11 | // The above copyright notice and this permission notice shall be included |
michael@0 | 12 | // in all copies or substantial portions of the Software. |
michael@0 | 13 | // |
michael@0 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
michael@0 | 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
michael@0 | 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
michael@0 | 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
michael@0 | 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
michael@0 | 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
michael@0 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. |
michael@0 | 21 | |
michael@0 | 22 | |
michael@0 | 23 | // Adapted version of: |
michael@0 | 24 | // https://github.com/joyent/node/blob/v0.9.1/test/simple/test-path.js |
michael@0 | 25 | |
michael@0 | 26 | exports['test path'] = function(assert) { |
michael@0 | 27 | |
michael@0 | 28 | var system = require('sdk/system'); |
michael@0 | 29 | var path = require('sdk/fs/path'); |
michael@0 | 30 | |
michael@0 | 31 | // Shim process global from node. |
michael@0 | 32 | var process = Object.create(require('sdk/system')); |
michael@0 | 33 | process.cwd = process.pathFor.bind(process, 'CurProcD'); |
michael@0 | 34 | |
michael@0 | 35 | var isWindows = require('sdk/system').platform.indexOf('win') === 0; |
michael@0 | 36 | |
michael@0 | 37 | assert.equal(path.basename(''), ''); |
michael@0 | 38 | assert.equal(path.basename('/dir/basename.ext'), 'basename.ext'); |
michael@0 | 39 | assert.equal(path.basename('/basename.ext'), 'basename.ext'); |
michael@0 | 40 | assert.equal(path.basename('basename.ext'), 'basename.ext'); |
michael@0 | 41 | assert.equal(path.basename('basename.ext/'), 'basename.ext'); |
michael@0 | 42 | assert.equal(path.basename('basename.ext//'), 'basename.ext'); |
michael@0 | 43 | |
michael@0 | 44 | if (isWindows) { |
michael@0 | 45 | // On Windows a backslash acts as a path separator. |
michael@0 | 46 | assert.equal(path.basename('\\dir\\basename.ext'), 'basename.ext'); |
michael@0 | 47 | assert.equal(path.basename('\\basename.ext'), 'basename.ext'); |
michael@0 | 48 | assert.equal(path.basename('basename.ext'), 'basename.ext'); |
michael@0 | 49 | assert.equal(path.basename('basename.ext\\'), 'basename.ext'); |
michael@0 | 50 | assert.equal(path.basename('basename.ext\\\\'), 'basename.ext'); |
michael@0 | 51 | |
michael@0 | 52 | } else { |
michael@0 | 53 | // On unix a backslash is just treated as any other character. |
michael@0 | 54 | assert.equal(path.basename('\\dir\\basename.ext'), '\\dir\\basename.ext'); |
michael@0 | 55 | assert.equal(path.basename('\\basename.ext'), '\\basename.ext'); |
michael@0 | 56 | assert.equal(path.basename('basename.ext'), 'basename.ext'); |
michael@0 | 57 | assert.equal(path.basename('basename.ext\\'), 'basename.ext\\'); |
michael@0 | 58 | assert.equal(path.basename('basename.ext\\\\'), 'basename.ext\\\\'); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // POSIX filenames may include control characters |
michael@0 | 62 | // c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html |
michael@0 | 63 | if (!isWindows) { |
michael@0 | 64 | var controlCharFilename = 'Icon' + String.fromCharCode(13); |
michael@0 | 65 | assert.equal(path.basename('/a/b/' + controlCharFilename), |
michael@0 | 66 | controlCharFilename); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | assert.equal(path.dirname('/a/b/'), '/a'); |
michael@0 | 70 | assert.equal(path.dirname('/a/b'), '/a'); |
michael@0 | 71 | assert.equal(path.dirname('/a'), '/'); |
michael@0 | 72 | assert.equal(path.dirname(''), '.'); |
michael@0 | 73 | assert.equal(path.dirname('/'), '/'); |
michael@0 | 74 | assert.equal(path.dirname('////'), '/'); |
michael@0 | 75 | |
michael@0 | 76 | if (isWindows) { |
michael@0 | 77 | assert.equal(path.dirname('c:\\'), 'c:\\'); |
michael@0 | 78 | assert.equal(path.dirname('c:\\foo'), 'c:\\'); |
michael@0 | 79 | assert.equal(path.dirname('c:\\foo\\'), 'c:\\'); |
michael@0 | 80 | assert.equal(path.dirname('c:\\foo\\bar'), 'c:\\foo'); |
michael@0 | 81 | assert.equal(path.dirname('c:\\foo\\bar\\'), 'c:\\foo'); |
michael@0 | 82 | assert.equal(path.dirname('c:\\foo\\bar\\baz'), 'c:\\foo\\bar'); |
michael@0 | 83 | assert.equal(path.dirname('\\'), '\\'); |
michael@0 | 84 | assert.equal(path.dirname('\\foo'), '\\'); |
michael@0 | 85 | assert.equal(path.dirname('\\foo\\'), '\\'); |
michael@0 | 86 | assert.equal(path.dirname('\\foo\\bar'), '\\foo'); |
michael@0 | 87 | assert.equal(path.dirname('\\foo\\bar\\'), '\\foo'); |
michael@0 | 88 | assert.equal(path.dirname('\\foo\\bar\\baz'), '\\foo\\bar'); |
michael@0 | 89 | assert.equal(path.dirname('c:'), 'c:'); |
michael@0 | 90 | assert.equal(path.dirname('c:foo'), 'c:'); |
michael@0 | 91 | assert.equal(path.dirname('c:foo\\'), 'c:'); |
michael@0 | 92 | assert.equal(path.dirname('c:foo\\bar'), 'c:foo'); |
michael@0 | 93 | assert.equal(path.dirname('c:foo\\bar\\'), 'c:foo'); |
michael@0 | 94 | assert.equal(path.dirname('c:foo\\bar\\baz'), 'c:foo\\bar'); |
michael@0 | 95 | assert.equal(path.dirname('\\\\unc\\share'), '\\\\unc\\share'); |
michael@0 | 96 | assert.equal(path.dirname('\\\\unc\\share\\foo'), '\\\\unc\\share\\'); |
michael@0 | 97 | assert.equal(path.dirname('\\\\unc\\share\\foo\\'), '\\\\unc\\share\\'); |
michael@0 | 98 | assert.equal(path.dirname('\\\\unc\\share\\foo\\bar'), |
michael@0 | 99 | '\\\\unc\\share\\foo'); |
michael@0 | 100 | assert.equal(path.dirname('\\\\unc\\share\\foo\\bar\\'), |
michael@0 | 101 | '\\\\unc\\share\\foo'); |
michael@0 | 102 | assert.equal(path.dirname('\\\\unc\\share\\foo\\bar\\baz'), |
michael@0 | 103 | '\\\\unc\\share\\foo\\bar'); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | |
michael@0 | 107 | assert.equal(path.extname(''), ''); |
michael@0 | 108 | assert.equal(path.extname('/path/to/file'), ''); |
michael@0 | 109 | assert.equal(path.extname('/path/to/file.ext'), '.ext'); |
michael@0 | 110 | assert.equal(path.extname('/path.to/file.ext'), '.ext'); |
michael@0 | 111 | assert.equal(path.extname('/path.to/file'), ''); |
michael@0 | 112 | assert.equal(path.extname('/path.to/.file'), ''); |
michael@0 | 113 | assert.equal(path.extname('/path.to/.file.ext'), '.ext'); |
michael@0 | 114 | assert.equal(path.extname('/path/to/f.ext'), '.ext'); |
michael@0 | 115 | assert.equal(path.extname('/path/to/..ext'), '.ext'); |
michael@0 | 116 | assert.equal(path.extname('file'), ''); |
michael@0 | 117 | assert.equal(path.extname('file.ext'), '.ext'); |
michael@0 | 118 | assert.equal(path.extname('.file'), ''); |
michael@0 | 119 | assert.equal(path.extname('.file.ext'), '.ext'); |
michael@0 | 120 | assert.equal(path.extname('/file'), ''); |
michael@0 | 121 | assert.equal(path.extname('/file.ext'), '.ext'); |
michael@0 | 122 | assert.equal(path.extname('/.file'), ''); |
michael@0 | 123 | assert.equal(path.extname('/.file.ext'), '.ext'); |
michael@0 | 124 | assert.equal(path.extname('.path/file.ext'), '.ext'); |
michael@0 | 125 | assert.equal(path.extname('file.ext.ext'), '.ext'); |
michael@0 | 126 | assert.equal(path.extname('file.'), '.'); |
michael@0 | 127 | assert.equal(path.extname('.'), ''); |
michael@0 | 128 | assert.equal(path.extname('./'), ''); |
michael@0 | 129 | assert.equal(path.extname('.file.ext'), '.ext'); |
michael@0 | 130 | assert.equal(path.extname('.file'), ''); |
michael@0 | 131 | assert.equal(path.extname('.file.'), '.'); |
michael@0 | 132 | assert.equal(path.extname('.file..'), '.'); |
michael@0 | 133 | assert.equal(path.extname('..'), ''); |
michael@0 | 134 | assert.equal(path.extname('../'), ''); |
michael@0 | 135 | assert.equal(path.extname('..file.ext'), '.ext'); |
michael@0 | 136 | assert.equal(path.extname('..file'), '.file'); |
michael@0 | 137 | assert.equal(path.extname('..file.'), '.'); |
michael@0 | 138 | assert.equal(path.extname('..file..'), '.'); |
michael@0 | 139 | assert.equal(path.extname('...'), '.'); |
michael@0 | 140 | assert.equal(path.extname('...ext'), '.ext'); |
michael@0 | 141 | assert.equal(path.extname('....'), '.'); |
michael@0 | 142 | assert.equal(path.extname('file.ext/'), '.ext'); |
michael@0 | 143 | assert.equal(path.extname('file.ext//'), '.ext'); |
michael@0 | 144 | assert.equal(path.extname('file/'), ''); |
michael@0 | 145 | assert.equal(path.extname('file//'), ''); |
michael@0 | 146 | assert.equal(path.extname('file./'), '.'); |
michael@0 | 147 | assert.equal(path.extname('file.//'), '.'); |
michael@0 | 148 | |
michael@0 | 149 | if (isWindows) { |
michael@0 | 150 | // On windows, backspace is a path separator. |
michael@0 | 151 | assert.equal(path.extname('.\\'), ''); |
michael@0 | 152 | assert.equal(path.extname('..\\'), ''); |
michael@0 | 153 | assert.equal(path.extname('file.ext\\'), '.ext'); |
michael@0 | 154 | assert.equal(path.extname('file.ext\\\\'), '.ext'); |
michael@0 | 155 | assert.equal(path.extname('file\\'), ''); |
michael@0 | 156 | assert.equal(path.extname('file\\\\'), ''); |
michael@0 | 157 | assert.equal(path.extname('file.\\'), '.'); |
michael@0 | 158 | assert.equal(path.extname('file.\\\\'), '.'); |
michael@0 | 159 | |
michael@0 | 160 | } else { |
michael@0 | 161 | // On unix, backspace is a valid name component like any other character. |
michael@0 | 162 | assert.equal(path.extname('.\\'), ''); |
michael@0 | 163 | assert.equal(path.extname('..\\'), '.\\'); |
michael@0 | 164 | assert.equal(path.extname('file.ext\\'), '.ext\\'); |
michael@0 | 165 | assert.equal(path.extname('file.ext\\\\'), '.ext\\\\'); |
michael@0 | 166 | assert.equal(path.extname('file\\'), ''); |
michael@0 | 167 | assert.equal(path.extname('file\\\\'), ''); |
michael@0 | 168 | assert.equal(path.extname('file.\\'), '.\\'); |
michael@0 | 169 | assert.equal(path.extname('file.\\\\'), '.\\\\'); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | // path.join tests |
michael@0 | 173 | var failures = []; |
michael@0 | 174 | var joinTests = |
michael@0 | 175 | // arguments result |
michael@0 | 176 | [[['.', 'x/b', '..', '/b/c.js'], 'x/b/c.js'], |
michael@0 | 177 | [['/.', 'x/b', '..', '/b/c.js'], '/x/b/c.js'], |
michael@0 | 178 | [['/foo', '../../../bar'], '/bar'], |
michael@0 | 179 | [['foo', '../../../bar'], '../../bar'], |
michael@0 | 180 | [['foo/', '../../../bar'], '../../bar'], |
michael@0 | 181 | [['foo/x', '../../../bar'], '../bar'], |
michael@0 | 182 | [['foo/x', './bar'], 'foo/x/bar'], |
michael@0 | 183 | [['foo/x/', './bar'], 'foo/x/bar'], |
michael@0 | 184 | [['foo/x/', '.', 'bar'], 'foo/x/bar'], |
michael@0 | 185 | [['./'], './'], |
michael@0 | 186 | [['.', './'], './'], |
michael@0 | 187 | [['.', '.', '.'], '.'], |
michael@0 | 188 | [['.', './', '.'], '.'], |
michael@0 | 189 | [['.', '/./', '.'], '.'], |
michael@0 | 190 | [['.', '/////./', '.'], '.'], |
michael@0 | 191 | [['.'], '.'], |
michael@0 | 192 | [['', '.'], '.'], |
michael@0 | 193 | [['', 'foo'], 'foo'], |
michael@0 | 194 | [['foo', '/bar'], 'foo/bar'], |
michael@0 | 195 | [['', '/foo'], '/foo'], |
michael@0 | 196 | [['', '', '/foo'], '/foo'], |
michael@0 | 197 | [['', '', 'foo'], 'foo'], |
michael@0 | 198 | [['foo', ''], 'foo'], |
michael@0 | 199 | [['foo/', ''], 'foo/'], |
michael@0 | 200 | [['foo', '', '/bar'], 'foo/bar'], |
michael@0 | 201 | [['./', '..', '/foo'], '../foo'], |
michael@0 | 202 | [['./', '..', '..', '/foo'], '../../foo'], |
michael@0 | 203 | [['.', '..', '..', '/foo'], '../../foo'], |
michael@0 | 204 | [['', '..', '..', '/foo'], '../../foo'], |
michael@0 | 205 | [['/'], '/'], |
michael@0 | 206 | [['/', '.'], '/'], |
michael@0 | 207 | [['/', '..'], '/'], |
michael@0 | 208 | [['/', '..', '..'], '/'], |
michael@0 | 209 | [[''], '.'], |
michael@0 | 210 | [['', ''], '.'], |
michael@0 | 211 | [[' /foo'], ' /foo'], |
michael@0 | 212 | [[' ', 'foo'], ' /foo'], |
michael@0 | 213 | [[' ', '.'], ' '], |
michael@0 | 214 | [[' ', '/'], ' /'], |
michael@0 | 215 | [[' ', ''], ' '], |
michael@0 | 216 | [['/', 'foo'], '/foo'], |
michael@0 | 217 | [['/', '/foo'], '/foo'], |
michael@0 | 218 | [['/', '//foo'], '/foo'], |
michael@0 | 219 | [['/', '', '/foo'], '/foo'], |
michael@0 | 220 | [['', '/', 'foo'], '/foo'], |
michael@0 | 221 | [['', '/', '/foo'], '/foo'] |
michael@0 | 222 | ]; |
michael@0 | 223 | |
michael@0 | 224 | // Windows-specific join tests |
michael@0 | 225 | if (isWindows) { |
michael@0 | 226 | joinTests = joinTests.concat( |
michael@0 | 227 | [// UNC path expected |
michael@0 | 228 | [['//foo/bar'], '//foo/bar/'], |
michael@0 | 229 | [['\\/foo/bar'], '//foo/bar/'], |
michael@0 | 230 | [['\\\\foo/bar'], '//foo/bar/'], |
michael@0 | 231 | // UNC path expected - server and share separate |
michael@0 | 232 | [['//foo', 'bar'], '//foo/bar/'], |
michael@0 | 233 | [['//foo/', 'bar'], '//foo/bar/'], |
michael@0 | 234 | [['//foo', '/bar'], '//foo/bar/'], |
michael@0 | 235 | // UNC path expected - questionable |
michael@0 | 236 | [['//foo', '', 'bar'], '//foo/bar/'], |
michael@0 | 237 | [['//foo/', '', 'bar'], '//foo/bar/'], |
michael@0 | 238 | [['//foo/', '', '/bar'], '//foo/bar/'], |
michael@0 | 239 | // UNC path expected - even more questionable |
michael@0 | 240 | [['', '//foo', 'bar'], '//foo/bar/'], |
michael@0 | 241 | [['', '//foo/', 'bar'], '//foo/bar/'], |
michael@0 | 242 | [['', '//foo/', '/bar'], '//foo/bar/'], |
michael@0 | 243 | // No UNC path expected (no double slash in first component) |
michael@0 | 244 | [['\\', 'foo/bar'], '/foo/bar'], |
michael@0 | 245 | [['\\', '/foo/bar'], '/foo/bar'], |
michael@0 | 246 | [['', '/', '/foo/bar'], '/foo/bar'], |
michael@0 | 247 | // No UNC path expected (no non-slashes in first component - questionable) |
michael@0 | 248 | [['//', 'foo/bar'], '/foo/bar'], |
michael@0 | 249 | [['//', '/foo/bar'], '/foo/bar'], |
michael@0 | 250 | [['\\\\', '/', '/foo/bar'], '/foo/bar'], |
michael@0 | 251 | [['//'], '/'], |
michael@0 | 252 | // No UNC path expected (share name missing - questionable). |
michael@0 | 253 | [['//foo'], '/foo'], |
michael@0 | 254 | [['//foo/'], '/foo/'], |
michael@0 | 255 | [['//foo', '/'], '/foo/'], |
michael@0 | 256 | [['//foo', '', '/'], '/foo/'], |
michael@0 | 257 | // No UNC path expected (too many leading slashes - questionable) |
michael@0 | 258 | [['///foo/bar'], '/foo/bar'], |
michael@0 | 259 | [['////foo', 'bar'], '/foo/bar'], |
michael@0 | 260 | [['\\\\\\/foo/bar'], '/foo/bar'], |
michael@0 | 261 | // Drive-relative vs drive-absolute paths. This merely describes the |
michael@0 | 262 | // status quo, rather than being obviously right |
michael@0 | 263 | [['c:'], 'c:.'], |
michael@0 | 264 | [['c:.'], 'c:.'], |
michael@0 | 265 | [['c:', ''], 'c:.'], |
michael@0 | 266 | [['', 'c:'], 'c:.'], |
michael@0 | 267 | [['c:.', '/'], 'c:./'], |
michael@0 | 268 | [['c:.', 'file'], 'c:file'], |
michael@0 | 269 | [['c:', '/'], 'c:/'], |
michael@0 | 270 | [['c:', 'file'], 'c:/file'] |
michael@0 | 271 | ]); |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | // Run the join tests. |
michael@0 | 275 | joinTests.forEach(function(test) { |
michael@0 | 276 | var actual = path.join.apply(path, test[0]); |
michael@0 | 277 | var expected = isWindows ? test[1].replace(/\//g, '\\') : test[1]; |
michael@0 | 278 | var message = 'path.join(' + test[0].map(JSON.stringify).join(',') + ')' + |
michael@0 | 279 | '\n expect=' + JSON.stringify(expected) + |
michael@0 | 280 | '\n actual=' + JSON.stringify(actual); |
michael@0 | 281 | if (actual !== expected) failures.push('\n' + message); |
michael@0 | 282 | // assert.equal(actual, expected, message); |
michael@0 | 283 | }); |
michael@0 | 284 | assert.equal(failures.length, 0, failures.join('')); |
michael@0 | 285 | var joinThrowTests = [true, false, 7, null, {}, undefined, [], NaN]; |
michael@0 | 286 | joinThrowTests.forEach(function(test) { |
michael@0 | 287 | assert.throws(function() { |
michael@0 | 288 | path.join(test); |
michael@0 | 289 | }, TypeError); |
michael@0 | 290 | assert.throws(function() { |
michael@0 | 291 | path.resolve(test); |
michael@0 | 292 | }, TypeError); |
michael@0 | 293 | }); |
michael@0 | 294 | |
michael@0 | 295 | |
michael@0 | 296 | // path normalize tests |
michael@0 | 297 | if (isWindows) { |
michael@0 | 298 | assert.equal(path.normalize('./fixtures///b/../b/c.js'), |
michael@0 | 299 | 'fixtures\\b\\c.js'); |
michael@0 | 300 | assert.equal(path.normalize('/foo/../../../bar'), '\\bar'); |
michael@0 | 301 | assert.equal(path.normalize('a//b//../b'), 'a\\b'); |
michael@0 | 302 | assert.equal(path.normalize('a//b//./c'), 'a\\b\\c'); |
michael@0 | 303 | assert.equal(path.normalize('a//b//.'), 'a\\b'); |
michael@0 | 304 | assert.equal(path.normalize('//server/share/dir/file.ext'), |
michael@0 | 305 | '\\\\server\\share\\dir\\file.ext'); |
michael@0 | 306 | } else { |
michael@0 | 307 | assert.equal(path.normalize('./fixtures///b/../b/c.js'), |
michael@0 | 308 | 'fixtures/b/c.js'); |
michael@0 | 309 | assert.equal(path.normalize('/foo/../../../bar'), '/bar'); |
michael@0 | 310 | assert.equal(path.normalize('a//b//../b'), 'a/b'); |
michael@0 | 311 | assert.equal(path.normalize('a//b//./c'), 'a/b/c'); |
michael@0 | 312 | assert.equal(path.normalize('a//b//.'), 'a/b'); |
michael@0 | 313 | } |
michael@0 | 314 | |
michael@0 | 315 | // path.resolve tests |
michael@0 | 316 | if (isWindows) { |
michael@0 | 317 | // windows |
michael@0 | 318 | var resolveTests = |
michael@0 | 319 | // arguments result |
michael@0 | 320 | [[['c:/blah\\blah', 'd:/games', 'c:../a'], 'c:\\blah\\a'], |
michael@0 | 321 | [['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'], |
michael@0 | 322 | [['c:/ignore', 'c:/some/file'], 'c:\\some\\file'], |
michael@0 | 323 | [['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'], |
michael@0 | 324 | [['.'], process.cwd()], |
michael@0 | 325 | [['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'], |
michael@0 | 326 | [['c:/', '//'], 'c:\\'], |
michael@0 | 327 | [['c:/', '//dir'], 'c:\\dir'], |
michael@0 | 328 | [['c:/', '//server/share'], '\\\\server\\share\\'], |
michael@0 | 329 | [['c:/', '//server//share'], '\\\\server\\share\\'], |
michael@0 | 330 | [['c:/', '///some//dir'], 'c:\\some\\dir'] |
michael@0 | 331 | ]; |
michael@0 | 332 | } else { |
michael@0 | 333 | // Posix |
michael@0 | 334 | var resolveTests = |
michael@0 | 335 | // arguments result |
michael@0 | 336 | [[['/var/lib', '../', 'file/'], '/var/file'], |
michael@0 | 337 | [['/var/lib', '/../', 'file/'], '/file'], |
michael@0 | 338 | // For some mysterious reasons OSX debug builds resolve incorrectly |
michael@0 | 339 | // https://tbpl.mozilla.org/php/getParsedLog.php?id=25105489&tree=Mozilla-Inbound |
michael@0 | 340 | // Disable this tests until Bug 891698 is fixed. |
michael@0 | 341 | // [['a/b/c/', '../../..'], process.cwd()], |
michael@0 | 342 | // [['.'], process.cwd()], |
michael@0 | 343 | [['/some/dir', '.', '/absolute/'], '/absolute']]; |
michael@0 | 344 | } |
michael@0 | 345 | var failures = []; |
michael@0 | 346 | resolveTests.forEach(function(test) { |
michael@0 | 347 | var actual = path.resolve.apply(path, test[0]); |
michael@0 | 348 | var expected = test[1]; |
michael@0 | 349 | var message = 'path.resolve(' + test[0].map(JSON.stringify).join(',') + ')' + |
michael@0 | 350 | '\n expect=' + JSON.stringify(expected) + |
michael@0 | 351 | '\n actual=' + JSON.stringify(actual); |
michael@0 | 352 | if (actual !== expected) failures.push('\n' + message); |
michael@0 | 353 | // assert.equal(actual, expected, message); |
michael@0 | 354 | }); |
michael@0 | 355 | assert.equal(failures.length, 0, failures.join('')); |
michael@0 | 356 | |
michael@0 | 357 | // path.isAbsolute tests |
michael@0 | 358 | if (isWindows) { |
michael@0 | 359 | assert.equal(path.isAbsolute('//server/file'), true); |
michael@0 | 360 | assert.equal(path.isAbsolute('\\\\server\\file'), true); |
michael@0 | 361 | assert.equal(path.isAbsolute('C:/Users/'), true); |
michael@0 | 362 | assert.equal(path.isAbsolute('C:\\Users\\'), true); |
michael@0 | 363 | assert.equal(path.isAbsolute('C:cwd/another'), false); |
michael@0 | 364 | assert.equal(path.isAbsolute('C:cwd\\another'), false); |
michael@0 | 365 | assert.equal(path.isAbsolute('directory/directory'), false); |
michael@0 | 366 | assert.equal(path.isAbsolute('directory\\directory'), false); |
michael@0 | 367 | } else { |
michael@0 | 368 | assert.equal(path.isAbsolute('/home/foo'), true); |
michael@0 | 369 | assert.equal(path.isAbsolute('/home/foo/..'), true); |
michael@0 | 370 | assert.equal(path.isAbsolute('bar/'), false); |
michael@0 | 371 | assert.equal(path.isAbsolute('./baz'), false); |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | // path.relative tests |
michael@0 | 375 | if (isWindows) { |
michael@0 | 376 | // windows |
michael@0 | 377 | var relativeTests = |
michael@0 | 378 | // arguments result |
michael@0 | 379 | [['c:/blah\\blah', 'd:/games', 'd:\\games'], |
michael@0 | 380 | ['c:/aaaa/bbbb', 'c:/aaaa', '..'], |
michael@0 | 381 | ['c:/aaaa/bbbb', 'c:/cccc', '..\\..\\cccc'], |
michael@0 | 382 | ['c:/aaaa/bbbb', 'c:/aaaa/bbbb', ''], |
michael@0 | 383 | ['c:/aaaa/bbbb', 'c:/aaaa/cccc', '..\\cccc'], |
michael@0 | 384 | ['c:/aaaa/', 'c:/aaaa/cccc', 'cccc'], |
michael@0 | 385 | ['c:/', 'c:\\aaaa\\bbbb', 'aaaa\\bbbb'], |
michael@0 | 386 | ['c:/aaaa/bbbb', 'd:\\', 'd:\\']]; |
michael@0 | 387 | } else { |
michael@0 | 388 | // posix |
michael@0 | 389 | var relativeTests = |
michael@0 | 390 | // arguments result |
michael@0 | 391 | [['/var/lib', '/var', '..'], |
michael@0 | 392 | ['/var/lib', '/bin', '../../bin'], |
michael@0 | 393 | ['/var/lib', '/var/lib', ''], |
michael@0 | 394 | ['/var/lib', '/var/apache', '../apache'], |
michael@0 | 395 | ['/var/', '/var/lib', 'lib'], |
michael@0 | 396 | ['/', '/var/lib', 'var/lib']]; |
michael@0 | 397 | } |
michael@0 | 398 | var failures = []; |
michael@0 | 399 | relativeTests.forEach(function(test) { |
michael@0 | 400 | var actual = path.relative(test[0], test[1]); |
michael@0 | 401 | var expected = test[2]; |
michael@0 | 402 | var message = 'path.relative(' + |
michael@0 | 403 | test.slice(0, 2).map(JSON.stringify).join(',') + |
michael@0 | 404 | ')' + |
michael@0 | 405 | '\n expect=' + JSON.stringify(expected) + |
michael@0 | 406 | '\n actual=' + JSON.stringify(actual); |
michael@0 | 407 | if (actual !== expected) failures.push('\n' + message); |
michael@0 | 408 | }); |
michael@0 | 409 | assert.equal(failures.length, 0, failures.join('')); |
michael@0 | 410 | |
michael@0 | 411 | // path.sep tests |
michael@0 | 412 | if (isWindows) { |
michael@0 | 413 | // windows |
michael@0 | 414 | assert.equal(path.sep, '\\'); |
michael@0 | 415 | } else { |
michael@0 | 416 | // posix |
michael@0 | 417 | assert.equal(path.sep, '/'); |
michael@0 | 418 | } |
michael@0 | 419 | |
michael@0 | 420 | // path.delimiter tests |
michael@0 | 421 | if (isWindows) { |
michael@0 | 422 | // windows |
michael@0 | 423 | assert.equal(path.delimiter, ';'); |
michael@0 | 424 | } else { |
michael@0 | 425 | // posix |
michael@0 | 426 | assert.equal(path.delimiter, ':'); |
michael@0 | 427 | } |
michael@0 | 428 | |
michael@0 | 429 | }; |
michael@0 | 430 | |
michael@0 | 431 | require('test').run(exports); |