Skip to content

Commit 153e907

Browse files
committed
Port test-path-zero-length-strings.
1 parent ed07938 commit 153e907

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ require('./test-path-isabsolute');
66
require('./test-path-join');
77
require('./test-path-relative');
88
require('./test-path-resolve');
9+
require('./test-path-zero-length-strings');

test/test-path-zero-length-strings.js

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

0 commit comments

Comments
 (0)