Skip to content

Commit 7dc0905

Browse files
Trottrvagg
authored andcommitted
test: fix redeclared test-util-* vars
PR-URL: #4994 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Klauke <[email protected]>
1 parent 53e7d60 commit 7dc0905

File tree

1 file changed

+119
-101
lines changed

1 file changed

+119
-101
lines changed

test/parallel/test-util-inspect.js

+119-101
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,26 @@ assert.equal(util.inspect(Object.create({},
4545
// the following ways this hash is displayed.
4646
// See http://codereview.chromium.org/9124004/
4747

48-
var out = util.inspect(Object.create({},
49-
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
50-
if (out !== '{ [hidden]: 2, visible: 1 }' &&
51-
out !== '{ visible: 1, [hidden]: 2 }') {
52-
assert.ok(false);
48+
{
49+
const out = util.inspect(Object.create({},
50+
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
51+
if (out !== '{ [hidden]: 2, visible: 1 }' &&
52+
out !== '{ visible: 1, [hidden]: 2 }') {
53+
assert.ok(false);
54+
}
5355
}
5456

55-
5657
// Objects without prototype
57-
var out = util.inspect(Object.create(null,
58-
{ name: {value: 'Tim', enumerable: true},
59-
hidden: {value: 'secret'}}), true);
60-
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
61-
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
62-
assert(false);
58+
{
59+
const out = util.inspect(Object.create(null,
60+
{ name: {value: 'Tim', enumerable: true},
61+
hidden: {value: 'secret'}}), true);
62+
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
63+
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
64+
assert(false);
65+
}
6366
}
6467

65-
6668
assert.equal(
6769
util.inspect(Object.create(null,
6870
{name: {value: 'Tim', enumerable: true},
@@ -129,17 +131,19 @@ assert.equal(util.inspect(a, true), '[ \'foo\', , \'baz\', [length]: 3 ]');
129131
assert.equal(util.inspect(new Array(5)), '[ , , , , ]');
130132

131133
// test for Array constructor in different context
132-
const Debug = require('vm').runInDebugContext('Debug');
133-
var map = new Map();
134-
map.set(1, 2);
135-
var mirror = Debug.MakeMirror(map.entries(), true);
136-
var vals = mirror.preview();
137-
var valsOutput = [];
138-
for (const o of vals) {
139-
valsOutput.push(o);
140-
}
134+
{
135+
const Debug = require('vm').runInDebugContext('Debug');
136+
const map = new Map();
137+
map.set(1, 2);
138+
const mirror = Debug.MakeMirror(map.entries(), true);
139+
const vals = mirror.preview();
140+
const valsOutput = [];
141+
for (const o of vals) {
142+
valsOutput.push(o);
143+
}
141144

142-
assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]');
145+
assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]');
146+
}
143147

144148
// test for other constructors in different context
145149
var obj = require('vm').runInNewContext('(function(){return {}})()', {});
@@ -212,8 +216,10 @@ assert.doesNotThrow(function() {
212216
});
213217

214218
// GH-2225
215-
var x = { inspect: util.inspect };
216-
assert.ok(util.inspect(x).indexOf('inspect') != -1);
219+
{
220+
const x = { inspect: util.inspect };
221+
assert.ok(util.inspect(x).indexOf('inspect') != -1);
222+
}
217223

218224
// util.inspect should not display the escaped value of a key.
219225
var w = {
@@ -261,39 +267,41 @@ assert.doesNotThrow(function() {
261267
});
262268

263269
// new API, accepts an "options" object
264-
var subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } };
265-
Object.defineProperty(subject, 'hidden', { enumerable: false, value: null });
266-
267-
assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1);
268-
assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1);
269-
assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1);
270-
assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1);
271-
assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1);
272-
assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1);
273-
assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1);
274-
275-
// "customInspect" option can enable/disable calling inspect() on objects
276-
subject = { inspect: function() { return 123; } };
277-
278-
assert(util.inspect(subject,
279-
{ customInspect: true }).indexOf('123') !== -1);
280-
assert(util.inspect(subject,
281-
{ customInspect: true }).indexOf('inspect') === -1);
282-
assert(util.inspect(subject,
283-
{ customInspect: false }).indexOf('123') === -1);
284-
assert(util.inspect(subject,
285-
{ customInspect: false }).indexOf('inspect') !== -1);
286-
287-
// custom inspect() functions should be able to return other Objects
288-
subject.inspect = function() { return { foo: 'bar' }; };
289-
290-
assert.equal(util.inspect(subject), '{ foo: \'bar\' }');
291-
292-
subject.inspect = function(depth, opts) {
293-
assert.strictEqual(opts.customInspectOptions, true);
294-
};
270+
{
271+
let subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } };
272+
Object.defineProperty(subject, 'hidden', { enumerable: false, value: null });
273+
274+
assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1);
275+
assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1);
276+
assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1);
277+
assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1);
278+
assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1);
279+
assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1);
280+
assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1);
281+
282+
// "customInspect" option can enable/disable calling inspect() on objects
283+
subject = { inspect: function() { return 123; } };
284+
285+
assert(util.inspect(subject,
286+
{ customInspect: true }).indexOf('123') !== -1);
287+
assert(util.inspect(subject,
288+
{ customInspect: true }).indexOf('inspect') === -1);
289+
assert(util.inspect(subject,
290+
{ customInspect: false }).indexOf('123') === -1);
291+
assert(util.inspect(subject,
292+
{ customInspect: false }).indexOf('inspect') !== -1);
293+
294+
// custom inspect() functions should be able to return other Objects
295+
subject.inspect = function() { return { foo: 'bar' }; };
296+
297+
assert.equal(util.inspect(subject), '{ foo: \'bar\' }');
298+
299+
subject.inspect = function(depth, opts) {
300+
assert.strictEqual(opts.customInspectOptions, true);
301+
};
295302

