test-path.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright Joyent, Inc. and other Node contributors.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a
  4. // copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8. // persons to whom the Software is furnished to do so, subject to the
  9. // following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included
  12. // in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. 'use strict';
  22. var tape = require('tape');
  23. var path = require('../');
  24. // Test thrown TypeErrors
  25. var typeErrorTests = [true, false, 7, null, {}, undefined, [], NaN];
  26. function fail(t, fn) {
  27. var args = [].slice.call(arguments, 1);
  28. t.throws(function () {
  29. fn.apply(null, args);
  30. }, TypeError);
  31. }
  32. tape('path.posix TypeErrors', function (t) {
  33. typeErrorTests.forEach(function (test) {
  34. fail(t, path.posix.join, test);
  35. fail(t, path.posix.resolve, test);
  36. fail(t, path.posix.normalize, test);
  37. fail(t, path.posix.isAbsolute, test);
  38. fail(t, path.posix.relative, test, 'foo');
  39. fail(t, path.posix.relative, 'foo', test);
  40. fail(t, path.posix.parse, test);
  41. fail(t, path.posix.dirname, test);
  42. fail(t, path.posix.basename, test);
  43. fail(t, path.posix.extname, test);
  44. // undefined is a valid value as the second argument to basename
  45. if (test !== undefined) {
  46. fail(t, path.posix.basename, 'foo', test);
  47. }
  48. });
  49. t.end();
  50. });
  51. tape('path.win32 TypeErrors', { skip: true }, function (t) {
  52. typeErrorTests.forEach(function (test) {
  53. fail(t, path.win32.join, test);
  54. fail(t, path.win32.resolve, test);
  55. fail(t, path.win32.normalize, test);
  56. fail(t, path.win32.isAbsolute, test);
  57. fail(t, path.win32.relative, test, 'foo');
  58. fail(t, path.win32.relative, 'foo', test);
  59. fail(t, path.win32.parse, test);
  60. fail(t, path.win32.dirname, test);
  61. fail(t, path.win32.basename, test);
  62. fail(t, path.win32.extname, test);
  63. // undefined is a valid value as the second argument to basename
  64. if (test !== undefined) {
  65. fail(t, path.win32.basename, 'foo', test);
  66. }
  67. });
  68. t.end();
  69. });
  70. // path.sep tests
  71. tape('path.win32.sep', { skip: true }, function (t) {
  72. // windows
  73. t.strictEqual(path.win32.sep, '\\');
  74. t.end();
  75. });
  76. tape('path.posix.sep', function (t) {
  77. // posix
  78. t.strictEqual(path.posix.sep, '/');
  79. t.end();
  80. });
  81. // path.delimiter tests
  82. tape('path.win32.delimiter', { skip: true }, function (t) {
  83. // windows
  84. t.strictEqual(path.win32.delimiter, ';');
  85. t.end();
  86. });
  87. tape('path.posix.delimiter', function (t) {
  88. // posix
  89. t.strictEqual(path.posix.delimiter, ':');
  90. t.end();
  91. });
  92. tape('path', function (t) {
  93. t.strictEqual(path, path.posix);
  94. t.end();
  95. });