-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
61 lines (49 loc) · 1.43 KB
/
Copy pathexample.js
File metadata and controls
61 lines (49 loc) · 1.43 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
const picklify = require('./picklify');
const assert = require('assert');
let sharedObj = {'nested': {'nested': {'morenested': 'value'}}};
let sharedArray = [1.2, 2, 3, 4, 5, 6];
class A {
constructor() {
this.n = 10,
this.config = {
'a': 1,
'b': null,
'c': sharedArray,
'sharedObj': sharedObj,
};
this.b= new B(this);
this.sharedArray = sharedArray;
}
}
class B {
constructor(a) {
this.aaa = 'asdasd';
this.a = a;
this.sharedArray = sharedArray;
this.sharedObj = sharedObj;
}
}
class Base {
constructor() {
this.base = 'base';
}
}
class C extends Base {
constructor(a) {
super();
this.a = a;
}
}
let originalRoot = new A();
originalRoot.c = new C();
originalRoot.c.b = new B(originalRoot);
let serializedRoot = picklify.picklify(originalRoot);
let recoveredRoot = picklify.unpicklify(serializedRoot, [A, B, C]);
assert.equal(recoveredRoot.b.a, recoveredRoot);
assert.equal(recoveredRoot.config.sharedObj, recoveredRoot.b.sharedObj);
assert.equal(recoveredRoot.config.b, null);
assert.equal(recoveredRoot.sharedArray, recoveredRoot.b.sharedArray);
assert.equal(recoveredRoot.sharedArray.length, originalRoot.sharedArray.length);
assert.notEqual(recoveredRoot.c.b, recoveredRoot.b);
assert.equal(recoveredRoot.c.b.a, recoveredRoot);
assert.equal(recoveredRoot.c.base, 'base');