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 22'use strict'; 23const common = require('../common'); 24const assert = require('assert'); 25const path = require('path'); 26 27// Test thrown TypeErrors 28const typeErrorTests = [true, false, 7, null, {}, undefined, [], NaN]; 29 30function fail(fn) { 31 const args = Array.from(arguments).slice(1); 32 33 assert.throws(() => { 34 fn.apply(null, args); 35 }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' }); 36} 37 38typeErrorTests.forEach((test) => { 39 [path.posix, path.win32].forEach((namespace) => { 40 fail(namespace.join, test); 41 fail(namespace.resolve, test); 42 fail(namespace.normalize, test); 43 fail(namespace.isAbsolute, test); 44 fail(namespace.relative, test, 'foo'); 45 fail(namespace.relative, 'foo', test); 46 fail(namespace.parse, test); 47 fail(namespace.dirname, test); 48 fail(namespace.basename, test); 49 fail(namespace.extname, test); 50 51 // Undefined is a valid value as the second argument to basename 52 if (test !== undefined) { 53 fail(namespace.basename, 'foo', test); 54 } 55 }); 56}); 57 58// path.sep tests 59// windows 60assert.strictEqual(path.win32.sep, '\\'); 61// posix 62assert.strictEqual(path.posix.sep, '/'); 63 64// path.delimiter tests 65// windows 66assert.strictEqual(path.win32.delimiter, ';'); 67// posix 68assert.strictEqual(path.posix.delimiter, ':'); 69 70if (common.isWindows) 71 assert.strictEqual(path, path.win32); 72else 73 assert.strictEqual(path, path.posix); 74