test: add block scoping to test-assert-deep

Add block scoping to test-assert-deep.js to reduce likelihood of one
test case having side effects that affect another test case.

PR-URL: https://github.com/nodejs/node/pull/16532
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
This commit is contained in:
Rich Trott 2017-10-26 15:30:04 -07:00 committed by Tobias Nießen
parent 403ccb68a5
commit 203b548381
No known key found for this signature in database
GPG Key ID: 718207F8FD156B70

View File

@ -34,18 +34,22 @@ assert.throws(() => assert.deepStrictEqual(arr, buf),
re`${arr} deepStrictEqual ${buf}`); re`${arr} deepStrictEqual ${buf}`);
assert.doesNotThrow(() => assert.deepEqual(arr, buf)); assert.doesNotThrow(() => assert.deepEqual(arr, buf));
const buf2 = Buffer.from(arr); {
buf2.prop = 1; const buf2 = Buffer.from(arr);
buf2.prop = 1;
assert.throws(() => assert.deepStrictEqual(buf2, buf), assert.throws(() => assert.deepStrictEqual(buf2, buf),
re`${buf2} deepStrictEqual ${buf}`); re`${buf2} deepStrictEqual ${buf}`);
assert.doesNotThrow(() => assert.deepEqual(buf2, buf)); assert.doesNotThrow(() => assert.deepEqual(buf2, buf));
}
const arr2 = new Uint8Array([120, 121, 122, 10]); {
arr2.prop = 5; const arr2 = new Uint8Array([120, 121, 122, 10]);
assert.throws(() => assert.deepStrictEqual(arr, arr2), arr2.prop = 5;
re`${arr} deepStrictEqual ${arr2}`); assert.throws(() => assert.deepStrictEqual(arr, arr2),
assert.doesNotThrow(() => assert.deepEqual(arr, arr2)); re`${arr} deepStrictEqual ${arr2}`);
assert.doesNotThrow(() => assert.deepEqual(arr, arr2));
}
const date = new Date('2016'); const date = new Date('2016');
@ -85,31 +89,33 @@ assert.throws(() => assert.deepStrictEqual(re1, re2),
// For these weird cases, deepEqual should pass (at least for now), // For these weird cases, deepEqual should pass (at least for now),
// but deepStrictEqual should throw. // but deepStrictEqual should throw.
const similar = new Set([ {
{ 0: '1' }, // Object const similar = new Set([
{ 0: 1 }, // Object { 0: '1' }, // Object
new String('1'), // Object { 0: 1 }, // Object
['1'], // Array new String('1'), // Object
[1], // Array ['1'], // Array
date2, // Date with this[0] = '1' [1], // Array
re2, // RegExp with this[0] = '1' date2, // Date with this[0] = '1'
new Int8Array([1]), // Int8Array re2, // RegExp with this[0] = '1'
new Uint8Array([1]), // Uint8Array new Int8Array([1]), // Int8Array
new Int16Array([1]), // Int16Array new Uint8Array([1]), // Uint8Array
new Uint16Array([1]), // Uint16Array new Int16Array([1]), // Int16Array
new Int32Array([1]), // Int32Array new Uint16Array([1]), // Uint16Array
new Uint32Array([1]), // Uint32Array new Int32Array([1]), // Int32Array
Buffer.from([1]), new Uint32Array([1]), // Uint32Array
// Arguments {'0': '1'} is not here Buffer.from([1]),
// See https://github.com/nodejs/node-v0.x-archive/pull/7178 // Arguments {'0': '1'} is not here
]); // See https://github.com/nodejs/node-v0.x-archive/pull/7178
]);
for (const a of similar) { for (const a of similar) {
for (const b of similar) { for (const b of similar) {
if (a !== b) { if (a !== b) {
assert.deepEqual(a, b); assert.deepEqual(a, b);
assert.throws(() => assert.deepStrictEqual(a, b), assert.throws(() => assert.deepStrictEqual(a, b),
re`${a} deepStrictEqual ${b}`); re`${a} deepStrictEqual ${b}`);
}
} }
} }
} }