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