Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 _("Make sure Utils.deepEquals correctly finds items that are deeply equal");
2 Cu.import("resource://services-sync/util.js");
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);
10 d1.forEach(function(a) {
11 _("Testing", a, typeof a, JSON.stringify([a]));
12 let numMatch = 0;
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 });
21 let expect = 1;
22 if (isNaN(a) && typeof a == "number") {
23 expect = 0;
24 _("Checking NaN should result in no matches");
25 }
27 _("Making sure we found the correct # match:", expect);
28 _("Actual matches:", numMatch);
29 do_check_eq(numMatch, expect);
30 });
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 }