diff options
author | isaacs <i@izs.me> | 2010-10-26 14:41:06 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-11-14 22:49:26 -0800 |
commit | 9996b459e15581fcbff22de2f9a2b5173fc2ba5f (patch) | |
tree | 93c8050ab102666e133464128f5a5c3a708b24d3 /test/simple/test-path.js | |
parent | 25eecd179bb50b08a97eccd80edde1b9afa124d0 (diff) | |
download | node-new-9996b459e15581fcbff22de2f9a2b5173fc2ba5f.tar.gz |
Implement new path.join behavior
1. Express desired path.join behavior in tests.
2. Update fs.realpath to reflect new path.join behavior
3. Update url.resolve() to use new path.join behavior.
Diffstat (limited to 'test/simple/test-path.js')
-rw-r--r-- | test/simple/test-path.js | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/test/simple/test-path.js b/test/simple/test-path.js index 6570732ab3..e91597bbbb 100644 --- a/test/simple/test-path.js +++ b/test/simple/test-path.js @@ -37,8 +37,71 @@ assert.equal(path.extname(".path/file.ext"), ".ext"); assert.equal(path.extname("file.ext.ext"), ".ext"); assert.equal(path.extname("file."), "."); -assert.equal(path.join(".", "fixtures/b", "..", "/b/c.js"), "fixtures/b/c.js"); -assert.equal(path.join("/foo", "../../../bar"), "/bar"); +// path.join tests +var failures = []; +var joinTests = + // arguments result + [[['.', 'x/b', '..', '/b/c.js' ], 'x/b/c.js' ] + ,[['/.', 'x/b', '..', '/b/c.js' ], '/x/b/c.js' ] + ,[['/foo', '../../../bar' ], '/bar' ] + ,[['foo', '../../../bar' ], '../../bar' ] + ,[['foo/', '../../../bar' ], '../../bar' ] + ,[['foo/x', '../../../bar' ], '../bar' ] + ,[['foo/x', './bar' ], 'foo/x/bar' ] + ,[['foo/x/', './bar' ], 'foo/x/bar' ] + ,[['foo/x/', '.', 'bar' ], 'foo/x/bar' ] + ,[['./' ], './' ] + ,[['.', './' ], './' ] + ,[['.', '.', '.' ], '.' ] + ,[['.', './', '.' ], '.' ] + ,[['.', '/./', '.' ], '.' ] + ,[['.', '/////./', '.' ], '.' ] + ,[['.' ], '.' ] + ,[['','.' ], '.' ] + ,[['', 'foo' ], 'foo' ] + ,[['foo', '/bar' ], 'foo/bar' ] + ,[['', '/foo' ], '/foo' ] + ,[['', '', '/foo' ], '/foo' ] + ,[['', '', 'foo' ], 'foo' ] + ,[['foo', '' ], 'foo' ] + ,[['foo/', '' ], 'foo/' ] + ,[['foo', '', '/bar' ], 'foo/bar' ] + ,[['./', '..', '/foo' ], '../foo' ] + ,[['./', '..', '..', '/foo' ], '../../foo' ] + ,[['.', '..', '..', '/foo' ], '../../foo' ] + ,[['', '..', '..', '/foo' ], '../../foo' ] + ,[['/' ], '/' ] + ,[['/', '.' ], '/' ] + ,[['/', '..' ], '/' ] + ,[['/', '..', '..' ], '/' ] + ,[['' ], '.' ] + ,[['', '' ], '.' ] + ,[[' /foo' ], ' /foo' ] + ,[[' ', 'foo' ], ' /foo' ] + ,[[' ', '.' ], ' ' ] + ,[[' ', '/' ], ' /' ] + ,[[' ', '' ], ' ' ] + // preserving empty path parts, for url resolution case + // pass boolean true as LAST argument. + ,[['', '', true ], '/' ] + ,[['foo', '', true ], 'foo/' ] + ,[['foo', '', 'bar', true ], 'foo//bar' ] + ,[['foo/', '', 'bar', true ], 'foo///bar' ] + ,[['', true ], '.' ] + // filtration of non-strings. + ,[['x', true, 7, 'y', null, {} ], 'x/y' ] + ]; +joinTests.forEach(function (test) { + var actual = path.join.apply(path, test[0]); + var expected = test[1]; + var message = "path.join("+test[0].map(JSON.stringify).join(",")+")" + + "\n expect="+JSON.stringify(expected) + + "\n actual="+JSON.stringify(actual); + if (actual !== expected) failures.push("\n"+message); + // assert.equal(actual, expected, message); +}); +assert.equal(failures.length, 0, failures.join("")) + assert.equal(path.normalize("./fixtures///b/../b/c.js"), "fixtures/b/c.js"); assert.equal(path.normalize("./fixtures///b/../b/c.js",true), "fixtures///b/c.js"); |