Bug 1565001 - Part 21: Use assertDeepEq to compare array objects. r=evilpie

`assertDeepEq` allows to compare arrays with nested objects, which isn't possible with `arraysEqual`.

Depends on D56936

Differential Revision: https://phabricator.services.mozilla.com/D56937

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2019-12-13 19:24:43 +00:00
parent 0613e67cfe
commit d2a19c000e
11 changed files with 42 additions and 24 deletions

View File

@ -1,6 +1,8 @@
// Parameter default values work in arrow functions
load(libdir + "asserts.js");
var f = (a=1, b=2, ...rest) => [a, b, rest];
assertEq(f().toSource(), "[1, 2, []]");
assertEq(f(0, 0).toSource(), "[0, 0, []]");
assertEq(f(0, 1, 1, 2, 3, 5).toSource(), "[0, 1, [1, 2, 3, 5]]");
assertDeepEq(f(), [1, 2, []]);
assertDeepEq(f(0, 0), [0, 0, []]);
assertDeepEq(f(0, 1, 1, 2, 3, 5), [0, 1, [1, 2, 3, 5]]);

View File

@ -1,5 +1,7 @@
// Rest parameters are allowed in arrow functions.
load(libdir + "asserts.js");
var A = (...x) => x;
assertEq(A().toSource(), "[]");
assertDeepEq(A(), []);
assertEq("" + A(3, 4, 5), "3,4,5");

View File

@ -1,5 +1,7 @@
// Rest parameters work in arrow functions
load(libdir + "asserts.js");
var f = (a, b, ...rest) => [a, b, rest];
assertEq(f().toSource(), "[(void 0), (void 0), []]");
assertEq(f(1, 2, 3, 4).toSource(), "[1, 2, [3, 4]]");
assertDeepEq(f(), [(void 0), (void 0), []]);
assertDeepEq(f(1, 2, 3, 4), [1, 2, [3, 4]]);

View File

@ -1,8 +1,10 @@
// return exits the innermost enclosing arrow (not an enclosing arrow)
load(libdir + "asserts.js");
function f() {
var g = a => [0, 1].map(x => { return x + a; });
return g(13).toSource();
return g(13);
}
assertEq(f(), "[13, 14]");
assertDeepEq(f(), [13, 14]);

View File

@ -1,4 +1,6 @@
assertEq(
load(libdir + "asserts.js");
assertDeepEq(
(function () {
var arr = [ 0, 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 ];
@ -11,5 +13,5 @@ assertEq(
}
}
return arr;
})().toSource(),
"[7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 32]");
})(),
[7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 32]);

View File

@ -13,6 +13,6 @@ assertIteratorNext(ki, "three");
assertIteratorNext(ki, "four");
assertIteratorDone(ki, undefined);
assertEq([...m.keys()].toSource(), ["one", "two", "three", "four"].toSource());
assertEq([...m.values()].toSource(), [1, 2, 3, 4].toSource());
assertEq([...m.entries()].toSource(), data.toSource());
assertDeepEq([...m.keys()], ["one", "two", "three", "four"]);
assertDeepEq([...m.values()], [1, 2, 3, 4]);
assertDeepEq([...m.entries()], data);

View File

@ -13,6 +13,6 @@ assertIteratorNext(ki, 3);
assertIteratorNext(ki, 4);
assertIteratorDone(ki, undefined);
assertEq([...s.keys()].toSource(), data.toSource());
assertEq([...s.values()].toSource(), data.toSource());
assertEq([...s.entries()].toSource(), [[1, 1], [2, 2], [3, 3], [4, 4]].toSource());
assertDeepEq([...s.keys()], data);
assertDeepEq([...s.values()], data);
assertDeepEq([...s.entries()], [[1, 1], [2, 2], [3, 3], [4, 4]]);

View File

@ -3,6 +3,8 @@
// (They're evaluated at a weird time in the generator life cycle, before the
// generator object is created.)
load(libdir + "asserts.js");
let g = newGlobal({newCompartment: true});
g.eval(`\
function f1() {} // line 1
@ -30,4 +32,4 @@ dbg.onEnterFrame = frame => {
};
g.gen(0);
assertEq(log.toSource(), [5, 7, 1, 8, 2, 9, 3, 10].toSource());
assertDeepEq(log, [5, 7, 1, 8, 2, 9, 3, 10]);

View File

@ -1,6 +1,8 @@
// When resuming a generator triggers one Debugger's onEnterFrame handler,
// all Debuggers' Debugger.Frames become usable at once.
load(libdir + "asserts.js");
let g = newGlobal({newCompartment: true});
g.eval(`
function* f() {
@ -29,4 +31,4 @@ dbg1.onEnterFrame = frame => {
let values = [...g.f()];
assertEq(hits, 2);
assertEq(values.toSource(), "[1]");
assertDeepEq(values, [1]);

View File

@ -3,6 +3,8 @@
* http://creativecommons.org/licenses/publicdomain/
*/
load(libdir + "asserts.js");
var map = new Map();
map.set("self", map);
@ -33,8 +35,8 @@ for (value of magic) {
assertEq(value[0], values[i++]);
}
assertEq([...map.keys()].toSource(), [...magic.keys()].toSource());
assertEq([...map.values()].toSource(), [...magic.values()].toSource());
assertDeepEq([...map.keys()], [...magic.keys()]);
assertDeepEq([...map.values()], [...magic.values()]);
var obj = {a: 1};
obj.map = new Map();
@ -56,7 +58,7 @@ assertEq(magic.get("a").valueOf(), 1);
assertEq(magic.get("b").valueOf(), "aaaa");
assertEq(magic.get("c").valueOf(), NaN);
assertEq([...magic.keys()].toSource(), ["a", "b", "c"].toSource());
assertDeepEq([...map.keys()], ["a", "b", "c"]);
map = new Map();
map.set("x", new Map());

View File

@ -3,6 +3,8 @@
* http://creativecommons.org/licenses/publicdomain/
*/
load(libdir + "asserts.js");
var set = new Set();
set.add(set);
@ -25,8 +27,8 @@ for (value of magic) {
assertEq(value, values[i++]);
}
assertEq([...set.keys()].toSource(), [...magic.keys()].toSource());
assertEq([...set.values()].toSource(), [...magic.values()].toSource());
assertDeepEq([...set.keys()], [...magic.keys()]);
assertDeepEq([...set.values()], [...magic.values()]);
var obj = {a: 1};
obj.set = new Set();