1 |
3a515b92
|
cagy
|
var test = require('tape');
|
2 |
|
|
var commondir = require('../');
|
3 |
|
|
|
4 |
|
|
test('common', function (t) {
|
5 |
|
|
t.equal(
|
6 |
|
|
commondir([ '/foo', '//foo/bar', '/foo//bar/baz' ]),
|
7 |
|
|
'/foo'
|
8 |
|
|
);
|
9 |
|
|
t.equal(
|
10 |
|
|
commondir([ '/a/b/c', '/a/b', '/a/b/c/d/e' ]),
|
11 |
|
|
'/a/b'
|
12 |
|
|
);
|
13 |
|
|
t.equal(
|
14 |
|
|
commondir([ '/x/y/z/w', '/xy/z', '/x/y/z' ]),
|
15 |
|
|
'/'
|
16 |
|
|
);
|
17 |
|
|
t.equal(
|
18 |
|
|
commondir([ 'X:\\foo', 'X:\\\\foo\\bar', 'X://foo/bar/baz' ]),
|
19 |
|
|
'X:/foo'
|
20 |
|
|
);
|
21 |
|
|
t.equal(
|
22 |
|
|
commondir([ 'X:\\a\\b\\c', 'X:\\a\\b', 'X:\\a\\b\\c\\d\\e' ]),
|
23 |
|
|
'X:/a/b'
|
24 |
|
|
);
|
25 |
|
|
t.equal(
|
26 |
|
|
commondir([ 'X:\\x\\y\\z\\w', '\\\\xy\\z', '\\x\\y\\z' ]),
|
27 |
|
|
'/'
|
28 |
|
|
);
|
29 |
|
|
t.throws(function () {
|
30 |
|
|
commondir([ '/x/y/z/w', 'qrs', '/x/y/z' ]);
|
31 |
|
|
});
|
32 |
|
|
t.end();
|
33 |
|
|
});
|
34 |
|
|
|
35 |
|
|
test('base', function (t) {
|
36 |
|
|
t.equal(
|
37 |
|
|
commondir('/foo/bar', [ 'baz', './quux', '../bar/bazzy' ]),
|
38 |
|
|
'/foo/bar'
|
39 |
|
|
);
|
40 |
|
|
t.equal(
|
41 |
|
|
commondir('/a/b', [ 'c', '../b/.', '../../a/b/e' ]),
|
42 |
|
|
'/a/b'
|
43 |
|
|
);
|
44 |
|
|
t.equal(
|
45 |
|
|
commondir('/a/b/c', [ '..', '../d', '../../a/z/e' ]),
|
46 |
|
|
'/a'
|
47 |
|
|
);
|
48 |
|
|
t.equal(
|
49 |
|
|
commondir('/foo/bar', [ 'baz', '.\\quux', '..\\bar\\bazzy' ]),
|
50 |
|
|
'/foo/bar'
|
51 |
|
|
);
|
52 |
|
|
// Tests including X:\ basedirs must wait until path.resolve supports
|
53 |
|
|
// Windows-style paths, starting in Node.js v0.5.X
|
54 |
|
|
t.end();
|
55 |
|
|
});
|