Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80529 views
1
var assert = require('assert');
2
var commondir = require('../');
3
4
exports.common = function () {
5
assert.equal(
6
commondir([ '/foo', '//foo/bar', '/foo//bar/baz' ]),
7
'/foo'
8
);
9
10
assert.equal(
11
commondir([ '/a/b/c', '/a/b', '/a/b/c/d/e' ]),
12
'/a/b'
13
);
14
15
assert.equal(
16
commondir([ '/x/y/z/w', '/xy/z', '/x/y/z' ]),
17
'/'
18
);
19
20
assert.equal(
21
commondir([ 'X:\\foo', 'X:\\\\foo\\bar', 'X://foo/bar/baz' ]),
22
'X:/foo'
23
);
24
25
assert.equal(
26
commondir([ 'X:\\a\\b\\c', 'X:\\a\\b', 'X:\\a\\b\\c\\d\\e' ]),
27
'X:/a/b'
28
);
29
30
assert.equal(
31
commondir([ 'X:\\x\\y\\z\\w', '\\\\xy\\z', '\\x\\y\\z' ]),
32
'/'
33
);
34
35
assert.throws(function () {
36
assert.equal(
37
commondir([ '/x/y/z/w', 'qrs', '/x/y/z' ]),
38
'/'
39
);
40
});
41
};
42
43
exports.base = function () {
44
assert.equal(
45
commondir('/foo/bar', [ 'baz', './quux', '../bar/bazzy' ]),
46
'/foo/bar'
47
);
48
49
assert.equal(
50
commondir('/a/b', [ 'c', '../b/.', '../../a/b/e' ]),
51
'/a/b'
52
);
53
54
assert.equal(
55
commondir('/a/b/c', [ '..', '../d', '../../a/z/e' ]),
56
'/a'
57
);
58
59
assert.equal(
60
commondir('/foo/bar', [ 'baz', '.\\quux', '..\\bar\\bazzy' ]),
61
'/foo/bar'
62
);
63
64
// Tests including X:\ basedirs must wait until path.resolve supports
65
// Windows-style paths, starting in Node.js v0.5.X
66
};
67
68