-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
674 lines (610 loc) · 22 KB
/
test.js
File metadata and controls
674 lines (610 loc) · 22 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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
/**
* @name littleDiffer.js
* @author Juliet Adams and Sara Kim
* @description testing for compareJSON function
*/
const test = require('ava');
const littleDiffer = require('./lib/littleDiffer.js');
if (process.argv[2] === 'verbose') {
console.debugging = true;
}
else {
console.debugging = false;
}
console.debug("Beginning tests in test.js");
//Testing missing value a in Obj2; returns null
test('Simple Test 1', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { }
const testObj3 = { a: [{ match: false }, { a: 1 }, null] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value a in Obj1; returns null
test('Simple Test 2', (t) => {
const testObj1 = { }
const testObj2 = { a: 1 }
const testObj3 = { a: [{ match: false }, null, { a: 1 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing undefined value a in Obj2; returns { a: undefined }
test('Simple Test 3', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { a: undefined }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: undefined }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing undefined value a in Obj1; returns { a:undefined }
test('Simple Test 4', (t) => {
const testObj1 = { a: undefined }
const testObj2 = { a: 1 }
const testObj3 = { a: [{ match: false }, { a: undefined }, { a: 1 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mis-match of value a
test('Simple Test 5', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { a: 2 }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: 2 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value a in Obj2; returns null for a in Obj2
//missing value b in Obj1; returns null for b in Obj1
//undefined value b in Obj2; returns { b:undefined }
test('Simple Test 6', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { b: undefined }
const testObj3 = { a: [{ match: false }, { a: 1 }, null], b: [{ match: false }, null, { b: undefined }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value a in Obj2; returns null for a in Obj2
//missing value b in Obj1; returns null for b in Obj1
test('Simple Test 7', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { b: 1 }
const testObj3 = { a: [{ match: false }, { a: 1 }, null], b: [{ match: false }, null, { b: 1 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value b in Obj2; returns null for b in Obj2
test('Simple Test 8', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 1 }
const testObj3 = { a: [{ match: true }, { a: 1 }, { a: 1 }], b: [{ match: false }, { b: 2 }, null] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value b in Obj2; returns null for b in Obj2
//simple mis-match for value a
test('Simple Test 9', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 2 }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: 2 }], b: [{ match: false }, { b: 2 }, null] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value a in Obj2; returns null for a in Obj2
test('Simple Test 10', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { b: 2 }
const testObj3 = { a: [{ match: false }, { a: 1 }, null], b: [{ match: true }, { b: 2 }, { b: 2 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value a in Obj2; returns null for a in Obj2
//simple mis-match for value b
test('Simple Test 11', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { b: 3 }
const testObj3 = { a: [{ match: false }, { a: 1 }, null], b: [{ match: false }, { b: 2 }, { b: 3 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mis-match for value a
test('Simple Test 12', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 2, b: 2 }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: 2 }], b: [{ match: true }, { b: 2 }, { b: 2 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mis-match for value b
test('Simple Test 13', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 1, b: 3 }
const testObj3 = { a: [{ match: true }, { a: 1 }, { a: 1 }], b: [{ match: false }, { b: 2 }, { b: 3 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mis-match for values a and b
test('Simple Test 14', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 2, b: 3 }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: 2 }], b: [{ match: false }, { b: 2 }, { b: 3 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing equal values for a and b
test('Simple Test 15', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 1, b: 2 }
const testObj3 = { a: [{ match: true }, { a: 1 }, { a: 1 }], b: [{ match: true }, { b: 2 }, { b: 2 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing undefined b value in Obj2; returns { b: undefined }
test('Simple Test 16', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 1, b: undefined }
const testObj3 = { a: [{ match: true }, { a: 1 }, { a: 1 }], b: [{ match: false }, { b: 2 }, { b: undefined }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing empty string b value in Obj1; returns { b: '' }
test('Simple Test 17', (t) => {
const testObj1 = { a: 1, b: '' }
const testObj2 = { a: 1, b: 2 }
const testObj3 = { a: [{ match: true }, { a: 1 }, { a: 1 }], b: [{ match: false }, { b: '' }, { b: 2 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
test('Simple Test 18', (t) => {
const testObj1 = { a: 1, b: null}
const testObj2 = { a: 1, b: 2 }
const testObj3 = { a: [{ match: true }, { a: 1 }, { a: 1 }], b: [{ match: false }, { b: null }, { b: 2 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mis-match for value a
//undefined b value in Obj2: returns { b: undefined }
test('Simple Test 19', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 2, b: undefined }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: 2 }], b: [{ match: false }, { b: 2 }, { b: undefined }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing undefined value a in Obj1; returns { a: undefined }
//Missing values b-f in Obj2; returns null for each
test('Simple Test 20', (t) => {
const testObj1 = {
a: undefined,
b: undefined,
c: undefined,
d: undefined,
e: undefined,
f: undefined,
}
const testObj2 = { c: 1 }
const testObj3 = {
a: [{ match: false }, {
a: undefined,
},
null,
],
b: [{ match: false }, {
b: undefined,
},
null],
c: [{ match: false }, {
c: undefined,
}, {
c: 1,
}],
d: [{ match: false }, {
d: undefined,
},
null,
],
e: [{ match: false }, {
e: undefined,
},
null,
],
f: [{ match: false }, {
f: undefined,
},
null,
],
}
const result = littleDiffer.compareJSON(testObj1, testObj2)
console.debug(result);
t.deepEqual(result, testObj3)
})
//simple out of order test
test('Simple Test 21', (t) => {
const original = { a: 1, b: 2, c: 3, d: 4 }
const docA = { b:2 }
const testObj3 = {
a: [ { match:false }, null, { a:1 }],
b: [ { match:true }, { b:2 }, { b:2 }],
c: [ { match:false }, null, { c:3 }],
d: [ { match: false }, null, { d:4 }], }
const result = littleDiffer.compareJSON(docA, original)
console.debug(result);
t.deepEqual(result, testObj3)
})
//simple out of order test comparing both possible results
test('Simple Test 22', (t) => {
const original = { a: 1, b: 2, c: 3, d: 4 }
const docA = { b:2 }
const expected = {
a: [ { match:false }, { a:1 }, null ],
b: [ { match:true }, { b:2 }, { b:2 }],
c: [ { match:false }, { c:3 }, null],
d: [ { match: false }, { d:4 }, null], }
const result = littleDiffer.compareJSON(original, docA)
t.deepEqual(result, expected)
})
//Testing equal null values
test('Simple Null Test 1', (t) => {
const testObj1 = { a: null }
const testObj2 = { a: null }
const testObj3 = { a: [{match: true}, { a: null }, { a: null }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing value a is null in Obj1
test('Simple Null Test 2', (t) => {
const testObj1 = { a: null }
const testObj2 = { a: 1 }
const testObj3 = { a: [{match: false}, { a: null }, { a: 1 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing value a is null in Obj2
test('Simple Null Test 3', (t) => {
const testObj1 = { a: 'hello' }
const testObj2 = { a: null }
const testObj3 = { a: [{match: false}, { a: 'hello' }, { a: null }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing mis-match for value a containing nested val vs number
//value a is null in Obj1
//missing b value in obj1 returns as null
test('Simple Null Test 4', (t) => {
const testObj1 = { a: null }
const testObj2 = { a: { b: 3 } }
const testObj3 = { a: [{ match: false }, { a: null }, { a: { b: [{ match: false }, null, { b: 3 }] } }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing mis-match for value in obj1 containing nested value vs null in obj2
//missing b value in obj 1 returns null
//null value in obj2 returns a: null
test('Simple Null Test 5', (t) => {
const testObj1 = { a: { b: 3 } }
const testObj2 = { a: null }
const testObj3 = { a: [{ match: false }, { a: { b: [{ match: false }, { b: 3 }, null ]} },{ a: null }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing mis-match for nested value b containing null in Obj2
test('Simple Null Test 6', (t) => {
const testObj1 = { a: { b: 2 } }
const testObj2 = { a: { b: null } }
const testObj3 = { a: { b: [{ match: false }, { b: 2 }, { b: null}] } }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing mis-match for nested value b containing null in Obj1
test('Simple Null Test 7', (t) => {
const testObj1 = { a: { b: null } }
const testObj2 = { a: { b: 2 } }
const testObj3 = { a: { b: [{ match: false }, { b: null }, { b: 2}] } }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing value containing null in Obj1, but missing in Obj2
test('Simple Null Test 8', (t) => {
const testObj1 = { test8: null }
const testObj2 = { }
const testObj3 = { test8: [{ match: false }, { test8: null }, null] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing value containing null in Obj1, but missing in Obj2
test('Simple Null Test 9', (t) => {
const testObj1 = { a: null, b: 123 }
const testObj2 = { b: 123 }
const testObj3 = { a: [{ match: false }, { a: null }, null ], b: [{ match: true }, { b: 123}, { b: 123 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing nested value containing null in Obj1, but missing in Obj2
test('Simple Null Test 10', (t) => {
const testObj1 = { a: { b: null } }
const testObj2 = { a: 1 }
const testObj3 = { a: [{ match: false }, { a: { b: [{ match: false }, { b: null }, null ]}}, { a: 1 } ] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3);
})
//Testing value containing null in Obj2, but missing in Obj1
test('Simple Null Test 11', (t) => {
const testObj1 = { }
const testObj2 = { a: null }
const testObj3 = { a: [ { match: false }, null, { a: null }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing value containing null in Obj2, but missing in Obj1
test('Simple Null Test 12', (t) => {
const testObj1 = { b: 123 }
const testObj2 = { a: null, b: 123 }
const testObj3 = { a: [ { match: false }, null, { a: null }], b: [{ match: true }, { b: 123}, { b: 123 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//still need to code for this:
//Testing nested value containing null in Obj2, but missing in Obj1
//value b is null in Obj2
//missing b value in obj1 returns as null
test('Simple Null Test 13', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { a: { b: null } }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: { b: [{ match: false }, null, { b: null }] } }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing Nested values with inner most c containing mis-match.
test('Complex Test 1', (t) => {
const testObj1 = {
a: {
b: {
c: 1,
},
},
}
const testObj2 = {
a: {
b: {
c: 3,
},
},
}
const testObj3 = {
a: {
b: {
c: [{ match: false }, { c: 1 }, { c: 3 }],
},
},
}
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mis-match of value a
//mis-match of nested values
test('Complex Test 2', (t) => {
const testObj1 = {
a: 1,
b: {
a: 2,
},
}
const testObj2 = {
a: 2,
b: {
a: 1,
},
}
const testObj3 = {
a: [{ match: false }, { a: 1 }, { a: 2 }],
b: {
a: [{ match: false }, { a: 2 }, { a: 1 }],
},
}
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing nested, Value c not located inside nested value -
//value c is missing from nested a in Obj2; returns null
//Value c is missing after a in Obj1; returns null
test('Complex Test 3', (t) => {
const testObj1 = {
a: {
b: 1,
c: 2,
},
}
const testObj2 = {
a: {
b: 1,
},
c: 3,
}
const testObj3 = {
a: {
b: [{ match: true }, { b: 1 }, { b: 1 }],
c: [{ match: false }, { c: 2 }, null],
},
c: [{ match: false }, null, { c: 3 }],
}
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing mis-match for value a containing nested val vs number
//missing b value in obj2 returns as null
test('Nested Test 1', (t) => {
const testObj1 = { a: { b: 3 } }
const testObj2 = { a: 1 }
const testObj3 = { a: [{ match: false }, { a: { b: [{ match: false }, { b: 3 }, null] } }, { a: 1 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing mis-match for value a containing nest val vs number
//missing b value in obj1 returns as null
test('Nested Test 2', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { a: { b: 3 } }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: { b: [{ match: false }, null, { b: 3 }] } }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing nested equal match
test('Nested Test 3', (t) => {
const testObj1 = { a: { b: 3 } }
const testObj2 = { a: { b: 3 } }
const testObj3 = { a: { b: [{ match: true }, { b: 3 }, { b: 3 }] } }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mis-match of value b inside nested
test('Nested Test 4', (t) => {
const testObj1 = { a: { b: 3 } }
const testObj2 = { a: { b: 4 } }
const testObj3 = { a: { b: [{ match: false }, { b: 3 }, { b: 4 }] } }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing empty json returns empty json
test('Edge Test 1', (t) => {
const testObj1 = { }
const testObj2 = { }
const testObj3 = { }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple value match
test('Edge Test 2', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { a: 1 }
const testObj3 = { a: [{ match: true }, { a: 1 }, { a: 1 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple value match
test('Edge Test 4', (t) => {
const testObj1 = { a: 1, b: 2 }
const testObj2 = { a: 1, b: 2 }
const testObj3 = { a: [{ match: true }, { a: 1 }, { a: 1 }], b: [{ match: true }, { b: 2 }, { b: 2 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing value mismatch
test('String Test 1', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { a: 'hello' }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: 'hello' }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple value match
test('String Test 2', (t) => {
const testObj1 = { a: 'hello' }
const testObj2 = { a: 'hello' }
const testObj3 = { a: [{ match: true }, { a: 'hello' }, { a: 'hello' }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing value mis-match of value a containing array vs simple value
test('String Test 3', (t) => {
const testObj1 = { a: ['hello', 'goodbye'] }
const testObj2 = { a: 5 }
const testObj3 = { a: [{ match: false }, { a: ['hello', 'goodbye'] }, { a: 5 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mismatch
test('String Test 4', (t) => {
const testObj1 = { a: 'hello' }
const testObj2 = { a: 1 }
const testObj3 = { a: [{ match: false }, { a: 'hello' }, { a: 1 }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mismatch
test('String Test 5', (t) => {
const testObj1 = { a: 'hello' }
const testObj2 = { a: 'goodbye' }
const testObj3 = { a: [{ match: false }, { a: 'hello' }, { a: 'goodbye' }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing mismatch of value a containing array vs simple string value
test('String Test 6', (t) => {
const testObj1 = { a: 'hello' }
const testObj2 = { a: [5, 'goodbye'] }
const testObj3 = { a: [{ match: false }, { a: 'hello' }, { a: [5, 'goodbye'] }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing value a containing string vs nested value b containing string
//missing value b in Obj2 returns null
test('String Test 7', (t) => {
const testObj1 = { a: { b: 'hello' } }
const testObj2 = { a: 'hello' }
const testObj3 = { a: [{ match: false }, { a: { b: [{ match: false }, { b: 'hello' }, null] } }, { a: 'hello' }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mismatch value a number vs string
test('String Test 8', (t) => {
const testObj1 = { a: 1 }
const testObj2 = { a: 'hello' }
const testObj3 = { a: [{ match: false }, { a: 1 }, { a: 'hello' }] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing simple mismatch nested strings
test('String Test 9', (t) => {
const testObj1 = { a: { b: 'hello' } }
const testObj2 = { a: { b: 'goodbye' } }
const testObj3 = { a: { b: [{ match: false }, { b: 'hello' }, { b: 'goodbye' }] } }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value b in Obj2 returns null
test('String Test 10', (t) => {
const testObj1 = { a: 'hello', b: 'goodbye' }
const testObj2 = { a: 'hello' }
const testObj3 = { a: [{ match: true }, { a: 'hello' }, { a: 'hello' }], b: [{ match: false }, { b: 'goodbye' }, null] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing value b in Obj2 returns null (duplicate test)
test('String Test 11', (t) => {
const testObj1 = { a: 'hello', b: 'goodbye' }
const testObj2 = { a: 'hello' }
const testObj3 = { a: [{ match: true }, { a: 'hello' }, { a: 'hello' }], b: [{ match: false }, { b: 'goodbye' }, null] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing string value a in Obj2 returns null
test('String Test 12', (t) => {
const testObj1 = { a: 'hello' }
const testObj2 = { }
const testObj3 = { a: [{ match: false }, { a: 'hello' }, null] }
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
//Testing missing string values a-d in Obj2, returns null for each
test('String Test 13', (t) => {
const testObj1 = {
a: 'hello',
b: 'goodbye',
c: 'apple',
d: 'pear',
}
const testObj2 = {}
const testObj3 = {
a: [{ match: false }, { a: 'hello' }, null],
b: [{ match: false }, { b: 'goodbye' }, null],
c: [{ match: false }, { c: 'apple' }, null],
d: [{ match: false }, { d: 'pear' }, null],
}
const result = littleDiffer.compareJSON(testObj1, testObj2)
t.deepEqual(result, testObj3)
})
test('Match With Array Test 1', (t) => {
const nestedMatchWithArrayTest1 = { a: { b: 2, c: 3 }, j: [10, 9, 8] }
const originalNestedMatchWithArrayTest1 = { a: { b: 2, c: 3 }, j: [10, 9, 8] }
const expectedResult = {"a":{"b":[{"match":true},{"b":2},{"b":2}],"c":[{"match":true},{"c":3},{"c":3}]},"j":[{"match":true},{"j":[10,9,8]},{"j":[10,9,8]}]}
const result = littleDiffer.compareJSON(nestedMatchWithArrayTest1, originalNestedMatchWithArrayTest1)
t.deepEqual(result, expectedResult)
})