-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
219 lines (174 loc) · 4.64 KB
/
Copy pathtest.js
File metadata and controls
219 lines (174 loc) · 4.64 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
var Pointer = require('./');
describe('.Pointer', function() {
// Get new object for each test
var o;
beforeEach(function() {
o = {};
});
describe('constructor()', function() {
it('Should bridge setRoot',function(done) {
var fx = Pointer.prototype.setRoot;
Pointer.prototype.setRoot = function() {
Pointer.prototype.setRoot = fx;
done();
};
new Pointer();
});
});
describe('setRoot()', function() {
it('Should set new root object', function() {
var p = new Pointer({});
var newObj = {};
p.setRoot(newObj);
p._root.should.equal(newObj);
p._loc.should.eql([]);
p._pointerRoot.should.eql({});
});
it('Should set new root object with location', function() {
var newObj = {};
var p = new Pointer(newObj, ['test']);
p._root.should.equal(newObj);
p._loc.should.eql(['test']);
(p._pointerRoot === undefined).should.be.true;
var o2 = {test: {}};
p.setRoot(o2, ['test']);
p._root.should.equal(o2);
p._loc.should.eql(['test']);
p._pointerRoot.should.equal(o2.test);
});
it.skip('Should hook to root pointer changes', function() {
});
it.skip('Should unhook previous root pointer', function() {
});
});
describe('getRoot()', function() {
it('Should get the root', function() {
var newObj = {};
var p1 = new Pointer(newObj);
var p2 = new Pointer(p1);
p2.getRoot().should.eql(newObj);
});
});
describe('setLocation()', function() {
});
describe('getLocationObject()', function() {
});
describe('create()', function() {
var o, p;
beforeEach(function() {
o = {};
p = new Pointer(o, ['test']);
});
it('Should return a new object', function() {
var r = p.create(['location']);
r.should.eql({});
o.should.eql({test:{location:{}}});
});
});
describe('set()', function() {
var o, p;
beforeEach(function() {
o = {};
p = new Pointer(o, ['test']);
});
it('Should set a value', function() {
p.set('test', 'testValue');
o.should.eql({
test: {
test:'testValue'
}
});
});
it('Should set a nested value', function() {
p.set(['test', 'nested'], 'testValue');
o.should.eql({
test: {
test: {
nested: 'testValue'
}
}
});
});
});
describe('get()', function() {
var o, p;
beforeEach(function() {
o = {};
p = new Pointer(o, ['test']);
});
it('Should return undefined', function() {
(p.get('test') === undefined).should.be.true;
});
it('Should return default value', function() {
p.get('test', 'default').should.equal('default');
});
it('Should return the value', function() {
p.set('t', 'test');
p.set(['test', 't'], 'test');
p.get('t').should.equal('test');
p.get(['test', 't']).should.equal('test');
});
});
describe('clear()', function() {
var o, p;
beforeEach(function() {
o = {
dummy:{
data: {
key: true
}
}
};
p = new Pointer(o);
});
it('Should delete the location', function() {
p.clear('dummy');
o.should.eql({});
});
it('Should delete the nested location', function() {
p.clear(['dummy', 'data']);
o.should.eql({});
p.set('data', 'test');
o.should.eql({data: 'test'})
p.clear('data');
o.should.eql({});
});
});
describe('Pointer Root', function() {
var obj = {};
var op = new Pointer(obj);
var np = new Pointer(op, 'test');
it('Should have the pointer set as root', function() {
np._root.should.equal(op);
np._loc.should.eql(['test']);
np._masterPointer.should.be.true;
(np._pointerRoot === undefined).should.be.true;
});
it('Should return undefined when retrieving pointer root', function() {
(np.getLocationObject() === undefined).should.be.true;
});
it('Should return the actual object when retrieving pointer root', function() {
np.getLocationObject(true).should.eql({});
});
it('Should hook to pointer modifications', function() {
var o = {};
op.setRoot(o);
np.set('test', 'test');
o.should.eql({
test: {
test: 'test'
}
})
});
it('Should unhook to pointer modifications', function() {
op.setRoot({});
np.setRoot({});
np.set('test', 'non test');
// from previous test
op._root.should.eql({});
np._root.should.eql({
test: 'non test'
})
});
});
});