summaryrefslogtreecommitdiff
path: root/test/parallel/test-path-parse-format.js
diff options
context:
space:
mode:
authorNathan Woltman <nwoltman@outlook.com>2015-08-16 23:26:46 -0400
committerJoão Reis <reis@janeasystems.com>2015-11-27 11:53:33 +0000
commitd1000b413793bb021e72a4a04c939364484433a3 (patch)
tree436b4d9a86c5d3e747d70ea58fc3ca3cbf9e42be /test/parallel/test-path-parse-format.js
parente25f8683f1735f55a27c00d41691be286f50e13f (diff)
downloadandroid-node-v8-d1000b413793bb021e72a4a04c939364484433a3.tar.gz
android-node-v8-d1000b413793bb021e72a4a04c939364484433a3.tar.bz2
android-node-v8-d1000b413793bb021e72a4a04c939364484433a3.zip
path: make format() consistent and more functional
Make the win32 and posix versions of path.format() consistent in when they add a directory separator between the dir and base parts of the path (always add it unless the dir part is the same as the root). Also, path.format() is now more functional in that it uses the name and ext parts of the path if the base part is left out and it uses the root part if the dir part is left out. Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/2408
Diffstat (limited to 'test/parallel/test-path-parse-format.js')
-rw-r--r--test/parallel/test-path-parse-format.js30
1 files changed, 18 insertions, 12 deletions
diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js
index 0d5502a1df..af1d993ffd 100644
--- a/test/parallel/test-path-parse-format.js
+++ b/test/parallel/test-path-parse-format.js
@@ -1,15 +1,16 @@
'use strict';
require('../common');
-var assert = require('assert');
-var path = require('path');
+const assert = require('assert');
+const path = require('path');
-var winPaths = [
+const winPaths = [
'C:\\path\\dir\\index.html',
- 'C:\\another_path\\DIR\\1\\2\\33\\index',
+ 'C:\\another_path\\DIR\\1\\2\\33\\\\index',
'another_path\\DIR with spaces\\1\\2\\33\\index',
'\\foo\\C:',
'file',
'.\\file',
+ 'C:\\',
'',
// unc
@@ -19,13 +20,17 @@ var winPaths = [
'\\\\?\\UNC\\server\\share'
];
-var winSpecialCaseFormatTests = [
+const winSpecialCaseFormatTests = [
[{dir: 'some\\dir'}, 'some\\dir\\'],
[{base: 'index.html'}, 'index.html'],
+ [{root: 'C:\\'}, 'C:\\'],
+ [{name: 'index', ext: '.html'}, 'index.html'],
+ [{dir: 'some\\dir', name: 'index', ext: '.html'}, 'some\\dir\\index.html'],
+ [{root: 'C:\\', name: 'index', ext: '.html'}, 'C:\\index.html'],
[{}, '']
];
-var unixPaths = [
+const unixPaths = [
'/home/user/dir/file.txt',
'/home/user/a dir/another File.zip',
'/home/user/a dir//another&File.',
@@ -35,16 +40,21 @@ var unixPaths = [
'.\\file',
'./file',
'C:\\foo',
+ '/',
''
];
-var unixSpecialCaseFormatTests = [
+const unixSpecialCaseFormatTests = [
[{dir: 'some/dir'}, 'some/dir/'],
[{base: 'index.html'}, 'index.html'],
+ [{root: '/'}, '/'],
+ [{name: 'index', ext: '.html'}, 'index.html'],
+ [{dir: 'some/dir', name: 'index', ext: '.html'}, 'some/dir/index.html'],
+ [{root: '/', name: 'index', ext: '.html'}, '/index.html'],
[{}, '']
];
-var errors = [
+const errors = [
{method: 'parse', input: [null],
message: /Path must be a string. Received null/},
{method: 'parse', input: [{}],
@@ -63,10 +73,6 @@ var errors = [
message: /Parameter "pathObject" must be an object, not boolean/},
{method: 'format', input: [1],
message: /Parameter "pathObject" must be an object, not number/},
- {method: 'format', input: [{root: true}],
- message: /"pathObject\.root" must be a string or undefined, not boolean/},
- {method: 'format', input: [{root: 12}],
- message: /"pathObject\.root" must be a string or undefined, not number/},
];
checkParseFormat(path.win32, winPaths);