-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
140 lines (133 loc) · 3.06 KB
/
test.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict'
const tape = require('tape')
const suppplant = require('./')
const subject = '{we.should.all.be.friends}'
tape('nested with string', (t) => {
let stringNegative = suppplant(subject, {
somethingelse: {}
})
let stringPositive = suppplant(subject, {
we: {
should: {
all: {
be: {
friends: 'Yes'
}
}
}
}
})
t.plan(2)
t.equal(stringNegative, subject, 'Leaves string as-is')
t.equal(stringPositive, 'Yes', 'multiple level objects replacement when deepest level is string')
t.end()
})
tape('nested with number', (t) => {
let stringNegative = suppplant(subject, {
somethingelse: {}
})
let stringPositive = suppplant(subject, {
we: {
should: {
all: {
be: {
friends: 42
}
}
}
}
})
t.plan(2)
t.equal(stringNegative, subject, 'Leaves string as-is')
t.equal(stringPositive, '42', 'multiple level objects replacement when deepest level is number')
t.end()
})
tape('nested with boolean', (t) => {
let stringNegative = suppplant(subject, {
we: {
should: {
all: {
be: {
friends: true
}
}
}
}
})
let stringPositive = suppplant(subject, {
we: {
should: {
all: {
be: {
friends: true
}
}
}
}
}, {boolean: true})
t.plan(2)
t.equal(stringNegative, subject, 'Leave booleans out there in the cold')
t.equal(stringPositive, 'true', 'boolean option set to true gives love to booleans')
t.end()
})
tape('nested with stringify objects and arrays', (t) => {
let stringNegative = suppplant('{we.should}', {
we: {
should: {
all: {
be: {
friends: true
}
}
}
}
})
let stringPositive = suppplant('{we.should}', {
we: {
should: {
all: {
be: {
friends: true
}
}
}
}
}, {stringify: true})
t.plan(2)
t.equal(stringNegative, '{we.should}', 'Should not suppplant because it just... shouldn\'t')
t.equal(stringPositive, '{"all":{"be":{"friends":true}}}', 'Stringifies remainder if that\'s a type of object')
t.end()
})
tape('nested with stringify objects and arrays', (t) => {
let stringNegative = suppplant('{we.should}', {
we: {
should: {
all: {
be: {
friends: true
}
}
}
}
})
let stringNegative2 = suppplant('{we.should}', {
we: {
should: {
all: {
be: {
friends: true
}
}
}
}
}, {clear: true})
let stringPositive = suppplant('{we.should}', {
somethingelse: {}
}, {clear: true})
t.plan(3)
//d
t.equal(stringNegative, '{we.should}', 'Should not clear, because clear options wasn\'t set')
t.equal(stringNegative2, '{we.should}', 'Should not clear, because there is we.should in the data')
t.equal(stringPositive, '', 'Should clear, because clear option is set AND there is no we.should in the data')
t.end()
})