Skip to content

Commit

Permalink
test: zero-length strings with path module functions
Browse files Browse the repository at this point in the history
These testcases are specific to one uncommon behaviour in path module.
Few of the functions in path module, treat '' strings as current working
directory. This test makes sure that the behaviour is intact between
commits. See: #2106
  • Loading branch information
thefourtheye committed Jul 7, 2015
1 parent 1b6838f commit a65d5fd
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/parallel/test-path-zero-length-strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

// These testcases are specific to one uncommon behaviour in path module. Few
// of the functions in path module, treat '' strings as current working
// directory. This test makes sure that the behaviour is intact between commits.
// See: https://github.com/nodejs/io.js/pull/2106

const common = require('../common');
const assert = require('assert');
const path = require('path');
const pwd = process.cwd();

// join will internally ignore all the zero-length strings and it will return
// '.' if the joined string is a zero-length string.
assert.equal(path.join(''), '.');
assert.equal(path.join('', ''), '.');
assert.equal(path.join(pwd), pwd);
assert.equal(path.join(pwd, ''), pwd);

// normalize will return '.' if the input is a zero-length string
assert.equal(path.normalize(''), '.');
assert.equal(path.normalize(pwd), pwd);

// Since '' is not a valid path in any of the common environments, return false
assert.equal(path.isAbsolute(''), false);

// resolve, internally ignores all the zero-length strings and returns the
// current working directory
assert.equal(path.resolve(''), pwd);
assert.equal(path.resolve('', ''), pwd);

// relative, internally calls resolve. So, '' is actually the current directory
assert.equal(path.relative('', pwd), '');
assert.equal(path.relative(pwd, ''), '');
assert.equal(path.relative(pwd, pwd), '');

0 comments on commit a65d5fd

Please sign in to comment.