|
1 | 1 | /*jshint indent:2, laxcomma:true, laxbreak:true*/
|
2 |
| -var util = require('util') |
3 |
| -, expect = require('expect.js') |
4 |
| -, eql = require('deep-equal') |
5 |
| -, deep = require('..') |
6 |
| -; |
| 2 | +var util = require('util'); |
| 3 | +var expect = require('expect.js'); |
| 4 | +var deep = require('..'); |
7 | 5 |
|
8 | 6 | var lhs = {
|
9 |
| - "id": "Release", |
10 |
| - "phases": [{ |
11 |
| - "id": "Phase1", |
12 |
| - "tasks": [ |
13 |
| - {"id": "Task1"}, |
14 |
| - {"id": "Task2"} |
15 |
| - ] |
16 |
| - }, { |
17 |
| - "id": "Phase2", |
18 |
| - "tasks": [ |
19 |
| - {"id": "Task3"} |
20 |
| - ] |
21 |
| - }] |
| 7 | + 'id': 'Release', |
| 8 | + 'phases': [{ |
| 9 | + 'id': 'Phase1', |
| 10 | + 'tasks': [ |
| 11 | + { 'id': 'Task1' }, |
| 12 | + { 'id': 'Task2' } |
| 13 | + ] |
| 14 | + }, { |
| 15 | + 'id': 'Phase2', |
| 16 | + 'tasks': [ |
| 17 | + { 'id': 'Task3' } |
| 18 | + ] |
| 19 | + }] |
22 | 20 | };
|
23 | 21 | var rhs = {
|
24 |
| - "id": "Release", |
25 |
| - "phases": [{ |
26 |
| - // E: Phase1 -> Phase2 |
27 |
| - "id": "Phase2", |
28 |
| - "tasks": [ |
29 |
| - {"id": "Task3"} |
30 |
| - ] |
31 |
| - }, { |
32 |
| - "id": "Phase1", |
33 |
| - "tasks": [ |
34 |
| - {"id": "Task1"}, |
35 |
| - {"id": "Task2"} |
36 |
| - ] |
37 |
| - }] |
38 |
| - }; |
39 |
| - |
40 |
| - var diff = deep.diff(lhs, rhs); |
41 |
| - |
42 |
| - // there should be differences |
43 |
| - expect(diff).to.be.ok(); |
44 |
| - expect(diff.length).to.be(6); |
45 |
| - |
46 |
| - |
47 |
| - // It.phases[0].id changed from 'Phase1' to 'Phase2' |
48 |
| - // |
49 |
| - expect(diff[0].kind).to.be('E'); |
50 |
| - expect(diff[0].path).to.be.an('array'); |
51 |
| - expect(diff[0].path).to.have.length(3); |
52 |
| - expect(diff[0].path[0]).to.be('phases'); |
53 |
| - expect(diff[0].path[1]).to.be(0); |
54 |
| - expect(diff[0].path[2]).to.be('id'); |
55 |
| - expect(diff[0].lhs).to.be('Phase1'); |
56 |
| - expect(diff[0].rhs).to.be('Phase2'); |
57 |
| - |
58 |
| - // It.phases[0].tasks[0].id changed from 'Task1' to 'Task3' |
59 |
| - // |
60 |
| - expect(diff[1].kind).to.be('E'); |
61 |
| - expect(diff[1].path).to.be.an('array'); |
62 |
| - expect(diff[1].path).to.have.length(5); |
63 |
| - expect(diff[1].path[0]).to.be('phases'); |
64 |
| - expect(diff[1].path[1]).to.be(0); |
65 |
| - expect(diff[1].path[2]).to.be('tasks'); |
66 |
| - expect(diff[1].path[3]).to.be(0); |
67 |
| - expect(diff[1].path[4]).to.be('id'); |
68 |
| - expect(diff[1].lhs).to.be('Task1'); |
69 |
| - expect(diff[1].rhs).to.be('Task3'); |
70 |
| - |
71 |
| - // It.phases[0].tasks[1] was deleted |
72 |
| - // |
73 |
| - expect(diff[2].kind).to.be('A'); |
74 |
| - expect(diff[2].path).to.be.an('array'); |
75 |
| - expect(diff[2].path).to.have.length(3); |
76 |
| - expect(diff[2].path[0]).to.be('phases'); |
77 |
| - expect(diff[2].path[1]).to.be(0); |
78 |
| - expect(diff[2].path[2]).to.be('tasks'); |
79 |
| - expect(diff[2].index).to.be(1); |
80 |
| - expect(diff[2].item.kind).to.be('D'); |
| 22 | + 'id': 'Release', |
| 23 | + 'phases': [{ |
| 24 | + // E: Phase1 -> Phase2 |
| 25 | + 'id': 'Phase2', |
| 26 | + 'tasks': [ |
| 27 | + { 'id': 'Task3' } |
| 28 | + ] |
| 29 | + }, { |
| 30 | + 'id': 'Phase1', |
| 31 | + 'tasks': [ |
| 32 | + { 'id': 'Task1' }, |
| 33 | + { 'id': 'Task2' } |
| 34 | + ] |
| 35 | + }] |
| 36 | +}; |
81 | 37 |
|
82 |
| - // It.phases[1].id changed from 'Phase2' to 'Phase1' |
83 |
| - // |
84 |
| - expect(diff[3].kind).to.be('E'); |
85 |
| - expect(diff[3].path).to.be.an('array'); |
86 |
| - expect(diff[3].path).to.have.length(3); |
87 |
| - expect(diff[3].path[0]).to.be('phases'); |
88 |
| - expect(diff[3].path[1]).to.be(1); |
89 |
| - expect(diff[3].path[2]).to.be('id'); |
90 |
| - expect(diff[3].lhs).to.be('Phase2'); |
91 |
| - expect(diff[3].rhs).to.be('Phase1'); |
| 38 | +var diff = deep.diff(lhs, rhs); |
| 39 | +console.log(util.inspect(diff, false, 9)); // eslint-disable-line no-console |
92 | 40 |
|
93 |
| - // It.phases[1].tasks[0].id changed from 'Task3' to 'Task1' |
94 |
| - // |
95 |
| - expect(diff[4].kind).to.be('E'); |
96 |
| - expect(diff[4].path).to.be.an('array'); |
97 |
| - expect(diff[4].path).to.have.length(5); |
98 |
| - expect(diff[4].path[0]).to.be('phases'); |
99 |
| - expect(diff[4].path[1]).to.be(1); |
100 |
| - expect(diff[4].path[2]).to.be('tasks'); |
101 |
| - expect(diff[4].path[3]).to.be(0); |
102 |
| - expect(diff[4].path[4]).to.be('id'); |
103 |
| - expect(diff[4].lhs).to.be('Task3'); |
104 |
| - expect(diff[4].rhs).to.be('Task1'); |
| 41 | +deep.applyDiff(lhs, rhs); |
| 42 | +console.log(util.inspect(lhs, false, 9)); // eslint-disable-line no-console |
105 | 43 |
|
106 |
| - // It.phases[1].tasks[1] is new |
107 |
| - // |
108 |
| - expect(diff[5].kind).to.be('A'); |
109 |
| - expect(diff[5].path).to.be.an('array'); |
110 |
| - expect(diff[5].path).to.have.length(3); |
111 |
| - expect(diff[5].path[0]).to.be('phases'); |
112 |
| - expect(diff[5].path[1]).to.be(1); |
113 |
| - expect(diff[5].path[2]).to.be('tasks'); |
114 |
| - expect(diff[5].index).to.be(1); |
115 |
| - expect(diff[5].item.kind).to.be('N'); |
| 44 | +expect(lhs).to.be.eql(rhs); |
116 | 45 |
|
117 |
| - var applied = deep.applyDiff(lhs, rhs); |
0 commit comments