Skip to content

Commit 72db4bf

Browse files
committed
Port test-path.
1 parent e3a8552 commit 72db4bf

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require('./test-path');
12
require('./test-path-basename');
23
require('./test-path-dirname');
34
require('./test-path-extname');

test/test-path.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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';
23+
var tape = require('tape');
24+
var path = require('../');
25+
26+
// Test thrown TypeErrors
27+
var typeErrorTests = [true, false, 7, null, {}, undefined, [], NaN];
28+
29+
function fail(t, fn) {
30+
var args = [].slice.call(arguments, 1);
31+
32+
t.throws(function () {
33+
fn.apply(null, args);
34+
}, TypeError);
35+
}
36+
37+
tape('path.posix TypeErrors', function (t) {
38+
typeErrorTests.forEach(function (test) {
39+
fail(t, path.posix.join, test);
40+
fail(t, path.posix.resolve, test);
41+
fail(t, path.posix.normalize, test);
42+
fail(t, path.posix.isAbsolute, test);
43+
fail(t, path.posix.relative, test, 'foo');
44+
fail(t, path.posix.relative, 'foo', test);
45+
fail(t, path.posix.parse, test);
46+
fail(t, path.posix.dirname, test);
47+
fail(t, path.posix.basename, test);
48+
fail(t, path.posix.extname, test);
49+
50+
// undefined is a valid value as the second argument to basename
51+
if (test !== undefined) {
52+
fail(t, path.posix.basename, 'foo', test);
53+
}
54+
});
55+
t.end();
56+
});
57+
58+
tape('path.win32 TypeErrors', { skip: true }, function (t) {
59+
typeErrorTests.forEach(function (test) {
60+
fail(t, path.win32.join, test);
61+
fail(t, path.win32.resolve, test);
62+
fail(t, path.win32.normalize, test);
63+
fail(t, path.win32.isAbsolute, test);
64+
fail(t, path.win32.relative, test, 'foo');
65+
fail(t, path.win32.relative, 'foo', test);
66+
fail(t, path.win32.parse, test);
67+
fail(t, path.win32.dirname, test);
68+
fail(t, path.win32.basename, test);
69+
fail(t, path.win32.extname, test);
70+
71+
// undefined is a valid value as the second argument to basename
72+
if (test !== undefined) {
73+
fail(t, path.win32.basename, 'foo', test);
74+
}
75+
});
76+
t.end();
77+
});
78+
79+
// path.sep tests
80+
tape('path.win32.sep', { skip: true }, function (t) {
81+
// windows
82+
t.strictEqual(path.win32.sep, '\\');
83+
t.end();
84+
});
85+
tape('path.posix.sep', function (t) {
86+
// posix
87+
t.strictEqual(path.posix.sep, '/');
88+
t.end();
89+
});
90+
91+
// path.delimiter tests
92+
tape('path.win32.delimiter', { skip: true }, function (t) {
93+
// windows
94+
t.strictEqual(path.win32.delimiter, ';');
95+
t.end();
96+
});
97+
tape('path.posix.delimiter', function (t) {
98+
// posix
99+
t.strictEqual(path.posix.delimiter, ':');
100+
t.end();
101+
});
102+
103+
tape('path', function (t) {
104+
t.strictEqual(path, path.posix);
105+
t.end();
106+
});
107+

0 commit comments

Comments
 (0)