-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.js
93 lines (80 loc) · 1.88 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
var obj, compiled;
function standardCheck(obj1, obj2, diffres){
console.log(JSON.stringify(diffres));
var obj3 = JSON.parse(JSON.stringify(obj1));
try{
jsonpatch.apply(obj3, diffres);
}catch(e){
console.log(e);
ok(false,e);
}
deepEqual(obj2,obj3)
}
// QUnit
test('simple replace', function() {
var obj1 = [ 1 ];
var obj2 = [ 2 ];
var diffres = jsondiff.diff(obj1, obj2);
deepEqual(diffres, [ {
"op" : "replace",
"path" : "/0",
"value" : 2
} ]);
standardCheck(obj1, obj2, diffres)
});
test('object add', function() {
var obj1 = [ { a : 1 } ];
var obj2 = [ { a : 1 }, { b : 2 } ];
var diffres = jsondiff.diff(obj1, obj2);
deepEqual(diffres, [ {
"op" : "add",
"path" : "/1",
"value" : {
"b" : 2
}
} ]);
standardCheck(obj1, obj2, diffres)
});
test('object remove', function() {
var obj1 = [ { a : 1 }, { b : 2 } ];
var obj2 = [ { a : 1 } ];
var diffres = jsondiff.diff(obj1, obj2);
deepEqual(diffres, [ {
"op" : "remove",
"path" : "/1"
} ]);
standardCheck(obj1, obj2, diffres)
});
test('object remove and add', function() {
var obj1 = [ { a : 1 } ];
var obj2 = [ { b : 2 } ];
var diffres = jsondiff.diff(obj1, obj2);
deepEqual(diffres, [ {
"op" : "add",
"path" : "/0/b",
"value" : 2
}, {
"op" : "remove",
"path" : "/0/a"
} ]);
standardCheck(obj1, obj2, diffres)
});
test('simple move', function() {
var obj1 = [ { a : 1 } ];
var obj2 = [ { b : 1 } ];
var diffres = jsondiff.diff(obj1, obj2);
deepEqual(diffres, [ {
"op": "move",
"from": "/0/a",
"path": "/0/b"
} ]);
standardCheck(obj1, obj2, diffres)
});
test('complex move', function() {
var obj1 = [ "thing", [1,2,3]];
var obj2 = [ "thing", {a:1}, [1,2,3]];
var diffres = jsondiff.diff(obj1, obj2, false);
//expect(0);
deepEqual(diffres,[]);
standardCheck(obj1, obj2, diffres)
});