michael@0: _("Make sure Utils.deepEquals correctly finds items that are deeply equal"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: michael@0: function run_test() { michael@0: 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]]'; michael@0: _("Generating two copies of data:", data); michael@0: let d1 = eval(data); michael@0: let d2 = eval(data); michael@0: michael@0: d1.forEach(function(a) { michael@0: _("Testing", a, typeof a, JSON.stringify([a])); michael@0: let numMatch = 0; michael@0: michael@0: d2.forEach(function(b) { michael@0: if (Utils.deepEquals(a, b)) { michael@0: numMatch++; michael@0: _("Found a match", b, typeof b, JSON.stringify([b])); michael@0: } michael@0: }); michael@0: michael@0: let expect = 1; michael@0: if (isNaN(a) && typeof a == "number") { michael@0: expect = 0; michael@0: _("Checking NaN should result in no matches"); michael@0: } michael@0: michael@0: _("Making sure we found the correct # match:", expect); michael@0: _("Actual matches:", numMatch); michael@0: do_check_eq(numMatch, expect); michael@0: }); michael@0: michael@0: _("Make sure adding undefined properties doesn't affect equalness"); michael@0: let a = {}; michael@0: let b = { a: undefined }; michael@0: do_check_true(Utils.deepEquals(a, b)); michael@0: a.b = 5; michael@0: do_check_false(Utils.deepEquals(a, b)); michael@0: b.b = 5; michael@0: do_check_true(Utils.deepEquals(a, b)); michael@0: a.c = undefined; michael@0: do_check_true(Utils.deepEquals(a, b)); michael@0: b.d = undefined; michael@0: do_check_true(Utils.deepEquals(a, b)); michael@0: }