forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_path.js
More file actions
72 lines (67 loc) · 3.54 KB
/
test_path.js
File metadata and controls
72 lines (67 loc) · 3.54 KB
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
describe('pc.path', function () {
it("path.getDirectory", function() {
expect("folder").to.equal(pc.path.getDirectory("folder/file.txt"));
expect("folder").to.equal(pc.path.getDirectory("folder/another"));
expect("folder/another").to.equal(pc.path.getDirectory("folder/another/"));
expect("").to.equal(pc.path.getDirectory(""));
expect("").to.equal(pc.path.getDirectory("/"));
});
it("path.join", function() {
expect("a/b").to.equal(pc.path.join("a", "b"));
expect("/b").to.equal(pc.path.join("a", "/b"));
expect("/a/b").to.equal(pc.path.join("/a", "b"));
expect("a/b/c").to.equal(pc.path.join("a", "b/c"));
expect("a/b/c").to.equal(pc.path.join("a/b", "c"));
expect("a/b/").to.equal(pc.path.join("a", "b/"));
expect("/b/").to.equal(pc.path.join("a", "/b/"));
expect("a/b/").to.equal(pc.path.join("a", "b/"));
expect("http://a.com/b").to.equal(pc.path.join("http://a.com", "b"));
expect("a/b").to.equal(pc.path.join("", "a/b"));
expect("a/b").to.equal(pc.path.join("a/b", ""));
});
it("path.join, more than two path sections", function () {
expect("a/b/c").to.equal(pc.path.join("a", "b", "c"));
expect("/b/c").to.equal(pc.path.join("a", "/b", "c"));
expect("/a/b/c").to.equal(pc.path.join("/a", "b", "c"));
expect("a/b/c/d").to.equal(pc.path.join("a/b", "c", "d"));
expect("a/b/c/d").to.equal(pc.path.join("a", "b/c", "d"));
expect("a/b/c/d").to.equal(pc.path.join("a", "b", "c/d"));
expect("a/b/c/").to.equal(pc.path.join("a", "b", "c/"));
expect("/b/c/").to.equal(pc.path.join("a", "/b", "c/"));
expect("http://a.com/b/c").to.equal(pc.path.join("http://a.com", "b", "c"));
expect("b/c/").to.equal(pc.path.join("", "b", "c/"));
expect("b/c/").to.equal(pc.path.join("b", "c/", ""));
expect("/").to.equal(pc.path.join("b", "c/", "/"));
expect("a/b/c/d").to.equal(pc.path.join("a", "b", "c", "d"));
});
it("path.join, invalid values", function () {
expect(function(){
pc.path.join("a", undefined);
}).to.throw();
});
it("path.normalize normalizes", function () {
// equal('a/b/c', pc.path.normalize('a/b/c'));
// equal('/a/b/c', pc.path.normalize('/a/b/c'));
// equal('a/b/c', pc.path.normalize('a//b/c'));
// equal('b/c', pc.path.normalize('a/../b/c'));
// equal('a/b/c', pc.path.normalize('a/./b/c'));
// equal('a/b', pc.path.normalize('a/b/c/..'));
// equal('a/b/c/', pc.path.normalize('a/b/c/'));
// equal('../a/b/c/', pc.path.normalize('../a/b/c/'));
// // equal('../../a/b/c', pc.path.normalize('../../a/b/c')); // TODO: fix this
// equal('/', pc.path.normalize('/'));
// equal('../', pc.path.normalize('../'));
// equal('./', pc.path.normalize('./'));
// equal('./', pc.path.normalize('././'));
// equal('../../', pc.path.normalize('../../'));
// equal('.', pc.path.normalize('.'));
// equal('..', pc.path.normalize('./../.'));
});
it("path.extractPath", function () {
expect("./path/to").to.equal(pc.path.extractPath("path/to/file"));
expect("./path/to").to.equal(pc.path.extractPath("./path/to/file"));
expect("../path/to").to.equal(pc.path.extractPath("../path/to/file"));
expect("/path/to").to.equal(pc.path.extractPath("/path/to/file"));
expect("./path/../path/to").to.equal(pc.path.extractPath("path/../path/to/file.txt"));
});
})