-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.js
87 lines (78 loc) · 2.98 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
/*!
* normalize-path <https://github.com/jonschlinkert/normalize-path>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Licensed under the MIT License
*/
require('mocha');
var path = require('path');
var argv = require('minimist')(process.argv.slice(2));
var assert = require('assert');
var normalize = require('./');
if (argv.bench) {
var b = path.join(__dirname, 'benchmark/code', argv.bench);
console.log(b);
normalize = require(b);
}
describe('normalize-path', function() {
describe('single slash', function() {
it('should always return a single forward slash', function() {
assert.equal(normalize('/'), '/');
assert.equal(normalize('/', true), '/');
assert.equal(normalize('\\'), '/');
assert.equal(normalize('\\', true), '/');
});
});
describe('strip trailing slashes', function() {
var units = [
['../../foo/bar', '../../foo/bar'],
['..\\..\\foo/bar', '../../foo/bar'],
['..\\\\..\\\\foo/bar', '../../foo/bar'],
['//foo/bar\\baz', '/foo/bar/baz'],
['//foo\\bar\\baz', '/foo/bar/baz'],
['/user/docs/Letter.txt', '/user/docs/Letter.txt'],
['\\?\\C:\\user\\docs\\Letter.txt', '/?/C:/user/docs/Letter.txt'],
['\\?\\UNC\\Server01\\user\\docs\\Letter.txt', '/?/UNC/Server01/user/docs/Letter.txt'],
['\\\\.\\CdRomX', '//./CdRomX'],
['\\\\.\\PhysicalDiskX', '//./PhysicalDiskX'],
['\\\\?\\C:\\user\\docs\\Letter.txt', '//?/C:/user/docs/Letter.txt'],
['\\\\?\\UNC\\Server01\\user\\docs\\Letter.txt', '//?/UNC/Server01/user/docs/Letter.txt'],
['\\Server01\\user\\docs\\Letter.txt', '/Server01/user/docs/Letter.txt'],
['C:\\user\\docs\\Letter.txt', 'C:/user/docs/Letter.txt'],
['C:\\user\\docs\\somefile.ext:alternate_stream_name', 'C:/user/docs/somefile.ext:alternate_stream_name'],
['C:Letter.txt', 'C:Letter.txt'],
['E://foo//bar//baz', 'E:/foo/bar/baz'],
['E://foo//bar//baz//', 'E:/foo/bar/baz'],
['E://foo//bar//baz//////', 'E:/foo/bar/baz'],
['E://foo/bar\\baz', 'E:/foo/bar/baz'],
['E://foo\\bar\\baz', 'E:/foo/bar/baz'],
['E:/foo/bar/baz/', 'E:/foo/bar/baz'],
['E:/foo/bar/baz///', 'E:/foo/bar/baz'],
['E:\\\\foo/bar\\baz', 'E:/foo/bar/baz'],
['foo\\bar\\baz', 'foo/bar/baz'],
['foo\\bar\\baz\\', 'foo/bar/baz'],
['foo\\bar\\baz\\\\\\', 'foo/bar/baz'],
];
units.forEach(function(unit) {
it('should normalize ' + unit[0], function() {
assert.equal(normalize(unit[0]), unit[1]);
});
});
});
describe('keep trailing slashes', function() {
var units = [
['\\', '/'],
['foo\\bar\\baz\\', 'foo/bar/baz/'],
['foo\\\\bar\\\\baz\\\\', 'foo/bar/baz/'],
['foo//bar//baz//', 'foo/bar/baz/'],
['foo/bar/baz/', 'foo/bar/baz/'],
['./foo/bar/baz/', './foo/bar/baz/']
];
units.forEach(function(unit) {
it('should normalize ' + unit[0], function() {
assert.equal(normalize(unit[0], false), unit[1]);
});
});
});
});