296-
util.inspect(subject, { customInspectOptions: true });
303+
util.inspect(subject, { customInspectOptions: true });
304+
}
297305

298306
// util.inspect with "colors" option should produce as many lines as without it
299307
function test_lines(input) {
@@ -353,8 +361,8 @@ if (typeof Symbol !== 'undefined') {
353361
assert.equal(util.inspect([Symbol()]), '[ Symbol() ]');
354362
assert.equal(util.inspect({ foo: Symbol() }), '{ foo: Symbol() }');
355363

356-
var options = { showHidden: true };
357-
var subject = {};
364+
const options = { showHidden: true };
365+
let subject = {};
358366

359367
subject[Symbol('symbol')] = 42;
360368

@@ -367,7 +375,6 @@ if (typeof Symbol !== 'undefined') {
367375
assert.equal(util.inspect(subject), '[ 1, 2, 3 ]');
368376
assert.equal(util.inspect(subject, options),
369377
'[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]');
370-
371378
}
372379

373380
// test Set
@@ -378,13 +385,15 @@ set.bar = 42;
378385
assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }');
379386

380387
// test Map
381-
assert.equal(util.inspect(new Map()), 'Map {}');
382-
assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])),
383-
'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }');
384-
var map = new Map([['foo', null]]);
385-
map.bar = 42;
386-
assert.equal(util.inspect(map, true),
387-
'Map { \'foo\' => null, [size]: 1, bar: 42 }');
388+
{
389+
assert.equal(util.inspect(new Map()), 'Map {}');
390+
assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])),
391+
'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }');
392+
const map = new Map([['foo', null]]);
393+
map.bar = 42;
394+
assert.equal(util.inspect(map, true),
395+
'Map { \'foo\' => null, [size]: 1, bar: 42 }');
396+
}
388397

389398
// test Promise
390399
assert.equal(util.inspect(Promise.resolve(3)), 'Promise { 3 }');
@@ -457,41 +466,50 @@ checkAlignment(new Map(big_array.map(function(y) { return [y, null]; })));
457466

458467

459468
// Test display of constructors
460-
461-
class ObjectSubclass {}
462-
class ArraySubclass extends Array {}
463-
class SetSubclass extends Set {}
464-
class MapSubclass extends Map {}
465-
class PromiseSubclass extends Promise {}
466-
467-
var x = new ObjectSubclass();
468-
x.foo = 42;
469-
assert.equal(util.inspect(x),
470-
'ObjectSubclass { foo: 42 }');
471-
assert.equal(util.inspect(new ArraySubclass(1, 2, 3)),
472-
'ArraySubclass [ 1, 2, 3 ]');
473-
assert.equal(util.inspect(new SetSubclass([1, 2, 3])),
474-
'SetSubclass { 1, 2, 3 }');
475-
assert.equal(util.inspect(new MapSubclass([['foo', 42]])),
476-
'MapSubclass { \'foo\' => 42 }');
477-
assert.equal(util.inspect(new PromiseSubclass(function() {})),
478-
'PromiseSubclass { <pending> }');
469+
{
470+
class ObjectSubclass {}
471+
class ArraySubclass extends Array {}
472+
class SetSubclass extends Set {}
473+
class MapSubclass extends Map {}
474+
class PromiseSubclass extends Promise {}
475+
476+
const x = new ObjectSubclass();
477+
x.foo = 42;
478+
assert.equal(util.inspect(x),
479+
'ObjectSubclass { foo: 42 }');
480+
assert.equal(util.inspect(new ArraySubclass(1, 2, 3)),
481+
'ArraySubclass [ 1, 2, 3 ]');
482+
assert.equal(util.inspect(new SetSubclass([1, 2, 3])),
483+
'SetSubclass { 1, 2, 3 }');
484+
assert.equal(util.inspect(new MapSubclass([['foo', 42]])),
485+
'MapSubclass { \'foo\' => 42 }');
486+
assert.equal(util.inspect(new PromiseSubclass(function() {})),
487+
'PromiseSubclass { <pending> }');
488+
}
479489

480490
// Corner cases.
481-
var x = { constructor: 42 };
482-
assert.equal(util.inspect(x), '{ constructor: 42 }');
483-
484-
var x = {};
485-
Object.defineProperty(x, 'constructor', {
486-
get: function() {
487-
throw new Error('should not access constructor');
488-
},
489-
enumerable: true
490-
});
491-
assert.equal(util.inspect(x), '{ constructor: [Getter] }');
491+
{
492+
const x = { constructor: 42 };
493+
assert.equal(util.inspect(x), '{ constructor: 42 }');
494+
}
492495

493-
var x = new (function() {});
494-
assert.equal(util.inspect(x), '{}');
496+
{
497+
const x = {};
498+
Object.defineProperty(x, 'constructor', {
499+
get: function() {
500+
throw new Error('should not access constructor');
501+
},
502+
enumerable: true
503+
});
504+
assert.equal(util.inspect(x), '{ constructor: [Getter] }');
505+
}
495506

496-
var x = Object.create(null);
497-
assert.equal(util.inspect(x), '{}');
507+
{
508+
const x = new (function() {});
509+
assert.equal(util.inspect(x), '{}');
510+
}
511+
512+
{
513+
const x = Object.create(null);
514+
assert.equal(util.inspect(x), '{}');
515+
}

0 commit comments

Comments
 (0)