Skip to content

Commit

Permalink
test: improve util inspect tests
Browse files Browse the repository at this point in the history
Remove unnecessary code parts and outdated code

PR-URL: #14881
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
BridgeAR authored and jasnell committed Sep 21, 2017
1 parent 5b47f84 commit 93c08b0
Showing 1 changed file with 19 additions and 76 deletions.
95 changes: 19 additions & 76 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,43 +235,21 @@ for (const showHidden of [true, false]) {
);
});

// Due to the hash seed randomization it's not deterministic the order that
// the following ways this hash is displayed.
// See http://codereview.chromium.org/9124004/

{
const out =
util.inspect(
Object.create(
{},
{ visible: { value: 1, enumerable: true }, hidden: { value: 2 } }
),
true
);
if (out !== '{ [hidden]: 2, visible: 1 }' &&
out !== '{ visible: 1, [hidden]: 2 }') {
assert.fail(`unexpected value for out ${out}`);
}
}

assert.strictEqual(
util.inspect(Object.create({}, {
visible: { value: 1, enumerable: true },
hidden: { value: 2 }
}), { showHidden: true }),
'{ visible: 1, [hidden]: 2 }'
);
// Objects without prototype
{
const out =
util.inspect(Object.create(null,
{
name: {
value: 'Tim',
enumerable: true
},
hidden: {
value: 'secret'
}
}), true);
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
assert.fail(`unexpected value for out ${out}`);
}
}
assert.strictEqual(
util.inspect(Object.create(null, {
name: { value: 'Tim', enumerable: true },
hidden: { value: 'secret' }
}), { showHidden: true }),
"{ name: 'Tim', [hidden]: 'secret' }"
);

assert.strictEqual(
util.inspect(Object.create(null,
Expand All @@ -280,7 +258,6 @@ assert.strictEqual(
'{ name: \'Tim\' }'
);


// Dynamic properties
{
assert.strictEqual(util.inspect({ get readonly() {} }),
Expand Down Expand Up @@ -1061,19 +1038,11 @@ if (typeof Symbol !== 'undefined') {
{
const x = new Array(101).fill();
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.strictEqual(
util.inspect(x, { maxArrayLength: -1 }),
'[ ... 101 more items ]'
);
}

{
const x = new Array(101).fill();
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
'[ ... 101 more items ]');
}
Expand All @@ -1082,46 +1051,20 @@ if (typeof Symbol !== 'undefined') {
const x = Array(101);
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
'[ ... 101 more items ]');
}

{
const x = new Uint8Array(101);
assert(util.inspect(x).endsWith('1 more item ]'));
}

{
const x = new Uint8Array(101);
assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]'));
}

{
const x = new Uint8Array(101);
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
'Uint8Array [ ... 101 more items ]');
}

{
const x = Array(101);
assert(!util.inspect(x, { maxArrayLength: null }).endsWith('1 more item ]'));
}

{
const x = Array(101);
assert(!util.inspect(
x, { maxArrayLength: Infinity }
).endsWith('1 more item ]'));
}

{
const x = new Uint8Array(101);
assert(util.inspect(x).endsWith('1 more item ]'));
assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]'));
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
'Uint8Array [ ... 101 more items ]');
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 ]'));
assert(util.inspect(x, { maxArrayLength: Infinity }).endsWith(' 0 ]'));
}

{
Expand Down

0 comments on commit 93c08b0

Please sign in to comment.