-
Notifications
You must be signed in to change notification settings - Fork 134
/
diff_test.coffee
350 lines (245 loc) · 22.6 KB
/
diff_test.coffee
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
fs = require 'fs'
Path = require 'path'
assert = require 'assert'
{ diff, diffString } = require "../#{process.env.JSLIB or 'lib'}/index"
describe 'diff', ->
describe 'with simple scalar values', ->
it "should return undefined for two identical numbers", ->
assert.deepEqual undefined, diff(42, 42)
it "should return undefined for two identical strings", ->
assert.deepEqual undefined, diff("foo", "foo")
it "should return { __old: <old value>, __new: <new value> } object for two different numbers", ->
assert.deepEqual { __old: 42, __new: 10 }, diff(42, 10)
describe 'with objects', ->
it "should return undefined for two empty objects", ->
assert.deepEqual undefined, diff({ }, { })
it "should return undefined for two objects with identical contents", ->
assert.deepEqual undefined, diff({ foo: 42, bar: 10 }, { foo: 42, bar: 10 })
it "should return undefined for two object hierarchies with identical contents", ->
assert.deepEqual undefined, diff({ foo: 42, bar: { bbbar: 10, bbboz: 11 } }, { foo: 42, bar: { bbbar: 10, bbboz: 11 } })
it "should return { <key>__deleted: <old value> } when the second object is missing a key", ->
assert.deepEqual { foo__deleted: 42 }, diff({ foo: 42, bar: 10 }, { bar: 10 })
it "should return { <key>__added: <new value> } when the first object is missing a key", ->
assert.deepEqual { foo__added: 42 }, diff({ bar: 10 }, { foo: 42, bar: 10 })
it "should return { <key>: { __old: <old value>, __new: <new value> } } for two objects with different scalar values for a key", ->
assert.deepEqual { foo: { __old: 42, __new: 10 } }, diff({ foo: 42 }, { foo: 10 })
it "should return { <key>: <diff> } with a recursive diff for two objects with different values for a key", ->
assert.deepEqual { bar: { bbboz__deleted: 11, bbbar: { __old: 10, __new: 12 } } }, diff({ foo: 42, bar: { bbbar: 10, bbboz: 11 }}, { foo: 42, bar: { bbbar: 12 }})
describe 'with arrays of scalars', ->
it "should return undefined for two arrays with identical contents", ->
assert.deepEqual undefined, diff([10, 20, 30], [10, 20, 30])
it "should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value", ->
assert.deepEqual [[' '], ['-', 20], [' ']], diff([10, 20, 30], [10, 30])
it "should return [..., ['+', <added item>], ...] for two arrays when the second one has an extra value", ->
assert.deepEqual [[' '], ['+', 20], [' ']], diff([10, 30], [10, 20, 30])
it "should return [..., ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)", ->
assert.deepEqual [[' '], [' '], ['+', 30]], diff([10, 20], [10, 20, 30])
it "should return [['-', true], ['+', 'true']] for two arrays with identical strings of different types", ->
assert.deepEqual undefined, diff([10, 20, 30], [10, 20, 30])
describe 'with arrays of objects', ->
it "should return undefined for two arrays with identical contents", ->
assert.deepEqual undefined, diff([{ foo: 10 }, { foo: 20 }, { foo: 30 }], [{ foo: 10 }, { foo: 20 }, { foo: 30 }])
it "should return undefined for two arrays with identical, empty object contents", ->
assert.deepEqual undefined, diff([{ }], [{ }])
it "should return undefined for two arrays with identical, empty array contents", ->
assert.deepEqual undefined, diff([[]], [[]])
it "should return undefined for two arrays with identical array contents including 'null'", ->
assert.deepEqual undefined, diff([1, null, null], [1, null, null])
it "should return undefined for two arrays with identical, repeated contents", ->
assert.deepEqual undefined, diff([{ a: 1, b: 2 }, { a: 1, b: 2 }], [{ a: 1, b: 2 }, { a: 1, b: 2 }])
it "should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value", ->
assert.deepEqual [[' '], ['-', { foo: 20 }], [' ']], diff([{ foo: 10 }, { foo: 20 }, { foo: 30 }], [{ foo: 10 }, { foo: 30 }])
it "should return [..., ['+', <added item>], ...] for two arrays when the second array has an extra value", ->
assert.deepEqual [[' '], ['+', { foo: 20 }], [' ']], diff([{ foo: 10 }, { foo: 30 }], [{ foo: 10 }, { foo: 20 }, { foo: 30 }])
it "should return [['+', <added item>], ..., ['+', <added item>]] for two arrays containing objects of 3 or more properties when the second array has extra values (fixes issue #57)", ->
assert.deepEqual([ [ "+", { "key1": "b", "key2": "1", "key3": "m" } ], [ " " ], [ "+", { "key1": "c", "key2": "1", "key3": "dm" } ]],
diff([ { "key1": "a", "key2": "12", "key3": "cm" } ], [ { "key1": "b", "key2": "1", "key3": "m" }, { "key1": "a", "key2": "12", "key3": "cm" }, { "key1": "c", "key2": "1", "key3": "dm" } ])
)
it "should return [..., ['+', <added item>], ...] for two arrays when the second array has a new but nearly identical object added", ->
assert.deepEqual [[' '],[ '+', { name: 'Foo', a: 3, b: 1, c: 1 }], [' ']], diff([{ "name": "Foo", "a": 3, "b": 1 },{ foo: 10 }], [{ "name": "Foo", "a": 3, "b": 1 },{ "name": "Foo", "a": 3, "b": 1, "c": 1 },{ foo: 10 }])
it "should return [..., ['~', <diff>], ...] for two arrays when an item has been modified", ->
assert.deepEqual( [[' '], ['~', { foo: { __old: 20, __new: 21 } }], [' ']],
diff([{ foo: 10, bar: { bbbar: 10, bbboz: 11 } },
{ foo: 20, bar: { bbbar: 50, bbboz: 25 } },
{ foo: 30, bar: { bbbar: 92, bbboz: 34 } }],
[{ foo: 10, bar: { bbbar: 10, bbboz: 11 } },
{ foo: 21, bar: { bbbar: 50, bbboz: 25 } },
{ foo: 30, bar: { bbbar: 92, bbboz: 34 } }])
)
describe 'with reported bugs', ->
it "should handle type mismatch during scalarize", ->
assert.deepEqual( { "s": [ [ "~", [ [ "~", { "b": { "__old": "123", "__new": "abc" } } ] ] ], [ "+", [] ] ] },
diff({"s": [[{ "b": "123" }]]}, {"s": [[{ "b": "abc" }], []]} ) )
it "should handle mixed scalars and non-scalars in scalarize", ->
assert.deepEqual( undefined,
diff(["a", {"foo": "bar"}, {"foo": "bar"}], ["a", {"foo": "bar"}, {"foo": "bar"}] ) )
describe 'diff({sort: true})', ->
describe 'with arrays', ->
it "should return undefined for two arrays with the same contents in different order", ->
assert.deepEqual undefined, diff( [1, undefined, null, true, "", {a:4}, [7, 8]], [[7, 8], {a:4}, true, null, undefined, "", 1], {sort: true})
describe 'diff({keepUnchangedValues: true})', ->
describe 'with nested object', ->
it "should return partial object with modified and unmodified elements in the edited scope", ->
assert.deepEqual { "a" : { "b" : [ [" ", 1], ["-", 2], [" ", 3], ["+", 4]] } }, diff( { "a" : { "b" : [ 1, 2, 3], "c": "d" } }, { "a" : { "b" : [ 1, 3, 4], "c": "d"} }, {keepUnchangedValues: true})
describe 'diff({full: true})', ->
describe 'with simple scalar values', ->
it "should return the number for two identical numbers", ->
assert.deepEqual 42, diff(42, 42, {full: true})
it "should return the string for two identical strings", ->
assert.deepEqual "foo", diff("foo", "foo", {full: true})
it "should return { __old: <old value>, __new: <new value> } object for two different numbers", ->
assert.deepEqual { __new: 10, __old: 42 }, diff(42, 10, {full: true})
describe 'with objects', ->
it "should return an empty object for two empty objects", ->
assert.deepEqual {}, diff({ }, { }, {full: true})
it "should return the object for two objects with identical contents", ->
assert.deepEqual { foo: 42, bar: 10 }, diff({ foo: 42, bar: 10 }, { foo: 42, bar: 10 }, {full: true})
it "should return the object for two object hierarchies with identical contents", ->
assert.deepEqual { foo: 42, bar: { bbbar: 10, bbboz: 11 } }, diff({ foo: 42, bar: { bbbar: 10, bbboz: 11 } }, { foo: 42, bar: { bbbar: 10, bbboz: 11 } }, {full: true})
it "should return { <key>__deleted: <old value>, <remaining properties>} when the second object is missing a key", ->
assert.deepEqual { foo__deleted: 42, bar: 10 }, diff({ foo: 42, bar: 10 }, { bar: 10 }, {full: true})
it "should return { <key>__added: <new value>, <remaining properties> } when the first object is missing a key", ->
assert.deepEqual { foo__added: 42, bar: 10 }, diff({ bar: 10 }, { foo: 42, bar: 10 }, {full: true})
it "should return { <key>: { __old: <old value>, __new: <new value> } } for two objects with different scalar values for a key", ->
assert.deepEqual { foo: { __old: 42, __new: 10 } }, diff({ foo: 42 }, { foo: 10 }, {full: true})
it "should return { <key>: <diff>, <equal properties> } with a recursive diff for two objects with different values for a key", ->
assert.deepEqual { foo: 42, bar: { bbbar: { __old: 10, __new: 12 } } }, diff({ foo: 42, bar: { bbbar: 10 }}, { foo: 42, bar: { bbbar: 12 }}, {full: true})
it "should return { <key>: <diff>, <equal properties> } with a recursive diff for two objects with different values for a key", ->
assert.deepEqual { foo: 42, bar: { bbboz__deleted: 11, bbbar: { __old: 10, __new: 12 } } }, diff({ foo: 42, bar: { bbbar: 10, bbboz: 11 }}, { foo: 42, bar: { bbbar: 12 }}, {full: true})
describe 'with arrays of scalars', ->
it "should return an array showing no changes for any element for two arrays with identical contents", ->
assert.deepEqual [ 10, 20, 30 ], diff([10, 20, 30], [10, 20, 30], {full: true})
it "should return [[' ', <unchanged item>], ['-', <removed item>], [' ', <unchanged item>]] for two arrays when the second array is missing a value", ->
assert.deepEqual [ [ " ", 10 ], [ "-", 20 ], [ "+", 42 ], [ " ", 30 ] ], diff([10, 20, 30], [10, 42, 30], {full: true})
it "should return [' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second one has an extra value", ->
assert.deepEqual [[' ', 10], ['+', 20], [' ', 30]], diff([10, 30], [10, 20, 30], {full: true})
it "should return [' ', <unchanged item>s], ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)", ->
assert.deepEqual [[' ', 10], [' ', 20], ['+', 30]], diff([10, 20], [10, 20, 30], {full: true})
describe 'with arrays of objects', ->
it "should return an array of unchanged elements for two arrays with identical contents", ->
assert.deepEqual [{ foo: 10 }, { foo: 20 }, { foo: 30 }], diff([{ foo: 10 }, { foo: 20 }, { foo: 30 }], [{ foo: 10 }, { foo: 20 }, { foo: 30 }], {full: true})
it "should return an array with an unchanged element for two arrays with identical, empty object contents", ->
assert.deepEqual [ {} ], diff([{ }], [{ }], {full: true})
it "should return an array with an unchanged element for two arrays with identical, empty array contents", ->
assert.deepEqual [ [] ], diff([[]], [[]], {full: true})
it "should return an array of unchanged elements for two arrays with identical array contents including 'null'", ->
assert.deepEqual [ 1, null, null ], diff([1, null, null], [1, null, null], {full: true})
it "should return an array of unchanged elements for two arrays with identical, repeated contents", ->
assert.deepEqual [ { "a": 1, "b": 2 }, { "a": 1, "b": 2 } ], diff([{ a: 1, b: 2 }, { a: 1, b: 2 }], [{ a: 1, b: 2 }, { a: 1, b: 2 }], {full: true})
it "should return [[' ', <unchanged item>], ['-', <removed item>], [' ', <unchanged item>]] for two arrays when the second array is missing a value", ->
assert.deepEqual [ [ " ", { "foo": 10 } ], [ "-", { "foo": 20 } ], [ " ", { "foo": 30 } ] ], diff([{ foo: 10 }, { foo: 20 }, { foo: 30 }], [{ foo: 10 }, { foo: 30 }], {full: true})
it "should return [[' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second array has an extra value", ->
assert.deepEqual [ [ " ", { "foo": 10 } ], [ "+", { "foo": 20 } ], [ " ", { "foo": 30 } ] ], diff([{ foo: 10 }, { foo: 30 }], [{ foo: 10 }, { foo: 20 }, { foo: 30 }], {full: true})
it "should return [[' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second array has a new but nearly identical object added", ->
assert.deepEqual [ [ " ", { "name": "Foo", "a": 3, "b": 1 } ], [ "+", { "name": "Foo", "a": 3, "b": 1, "c": 1 } ], [ " ", { "foo": 10 } ] ], diff([{ "name": "Foo", "a": 3, "b": 1 },{ "foo": 10 }], [{ "name": "Foo", "a": 3, "b": 1 },{ "name": "Foo", "a": 3, "b": 1, "c": 1 },{ "foo": 10 }], {full: true})
it "should return [[' ', <unchanged item>], ['~', <diff>], [' ', <unchanged item>]] for two arrays when an item has been modified", ->
assert.deepEqual( [ [ " ", { "foo": 10, "bar": { "bbbar": 10, "bbboz": 11 } } ],
[ "~", { "foo": { "__old": 20, "__new": 21 }, "bar": { "bbbar": 50, "bbboz": 25 } } ],
[ " ", { "foo": 30, "bar": { "bbbar": 92, "bbboz": 34 } } ] ],
diff([{ foo: 10, bar: { bbbar: 10, bbboz: 11 } },
{ foo: 20, bar: { bbbar: 50, bbboz: 25 } },
{ foo: 30, bar: { bbbar: 92, bbboz: 34 } }],
[{ foo: 10, bar: { bbbar: 10, bbboz: 11 } },
{ foo: 21, bar: { bbbar: 50, bbboz: 25 } },
{ foo: 30, bar: { bbbar: 92, bbboz: 34 } }], {full: true})
)
describe 'diff({ outputKeys: foo,bar }', ->
it "should return keys foo and bar although they have no changes", ->
assert.deepEqual { foo: 42, bar: 10, bbar__added: 5 }, diff({ foo: 42, bar: 10 }, { foo: 42, bar: 10, bbar: 5 }, {outputKeys: ["foo", "bar"]})
it "should return keys foo (with addition) and bar (with no changes) ", ->
assert.deepEqual { foo__added: 42, bar: 10, bbar__added: 5 }, diff({ bar: 10 }, { foo: 42, bar: 10, bbar: 5 }, {outputKeys: ["foo", "bar"]})
it "should return keys foo and bar (with addition) ", ->
assert.deepEqual { foo__added: 42, bar__added: 10 }, diff({ bbar: 5 }, { foo: 42, bar: 10, bbar: 5 }, {outputKeys: ["foo", "bar"]})
it "should return nothing as the entire object is equal, no matter that show keys has some of them", ->
assert.deepEqual undefined, diff({ foo: 42, bar: 10, bbar: 5 }, { foo: 42, bar: 10, bbar: 5 }, {outputKeys: ["foo", "bar"]})
it "should return the keys of an entire object although it has no changes ", ->
assert.deepEqual { foo: { a: 1, b: 2, c: [1, 2] }, bbar__added: 5 }, diff({ foo: { a: 1, b: 2, c: [1, 2] } }, { foo: { a: 1, b: 2, c: [1, 2] }, bbar: 5 }, {outputKeys: ["foo", "bar"]})
describe 'diff({ excludeKeys: foo,bar }', ->
it "shouldn't return keys foo and bar even thou they have changes", ->
assert.deepEqual { bbar__added: 5 }, diff({ foo: 42 }, { bar: 10, bbar: 5 }, excludeKeys: ["foo", "bar"])
it "shouldn't return keys foo (with addition) and bar (with no changes) ", ->
assert.deepEqual { bbar__added: 5 }, diff({ bar: 10 }, { foo: 42, bar: 10, bbar: 5 }, {excludeKeys: ["foo", "bar"]})
it "shouldn't return keys foo and bar (with addition) ", ->
assert.deepEqual undefined, diff({ bbar: 5 }, { foo: 42, bar: 10, bbar: 5 }, {excludeKeys: ["foo", "bar"]})
describe 'diff({keysOnly: true})', ->
describe 'with simple scalar values', ->
it "should return undefined for two identical numbers", ->
assert.deepEqual undefined, diff(42, 42, {keysOnly: true})
it "should return undefined for two identical strings", ->
assert.deepEqual undefined, diff("foo", "foo", {keysOnly: true})
it "should return undefined object for two different numbers", ->
assert.deepEqual undefined, diff(42, 10, {keysOnly: true})
describe 'with objects', ->
it "should return undefined for two empty objects", ->
assert.deepEqual undefined, diff({ }, { }, {keysOnly: true})
it "should return undefined for two objects with identical contents", ->
assert.deepEqual undefined, diff({ foo: 42, bar: 10 }, { foo: 42, bar: 10 }, {keysOnly: true})
it "should return undefined for two object hierarchies with identical contents", ->
assert.deepEqual undefined, diff({ foo: 42, bar: { bbbar: 10, bbboz: 11 } }, { foo: 42, bar: { bbbar: 10, bbboz: 11 } }, {keysOnly: true})
it "should return { <key>__deleted: <old value> } when the second object is missing a key", ->
assert.deepEqual { foo__deleted: 42 }, diff({ foo: 42, bar: 10 }, { bar: 10 }, {keysOnly: true})
it "should return { <key>__added: <new value> } when the first object is missing a key", ->
assert.deepEqual { foo__added: 42 }, diff({ bar: 10 }, { foo: 42, bar: 10 }, {keysOnly: true})
it "should return undefined for two objects with different scalar values for a key", ->
assert.deepEqual undefined, diff({ foo: 42 }, { foo: 10 }, {keysOnly: true})
it "should return undefined with a recursive diff for two objects with different values for a key", ->
assert.deepEqual undefined, diff({ foo: 42, bar: { bbbar: 10 }}, { foo: 42, bar: { bbbar: 12 }}, {keysOnly: true})
it "should return { <key>: <diff> } with a recursive diff when second object is missing a key and two objects with different values for a key", ->
assert.deepEqual { bar: { bbboz__deleted: 11 } }, diff({ foo: 42, bar: { bbbar: 10, bbboz: 11 }}, { foo: 42, bar: { bbbar: 12 }}, {keysOnly: true})
describe 'with arrays of scalars', ->
it "should return undefined for two arrays with identical contents", ->
assert.deepEqual undefined, diff([10, 20, 30], [10, 20, 30], {keysOnly: true})
it "should return undefined for two arrays with when an item has been modified", ->
assert.deepEqual undefined, diff([10, 20, 30], [10, 42, 30], {keysOnly: true})
it "should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value", ->
assert.deepEqual [[' '], ['-', 20], [' ']], diff([10, 20, 30], [10, 30], {keysOnly: true})
it "should return [..., ['+', <added item>], ...] for two arrays when the second one has an extra value", ->
assert.deepEqual [[' '], ['+', 20], [' ']], diff([10, 30], [10, 20, 30], {keysOnly: true})
it "should return [..., ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)", ->
assert.deepEqual [[' '], [' '], ['+', 30]], diff([10, 20], [10, 20, 30], {keysOnly: true})
describe 'with arrays of objects', ->
it "should return undefined for two arrays with identical contents", ->
assert.deepEqual undefined, diff([{ foo: 10 }, { foo: 20 }, { foo: 30 }], [{ foo: 10 }, { foo: 20 }, { foo: 30 }], {keysOnly: true})
it "should return undefined for two arrays with identical, empty object contents", ->
assert.deepEqual undefined, diff([{ }], [{ }], {keysOnly: true})
it "should return undefined for two arrays with identical, empty array contents", ->
assert.deepEqual undefined, diff([[]], [[]], {keysOnly: true})
it "should return undefined for two arrays with identical, repeated contents", ->
assert.deepEqual undefined, diff([{ a: 1, b: 2 }, { a: 1, b: 2 }], [{ a: 1, b: 2 }, { a: 1, b: 2 }], {keysOnly: true})
it "should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value", ->
assert.deepEqual [[' '], ['-', { bar: 20 }], [' ']], diff([{ foo: 10 }, { bar: 20 }, { bletch: 30 }], [{ foo: 10 }, { bletch: 30 }], {keysOnly: true})
it "should return [..., ['+', <added item>], ...] for two arrays when the second array has an extra value", ->
assert.deepEqual [[' '], ['+', { bar: 20 }], [' ']], diff([{ foo: 10 }, { bletch: 30 }], [{ foo: 10 }, { bar: 20 }, { bletch: 30 }], {keysOnly: true})
it "should return [..., ['~', <diff>], ...] for two arrays when an item has been modified", ->
assert.deepEqual undefined, diff([{ foo: 10, bar: { bbbar: 10, bbboz: 11 } }, { foo: 20, bar: { bbbar: 50, bbboz: 25 } }, { foo: 30, bar: { bbbar: 92, bbboz: 34 } }], [{ foo: 10, bar: { bbbar: 10, bbboz: 11 } }, { foo: 21, bar: { bbbar: 50, bbboz: 25 } }, { foo: 30, bar: { bbbar: 92, bbboz: 34 } }], {keysOnly: true})
describe 'diffString', ->
readExampleFile = (file) -> fs.readFileSync(Path.join(__dirname, '../example', file), 'utf8')
a = JSON.parse(readExampleFile('a.json'))
b = JSON.parse(readExampleFile('b.json'))
big_a = JSON.parse(readExampleFile('big_a.json'))
big_b = JSON.parse(readExampleFile('big_b.json'))
# Get duplicate copies for the precision test - numbers within these are altered (rounded) by the precision operation
aprec = JSON.parse(readExampleFile('a.json'))
bprec = JSON.parse(readExampleFile('b.json'))
it "should produce the expected result for the example JSON files", ->
assert.equal diffString(a, b, {color: false, full: true}), readExampleFile('full-result.jsdiff')
assert.equal diffString(big_a, big_b, {color: false, maxElisions: 5}), readExampleFile('big_result.jsdiff')
it "should produce the expected result for the example JSON files with precision set to 1", ->
assert.equal diffString(a, b, {color: false, full: true, precision: 1}), readExampleFile('full-result-precision-1.jsdiff')
it "should produce the expected colored result for the example JSON files", ->
assert.equal diffString(aprec, bprec, {color: true, full: true}), readExampleFile('full-result-colored.jsdiff')
it "return an empty string when no diff found", ->
assert.equal diffString(a, a), ''
describe 'diff({ outputNewOnly: true }', ->
it "should return only new diffs (added)", ->
assert.deepEqual { bbar: 5 }, diff({ foo: 42, bar: 10 }, { foo: 42, bar: 10, bbar: 5 }, {outputNewOnly: true})
it "should return only new diffs (changed)", ->
assert.deepEqual { foo: 13, bbar: 5 }, diff({ foo: 42, bar: 10 }, { foo: 13, bar: 10, bbar: 5 }, {outputNewOnly: true})
it "should return only new diffs (deleted)", ->
assert.deepEqual { bbar: 5 }, diff({ foo: 42, bar: 10 }, { bar: 10, bbar: 5 }, {outputNewOnly: true})
it "should return only old diffs - exchanged first and second json (added)", ->
assert.deepEqual undefined, diff({ foo: 42, bar: 10, bbar: 5 }, { foo: 42, bar: 10 }, {outputNewOnly: true})
it "should return only old diffs - exchanged first and second json (changed)", ->
assert.deepEqual { foo: 42 }, diff({ foo: 13, bar: 10, bbar: 5 }, { foo: 42, bar: 10 }, {outputNewOnly: true})
it "should return only old diffs - exchanged first and second json (deleted)", ->
assert.deepEqual { foo: 42 }, diff({ bar: 10, bbar: 5 }, { foo: 42, bar: 10 }, {outputNewOnly: true})