test-path-zero-length-strings.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. // These testcases are specific to one uncommon behavior in path module. Few
  3. // of the functions in path module, treat '' strings as current working
  4. // directory. This test makes sure that the behavior is intact between commits.
  5. // See: https://github.com/nodejs/node/pull/2106
  6. var tape = require('tape');
  7. var path = require('../');
  8. var pwd = process.cwd();
  9. tape('path.join zero-length', function (t) {
  10. // join will internally ignore all the zero-length strings and it will return
  11. // '.' if the joined string is a zero-length string.
  12. t.strictEqual(path.posix.join(''), '.');
  13. t.strictEqual(path.posix.join('', ''), '.');
  14. if (path.win32) t.strictEqual(path.win32.join(''), '.');
  15. if (path.win32) t.strictEqual(path.win32.join('', ''), '.');
  16. t.strictEqual(path.join(pwd), pwd);
  17. t.strictEqual(path.join(pwd, ''), pwd);
  18. t.end();
  19. });
  20. tape('path.normalize zero-length', function (t) {
  21. // normalize will return '.' if the input is a zero-length string
  22. t.strictEqual(path.posix.normalize(''), '.');
  23. if (path.win32) t.strictEqual(path.win32.normalize(''), '.');
  24. t.strictEqual(path.normalize(pwd), pwd);
  25. t.end();
  26. });
  27. tape('path.isAbsolute zero-length', function (t) {
  28. // Since '' is not a valid path in any of the common environments, return false
  29. t.strictEqual(path.posix.isAbsolute(''), false);
  30. if (path.win32) t.strictEqual(path.win32.isAbsolute(''), false);
  31. t.end();
  32. });
  33. tape('path.resolve zero-length', function (t) {
  34. // resolve, internally ignores all the zero-length strings and returns the
  35. // current working directory
  36. t.strictEqual(path.resolve(''), pwd);
  37. t.strictEqual(path.resolve('', ''), pwd);
  38. t.end();
  39. });
  40. tape('path.relative zero-length', function (t) {
  41. // relative, internally calls resolve. So, '' is actually the current directory
  42. t.strictEqual(path.relative('', pwd), '');
  43. t.strictEqual(path.relative(pwd, ''), '');
  44. t.strictEqual(path.relative(pwd, pwd), '');
  45. t.end();
  46. });