|
1 _("Make sure Utils.deepEquals correctly finds items that are deeply equal"); |
|
2 Cu.import("resource://services-sync/util.js"); |
|
3 |
|
4 function run_test() { |
|
5 let data = '[NaN, undefined, null, true, false, Infinity, 0, 1, "a", "b", {a: 1}, {a: "a"}, [{a: 1}], [{a: true}], {a: 1, b: 2}, [1, 2], [1, 2, 3]]'; |
|
6 _("Generating two copies of data:", data); |
|
7 let d1 = eval(data); |
|
8 let d2 = eval(data); |
|
9 |
|
10 d1.forEach(function(a) { |
|
11 _("Testing", a, typeof a, JSON.stringify([a])); |
|
12 let numMatch = 0; |
|
13 |
|
14 d2.forEach(function(b) { |
|
15 if (Utils.deepEquals(a, b)) { |
|
16 numMatch++; |
|
17 _("Found a match", b, typeof b, JSON.stringify([b])); |
|
18 } |
|
19 }); |
|
20 |
|
21 let expect = 1; |
|
22 if (isNaN(a) && typeof a == "number") { |
|
23 expect = 0; |
|
24 _("Checking NaN should result in no matches"); |
|
25 } |
|
26 |
|
27 _("Making sure we found the correct # match:", expect); |
|
28 _("Actual matches:", numMatch); |
|
29 do_check_eq(numMatch, expect); |
|
30 }); |
|
31 |
|
32 _("Make sure adding undefined properties doesn't affect equalness"); |
|
33 let a = {}; |
|
34 let b = { a: undefined }; |
|
35 do_check_true(Utils.deepEquals(a, b)); |
|
36 a.b = 5; |
|
37 do_check_false(Utils.deepEquals(a, b)); |
|
38 b.b = 5; |
|
39 do_check_true(Utils.deepEquals(a, b)); |
|
40 a.c = undefined; |
|
41 do_check_true(Utils.deepEquals(a, b)); |
|
42 b.d = undefined; |
|
43 do_check_true(Utils.deepEquals(a, b)); |
|
44 } |