test-path-relative.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. var tape = require('tape');
  3. var path = require('../');
  4. var relativeTests = {
  5. win32:
  6. // arguments result
  7. [['c:/blah\\blah', 'd:/games', 'd:\\games'],
  8. ['c:/aaaa/bbbb', 'c:/aaaa', '..'],
  9. ['c:/aaaa/bbbb', 'c:/cccc', '..\\..\\cccc'],
  10. ['c:/aaaa/bbbb', 'c:/aaaa/bbbb', ''],
  11. ['c:/aaaa/bbbb', 'c:/aaaa/cccc', '..\\cccc'],
  12. ['c:/aaaa/', 'c:/aaaa/cccc', 'cccc'],
  13. ['c:/', 'c:\\aaaa\\bbbb', 'aaaa\\bbbb'],
  14. ['c:/aaaa/bbbb', 'd:\\', 'd:\\'],
  15. ['c:/AaAa/bbbb', 'c:/aaaa/bbbb', ''],
  16. ['c:/aaaaa/', 'c:/aaaa/cccc', '..\\aaaa\\cccc'],
  17. ['C:\\foo\\bar\\baz\\quux', 'C:\\', '..\\..\\..\\..'],
  18. ['C:\\foo\\test', 'C:\\foo\\test\\bar\\package.json', 'bar\\package.json'],
  19. ['C:\\foo\\bar\\baz-quux', 'C:\\foo\\bar\\baz', '..\\baz'],
  20. ['C:\\foo\\bar\\baz', 'C:\\foo\\bar\\baz-quux', '..\\baz-quux'],
  21. ['\\\\foo\\bar', '\\\\foo\\bar\\baz', 'baz'],
  22. ['\\\\foo\\bar\\baz', '\\\\foo\\bar', '..'],
  23. ['\\\\foo\\bar\\baz-quux', '\\\\foo\\bar\\baz', '..\\baz'],
  24. ['\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz-quux', '..\\baz-quux'],
  25. ['C:\\baz-quux', 'C:\\baz', '..\\baz'],
  26. ['C:\\baz', 'C:\\baz-quux', '..\\baz-quux'],
  27. ['\\\\foo\\baz-quux', '\\\\foo\\baz', '..\\baz'],
  28. ['\\\\foo\\baz', '\\\\foo\\baz-quux', '..\\baz-quux'],
  29. ['C:\\baz', '\\\\foo\\bar\\baz', '\\\\foo\\bar\\baz'],
  30. ['\\\\foo\\bar\\baz', 'C:\\baz', 'C:\\baz']
  31. ],
  32. posix:
  33. // arguments result
  34. [['/var/lib', '/var', '..'],
  35. ['/var/lib', '/bin', '../../bin'],
  36. ['/var/lib', '/var/lib', ''],
  37. ['/var/lib', '/var/apache', '../apache'],
  38. ['/var/', '/var/lib', 'lib'],
  39. ['/', '/var/lib', 'var/lib'],
  40. ['/foo/test', '/foo/test/bar/package.json', 'bar/package.json'],
  41. ['/Users/a/web/b/test/mails', '/Users/a/web/b', '../..'],
  42. ['/foo/bar/baz-quux', '/foo/bar/baz', '../baz'],
  43. ['/foo/bar/baz', '/foo/bar/baz-quux', '../baz-quux'],
  44. ['/baz-quux', '/baz', '../baz'],
  45. ['/baz', '/baz-quux', '../baz-quux']
  46. ]
  47. };
  48. tape('path.posix.relative', function (t) {
  49. relativeTests.posix.forEach(function (p) {
  50. var expected = p[2];
  51. var actual = path.posix.relative(p[0], p[1]);
  52. t.strictEqual(actual, expected);
  53. });
  54. t.end();
  55. });
  56. tape('path.win32.relative', { skip: true }, function (t) {
  57. relativeTests.win32.forEach(function (p) {
  58. var expected = p[2];
  59. var actual = path.win32.relative(p[0], p[1]);
  60. t.strictEqual(actual, expected);
  61. });
  62. t.end();
  63. });