-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
77 lines (64 loc) · 1.87 KB
/
test.js
File metadata and controls
77 lines (64 loc) · 1.87 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
const chai = require('chai');
const expect = chai.expect;
const chaiDeepMatch = require('chai-deep-match');
chai.use(chaiDeepMatch);
const string2tree = require('./');
describe('test cases', () => {
it('param is null', () => {
expect(string2tree(null)).to.deep.match({});
});
it('value undefined', () => {
expect(string2tree({'a.b.c': undefined})).to.deep.match({a: {b: {c: {}}}});
});
it('single', () => {
expect(string2tree({'a.b.c': 1})).to.deep.match({a: {b: {c: {_v: 1}}}});
});
it('branch', () => {
expect(string2tree({'a.b.c': 1, 'a.b.d': 2})).to.deep.match({a: {b: {c: {_v: 1}, d: {_v: 2}}}});
});
it('parent-child', () => {
expect(string2tree({'a.b.c': 1, 'a.b': 2})).to.deep.match({a: {b: {_v: 2, c: {_v: 1}}}});
});
it('multiroot', () => {
expect(string2tree({'a.b.c': 1, 'd': 2, 'e': 3})).to.deep.match({a: {b: {c: {_v: 1}}}, d: {_v: 2}, e: {_v: 3}});
});
it('complex', () => {
expect(string2tree({
'a.b.c.d': 1,
'a.b': 2,
'a.b.e': 3,
'f.g': 4
}
)).to.deep.match({
a: {
b: {
c: {
d: {
_v: 1
}
},
_v: 2,
e: {
_v: 3
}
}
},
f: {
g: {
_v: 4
}
}
})
});
it('value types', () => {
const f = (x) => {
return true
};
expect(string2tree({'a': 1, 'b': true, 'c': [5, 6], 'd': f})).to.deep.match({
a: {_v: 1},
b: {_v: true},
c: {_v: [5, 6]},
d: {_v: f}
});
});
});