test: improve util inspect tests

Remove unnecessary code parts and outdated code

PR-URL: https://github.com/nodejs/node/pull/14881
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Ruben Bridgewater 2017-09-08 22:48:40 -03:00
parent bac313b086
commit e3f4305c25
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -243,32 +243,21 @@ for (const showHidden of [true, false]) {
); );
}); });
// Due to the hash seed randomization it's not deterministic the order that assert.strictEqual(
// the following ways this hash is displayed. util.inspect(Object.create({}, {
// See http://codereview.chromium.org/9124004/
{
const out = util.inspect(Object.create({}, {
visible: { value: 1, enumerable: true }, visible: { value: 1, enumerable: true },
hidden: { value: 2 } hidden: { value: 2 }
}), true); }), { showHidden: true }),
if (out !== '{ [hidden]: 2, visible: 1 }' && '{ visible: 1, [hidden]: 2 }'
out !== '{ visible: 1, [hidden]: 2 }') { );
assert.fail(`unexpected value for out ${out}`);
}
}
// Objects without prototype // Objects without prototype
{ assert.strictEqual(
const out = util.inspect(Object.create(null, { util.inspect(Object.create(null, {
name: { value: 'Tim', enumerable: true }, name: { value: 'Tim', enumerable: true },
hidden: { value: 'secret' } hidden: { value: 'secret' }
}), true); }), { showHidden: true }),
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" && "{ name: 'Tim', [hidden]: 'secret' }"
out !== "{ name: 'Tim', [hidden]: 'secret' }") { );
assert.fail(`unexpected value for out ${out}`);
}
}
assert.strictEqual( assert.strictEqual(
util.inspect(Object.create(null, { util.inspect(Object.create(null, {
@ -278,7 +267,6 @@ assert.strictEqual(
'{ name: \'Tim\' }' '{ name: \'Tim\' }'
); );
// Dynamic properties // Dynamic properties
{ {
assert.strictEqual( assert.strictEqual(
@ -1061,19 +1049,11 @@ if (typeof Symbol !== 'undefined') {
{ {
const x = new Array(101).fill(); const x = new Array(101).fill();
assert(util.inspect(x).endsWith('1 more item ]')); assert(util.inspect(x).endsWith('1 more item ]'));
}
{
const x = new Array(101).fill();
assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]')); assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]'));
assert.strictEqual( assert.strictEqual(
util.inspect(x, { maxArrayLength: -1 }), util.inspect(x, { maxArrayLength: -1 }),
'[ ... 101 more items ]' '[ ... 101 more items ]'
); );
}
{
const x = new Array(101).fill();
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }), assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
'[ ... 101 more items ]'); '[ ... 101 more items ]');
} }
@ -1082,46 +1062,20 @@ if (typeof Symbol !== 'undefined') {
const x = Array(101); const x = Array(101);
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }), assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
'[ ... 101 more items ]'); '[ ... 101 more items ]');
assert(!util.inspect(x, { maxArrayLength: null }).endsWith('1 more item ]'));
assert(!util.inspect(
x, { maxArrayLength: Infinity }
).endsWith('1 more item ]'));
} }
{ {
const x = new Uint8Array(101); const x = new Uint8Array(101);
assert(util.inspect(x).endsWith('1 more item ]')); assert(util.inspect(x).endsWith('1 more item ]'));
}
{
const x = new Uint8Array(101);
assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]')); assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]'));
}
{
const x = new Uint8Array(101);
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }), assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
'Uint8Array [ ... 101 more items ]'); 'Uint8Array [ ... 101 more items ]');
}
{
const x = Array(101);
assert(!util.inspect(x, { maxArrayLength: null }).endsWith('1 more item ]')); assert(!util.inspect(x, { maxArrayLength: null }).endsWith('1 more item ]'));
} assert(util.inspect(x, { maxArrayLength: Infinity }).endsWith(' 0 ]'));
{
const x = Array(101);
assert(!util.inspect(
x, { maxArrayLength: Infinity }
).endsWith('1 more item ]'));
}
{
const x = new Uint8Array(101);
assert(!util.inspect(x, { maxArrayLength: null }).endsWith('1 more item ]'));
}
{
const x = new Uint8Array(101);
assert(!util.inspect(
x, { maxArrayLength: Infinity }
).endsWith('1 more item ]'));
} }
{ {