Skip to content

Commit

Permalink
test: clean up some assert deepEqual tests
Browse files Browse the repository at this point in the history
PR-URL: #14491
Fixes: #14441
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
BridgeAR authored and jasnell committed Sep 25, 2017
1 parent 8eeaba6 commit b122714
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 66 deletions.
62 changes: 52 additions & 10 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,17 @@ assertNotDeepOrStrict(new Set([1, 2, 3, 4]), new Set([1, 2, 3]));
assertDeepAndStrictEqual(new Set(['1', '2', '3']), new Set(['1', '2', '3']));
assertDeepAndStrictEqual(new Set([[1, 2], [3, 4]]), new Set([[3, 4], [1, 2]]));

const a = [ 1, 2 ];
const b = [ 3, 4 ];
const c = [ 1, 2 ];
const d = [ 3, 4 ];

assertDeepAndStrictEqual(
{ a: a, b: b, s: new Set([a, b]) },
{ a: c, b: d, s: new Set([d, c]) }
);
{
const a = [ 1, 2 ];
const b = [ 3, 4 ];
const c = [ 1, 2 ];
const d = [ 3, 4 ];

assertDeepAndStrictEqual(
{ a: a, b: b, s: new Set([a, b]) },
{ a: c, b: d, s: new Set([d, c]) }
);
}

assertDeepAndStrictEqual(new Map([[1, 1], [2, 2]]), new Map([[1, 1], [2, 2]]));
assertDeepAndStrictEqual(new Map([[1, 1], [2, 2]]), new Map([[2, 2], [1, 1]]));
Expand Down Expand Up @@ -303,7 +305,26 @@ assertOnlyDeepEqual(
new Set([undefined])
);

// Circular structures
// GH-6416. Make sure circular refs don't throw.
{
const b = {};
b.b = b;
const c = {};
c.b = c;

assertDeepAndStrictEqual(b, c);

const d = {};
d.a = 1;
d.b = d;
const e = {};
e.a = 1;
e.b = {};

assertNotDeepOrStrict(d, e);
}

// GH-14441. Circular structures should be consistent
{
const a = {};
const b = {};
Expand All @@ -323,6 +344,27 @@ assertOnlyDeepEqual(
assertDeepAndStrictEqual(b, c);
}

// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
{
const args = (function() { return arguments; })();
assertNotDeepOrStrict([], args);
}

// More checking that arguments objects are handled correctly
{
// eslint-disable-next-line func-style
const returnArguments = function() { return arguments; };

const someArgs = returnArguments('a');
const sameArgs = returnArguments('a');
const diffArgs = returnArguments('b');

assertNotDeepOrStrict(someArgs, ['a']);
assertNotDeepOrStrict(someArgs, { '0': 'a' });
assertNotDeepOrStrict(someArgs, diffArgs);
assertDeepAndStrictEqual(someArgs, sameArgs);
}

{
const values = [
123,
Expand Down
56 changes: 0 additions & 56 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,62 +518,6 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
assert.ok(threw);
}

// https://github.com/nodejs/node/issues/6416
// Make sure circular refs don't throw.
{
const b = {};
b.b = b;

const c = {};
c.b = c;

a.doesNotThrow(makeBlock(a.deepEqual, b, c));
a.doesNotThrow(makeBlock(a.deepStrictEqual, b, c));

const d = {};
d.a = 1;
d.b = d;

const e = {};
e.a = 1;
e.b = e.a;

a.throws(makeBlock(a.deepEqual, d, e), /AssertionError/);
a.throws(makeBlock(a.deepStrictEqual, d, e), /AssertionError/);

// https://github.com/nodejs/node/issues/13314
const f = {};
f.ref = f;

const g = {};
g.ref = g;

const h = { ref: g };

a.doesNotThrow(makeBlock(a.deepEqual, f, h));
a.doesNotThrow(makeBlock(a.deepStrictEqual, f, h));
}
// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
const args = (function() { return arguments; })();
a.throws(makeBlock(a.deepEqual, [], args));
a.throws(makeBlock(a.deepEqual, args, []));

// more checking that arguments objects are handled correctly
{
// eslint-disable-next-line func-style
const returnArguments = function() { return arguments; };

const someArgs = returnArguments('a');
const sameArgs = returnArguments('a');
const diffArgs = returnArguments('b');

a.throws(makeBlock(a.deepEqual, someArgs, ['a']));
a.throws(makeBlock(a.deepEqual, ['a'], someArgs));
a.throws(makeBlock(a.deepEqual, someArgs, { '0': 'a' }));
a.throws(makeBlock(a.deepEqual, someArgs, diffArgs));
a.doesNotThrow(makeBlock(a.deepEqual, someArgs, sameArgs));
}

// check messages from assert.throws()
{
const noop = () => {};
Expand Down

0 comments on commit b122714

Please sign in to comment.