summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTony Huang <cnwzhjs@gmail.com>2011-03-06 10:42:33 +0800
committerRyan Dahl <ry@tinyclouds.org>2011-03-08 11:03:21 -0800
commit502900c0bc9b78faf191489c0ea4d8c00f1642d2 (patch)
tree540dfeb1eaa4b572f34ae079048f93d345b18baf /test
parentcf78ce59b3c0a9e7cdcdbd84d71300b04150b6df (diff)
downloadnodejs-502900c0bc9b78faf191489c0ea4d8c00f1642d2.tar.gz
nodejs-502900c0bc9b78faf191489c0ea4d8c00f1642d2.tar.bz2
nodejs-502900c0bc9b78faf191489c0ea4d8c00f1642d2.zip
add path.relative
Diffstat (limited to 'test')
-rw-r--r--test/simple/test-path.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/simple/test-path.js b/test/simple/test-path.js
index c263bbcbf..92d160ff2 100644
--- a/test/simple/test-path.js
+++ b/test/simple/test-path.js
@@ -147,3 +147,39 @@ resolveTests.forEach(function(test) {
// assert.equal(actual, expected, message);
});
assert.equal(failures.length, 0, failures.join(''));
+
+// path.relative tests
+if (isWindows) {
+ // windows
+ var relativeTests =
+ // arguments result
+ [['c:/blah\\blah', 'd:/games', 'd:\\games'],
+ ['c:/aaaa/bbbb', 'c:/aaaa', '..'],
+ ['c:/aaaa/bbbb', 'c:/cccc', '..\\..\\cccc'],
+ ['c:/aaaa/bbbb', 'c:/aaaa/bbbb',''],
+ ['c:/aaaa/bbbb', 'c:/aaaa/cccc','..\\cccc'],
+ ['c:/aaaa/', 'c:/aaaa/cccc', 'cccc'],
+ ['c:/', 'c:\\aaaa\\bbbb', 'aaaa\\bbbb'],
+ ['c:/aaaa/bbbb', 'd:\\', 'd:\\']];
+} else {
+ // posix
+ var relativeTests =
+ // arguments result
+ [['/var/lib', '/var', '..'],
+ ['/var/lib', '/bin', '../../bin'],
+ ['/var/lib', '/var/lib', ''],
+ ['/var/lib', '/var/apache', '../apache'],
+ ['/var/', '/var/lib', 'lib'],
+ ['/', '/var/lib', 'var/lib']];
+}
+var failures = [];
+relativeTests.forEach(function(test) {
+ var actual = path.relative(test[0], test[1]);
+ var expected = test[2];
+ var message = 'path.relative(' + test.slice(0, 2).map(JSON.stringify).join(',') + ')' +
+ '\n expect=' + JSON.stringify(expected) +
+ '\n actual=' + JSON.stringify(actual);
+ if (actual !== expected) failures.push('\n' + message);
+});
+assert.equal(failures.length, 0, failures.join(''));
+