-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_test.js
More file actions
86 lines (74 loc) · 2.62 KB
/
path_test.js
File metadata and controls
86 lines (74 loc) · 2.62 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var demand = require('must');
var Path = require("../../lib/path");
describe("Path", function() {
describe("new", function() {
it("must be an instance of Path", function() {
new Path("").must.be.an.instanceof(Path);
})
})
describe(".prototype.append", function() {
it("must return the path appended to the given part", function() {
var path = new Path("foo.example.dir")
path.append(".com").must.equal("foo.example.dir.com")
})
})
describe(".prototype.addTo", function() {
it("must return an hierarchical object from path", function() {
var path = new Path("foo.example.dir.file")
var obj = path.addTo({}, 42)
obj.must.eql({foo: {example: {dir: {file: 42}}}})
})
it("must merge given an existing hierarchy", function() {
var path = new Path("foo.example.dir.file")
var obj = path.addTo({foo: {example: {link: 69}}}, 42)
obj.must.eql({foo: {example: {link: 69, dir: {file: 42}}}})
})
})
describe(".prototype.get", function() {
it("must walk hierarchy and return value", function() {
var path = new Path("foo.example.dir")
path.get({foo: {example: {dir: 42}}}).must.equal(42)
})
it("must return undefined when a path isn't present", function() {
var path = new Path("foo.example.dir")
demand(path.get({})).be.undefined()
})
})
describe(".prototype.prependToLast", function() {
it("must return path with preprended last part", function() {
var path = new Path("foo.example.dir")
path.prependToLast("cool").must.equal("foo.example.cooldir")
})
it("must return path with last part in titlecase given true", function() {
var path = new Path("foo.example.dir")
path.prependToLast("cool", true).must.equal("foo.example.coolDir")
})
it("must return path with last part as-is given false", function() {
var path = new Path("foo.example.dir")
path.prependToLast("cool", false).must.equal("foo.example.cooldir")
})
})
describe(".prototype.flatten", function() {
it("must return path camel cased given false", function() {
var path = new Path("foo.example.dir")
path.flatten(false).must.equal("FooExampleDir")
})
it("must return path camel cased with lowercase first letter given true",
function() {
var path = new Path("foo.example.dir")
path.flatten(true).must.equal("fooExampleDir")
})
})
describe("last", function() {
it("must equal to the last part of path", function() {
var path = new Path("foo.example.dir")
path.last.must.equal("dir")
})
})
describe("exceptLast", function() {
it("must equal to the path without last part", function() {
var path = new Path("foo.example.dir")
path.exceptLast.must.equal("foo.example")
})
})
})