test-path-resolve.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. var tape = require('tape');
  3. var path = require('../');
  4. var windowsTests =
  5. // arguments result
  6. [[['c:/blah\\blah', 'd:/games', 'c:../a'], 'c:\\blah\\a'],
  7. [['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'],
  8. [['c:/ignore', 'c:/some/file'], 'c:\\some\\file'],
  9. [['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'],
  10. [['.'], process.cwd()],
  11. [['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'],
  12. [['c:/', '//'], 'c:\\'],
  13. [['c:/', '//dir'], 'c:\\dir'],
  14. [['c:/', '//server/share'], '\\\\server\\share\\'],
  15. [['c:/', '//server//share'], '\\\\server\\share\\'],
  16. [['c:/', '///some//dir'], 'c:\\some\\dir'],
  17. [['C:\\foo\\tmp.3\\', '..\\tmp.3\\cycles\\root.js'],
  18. 'C:\\foo\\tmp.3\\cycles\\root.js']
  19. ];
  20. var posixTests =
  21. // arguments result
  22. [[['/var/lib', '../', 'file/'], '/var/file'],
  23. [['/var/lib', '/../', 'file/'], '/file'],
  24. [['a/b/c/', '../../..'], process.cwd()],
  25. [['.'], process.cwd()],
  26. [['/some/dir', '.', '/absolute/'], '/absolute'],
  27. [['/foo/tmp.3/', '../tmp.3/cycles/root.js'], '/foo/tmp.3/cycles/root.js']
  28. ];
  29. tape('path.posix.resolve', function (t) {
  30. posixTests.forEach(function (p) {
  31. var actual = path.posix.resolve.apply(null, p[0]);
  32. t.strictEqual(actual, p[1]);
  33. });
  34. t.end();
  35. });
  36. tape('path.win32.resolve', { skip: true }, function (t) {
  37. windowsTests.forEach(function (p) {
  38. var actual = path.win32.resolve.apply(null, p[0]);
  39. t.strictEqual(actual, p[1]);
  40. });
  41. t.end();
  42. });