Skip to content

Commit 1a62f5a

Browse files
TrottMichael Scovetta
authored and
Michael Scovetta
committed
test: fix redeclared test-util-* vars
PR-URL: nodejs#4994 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Klauke <[email protected]>
1 parent 7679183 commit 1a62f5a

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
@@ -160,24 +160,26 @@ for (const showHidden of [true, false]) {
160160
// the following ways this hash is displayed.
161161
// See http://codereview.chromium.org/9124004/
162162

163-
var out = util.inspect(Object.create({},
164-
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
165-
if (out !== '{ [hidden]: 2, visible: 1 }' &&
166-
out !== '{ visible: 1, [hidden]: 2 }') {
167-
assert.ok(false);
163+
{
164+
const out = util.inspect(Object.create({},
165+
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
166+
if (out !== '{ [hidden]: 2, visible: 1 }' &&
167+
out !== '{ visible: 1, [hidden]: 2 }') {
168+
assert.ok(false);
169+
}
168170
}
169171

170-
171172
// Objects without prototype
172-
var out = util.inspect(Object.create(null,
173-
{ name: {value: 'Tim', enumerable: true},
174-
hidden: {value: 'secret'}}), true);
175-
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
176-
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
177-
assert(false);
173+
{
174+
const out = util.inspect(Object.create(null,
175+
{ name: {value: 'Tim', enumerable: true},
176+
hidden: {value: 'secret'}}), true);
177+
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
178+
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
179+
assert(false);
180+
}
178181
}
179182

180-
181183
assert.equal(
182184
util.inspect(Object.create(null,
183185
{name: {value: 'Tim', enumerable: true},
@@ -244,17 +246,19 @@ assert.equal(util.inspect(a, true), '[ \'foo\', , \'baz\', [length]: 3 ]');
244246
assert.equal(util.inspect(new Array(5)), '[ , , , , ]');
245247

246248
// test for Array constructor in different context
247-
const Debug = require('vm').runInDebugContext('Debug');
248-
var map = new Map();
249-
map.set(1, 2);
250-
var mirror = Debug.MakeMirror(map.entries(), true);
251-
var vals = mirror.preview();
252-
var valsOutput = [];
253-
for (const o of vals) {
254-
valsOutput.push(o);
255-
}
249+
{
250+
const Debug = require('vm').runInDebugContext('Debug');
251+
const map = new Map();
252+
map.set(1, 2);
253+
const mirror = Debug.MakeMirror(map.entries(), true);
254+
const vals = mirror.preview();
255+
const valsOutput = [];
256+
for (const o of vals) {
257+
valsOutput.push(o);
258+
}
256259

257-
assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]');
260+
assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]');
261+
}
258262

259263
// test for other constructors in different context
260264
var obj = require('vm').runInNewContext('(function(){return {}})()', {});
@@ -347,8 +351,10 @@ assert.doesNotThrow(function() {
347351
});
348352

349353
// GH-2225
350-
var x = { inspect: util.inspect };
351-
assert.ok(util.inspect(x).indexOf('inspect') != -1);
354+
{
355+
const x = { inspect: util.inspect };
356+
assert.ok(util.inspect(x).indexOf('inspect') != -1);
357+
}
352358

353359
// util.inspect should not display the escaped value of a key.
354360
var w = {
@@ -396,39 +402,41 @@ assert.doesNotThrow(function() {
396402
});
397403

398404
// new API, accepts an "options" object
399-
var subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } };
400-
Object.defineProperty(subject, 'hidden', { enumerable: false, value: null });
401-
402-
assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1);
403-
assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1);
404-
assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1);
405-
assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1);
406-
assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1);
407-
assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1);
408-
assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1);
409-
410-
// "customInspect" option can enable/disable calling inspect() on objects
411-
subject = { inspect: function() { return 123; } };
412-
413-
assert(util.inspect(subject,
414-
{ customInspect: true }).indexOf('123') !== -1);
415-
assert(util.inspect(subject,
416-
{ customInspect: true }).indexOf('inspect') === -1);
417-
assert(util.inspect(subject,
418-
{ customInspect: false }).indexOf('123') === -1);
419-
assert(util.inspect(subject,
420-
{ customInspect: false }).indexOf('inspect') !== -1);
421-
422-
// custom inspect() functions should be able to return other Objects
423-
subject.inspect = function() { return { foo: 'bar' }; };
424-
425-
assert.equal(util.inspect(subject), '{ foo: \'bar\' }');
426-
427-
subject.inspect = function(depth, opts) {
428-
assert.strictEqual(opts.customInspectOptions, true);
429-
};
405+
{
406+
let subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } };
407+
Object.defineProperty(subject, 'hidden', { enumerable: false, value: null });
408+
409+
assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1);
410+
assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1);
411+
assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1);
412+
assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1);
413+
assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1);
414+
assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1);
415+
assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1);
416+
417+
// "customInspect" option can enable/disable calling inspect() on objects
418+
subject = { inspect: function() { return 123; } };
419+
420+
assert(util.inspect(subject,
421+
{ customInspect: true }).indexOf('123') !== -1);
422+
assert(util.inspect(subject,
423+
{ customInspect: true }).indexOf('inspect') === -1);
424+
assert(util.inspect(subject,
425+
{ customInspect: false }).indexOf('123') === -1);
426+
assert(util.inspect(subject,
427+
{ customInspect: false }).indexOf('inspect') !== -1);
428+
429+
// custom inspect() functions should be able to return other Objects
430+
subject.inspect = function() { return { foo: 'bar' }; };
431+
432+
assert.equal(util.inspect(subject), '{ foo: \'bar\' }');
433+
434+
subject.inspect = function(depth, opts) {
435+
assert.strictEqual(opts.customInspectOptions, true);
436+
};
430437

431-
util.inspect(subject, { customInspectOptions: true });
438+
util.inspect(subject, { customInspectOptions: true });
439+
}
432440

433441
// util.inspect with "colors" option should produce as many lines as without it
434442
function test_lines(input) {
@@ -488,8 +496,8 @@ if (typeof Symbol !== 'undefined') {
488496
assert.equal(util.inspect([Symbol()]), '[ Symbol() ]');
489497
assert.equal(util.inspect({ foo: Symbol() }), '{ foo: Symbol() }');
490498

491-
var options = { showHidden: true };
492-
var subject = {};
499+
const options = { showHidden: true };
500+
let subject = {};
493501

494502
subject[Symbol('symbol')] = 42;
495503

@@ -502,7 +510,6 @@ if (typeof Symbol !== 'undefined') {
502510
assert.equal(util.inspect(subject), '[ 1, 2, 3 ]');
503511
assert.equal(util.inspect(subject, options),
504512
'[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]');
505-
506513
}
507514

508515
// test Set
@@ -513,13 +520,15 @@ set.bar = 42;
513520
assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }');
514521

515522
// test Map
516-
assert.equal(util.inspect(new Map()), 'Map {}');
517-
assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])),
518-
'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }');
519-
var map = new Map([['foo', null]]);
520-
map.bar = 42;
521-
assert.equal(util.inspect(map, true),
522-
'Map { \'foo\' => null, [size]: 1, bar: 42 }');
523+
{
524+
assert.equal(util.inspect(new Map()), 'Map {}');
525+
assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])),
526+
'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }');
527+
const map = new Map([['foo', null]]);
528+
map.bar = 42;
529+
assert.equal(util.inspect(map, true),
530+
'Map { \'foo\' => null, [size]: 1, bar: 42 }');
531+
}
523532

524533
// test Promise
525534
assert.equal(util.inspect(Promise.resolve(3)), 'Promise { 3 }');
@@ -592,41 +601,50 @@ checkAlignment(new Map(big_array.map(function(y) { return [y, null]; })));
592601

593602

594603
// Test display of constructors
595-
596-
class ObjectSubclass {}
597-
class ArraySubclass extends Array {}
598-
class SetSubclass extends Set {}
599-
class MapSubclass extends Map {}
600-
class PromiseSubclass extends Promise {}
601-
602-
var x = new ObjectSubclass();
603-
x.foo = 42;
604-
assert.equal(util.inspect(x),
605-
'ObjectSubclass { foo: 42 }');
606-
assert.equal(util.inspect(new ArraySubclass(1, 2, 3)),
607-
'ArraySubclass [ 1, 2, 3 ]');
608-
assert.equal(util.inspect(new SetSubclass([1, 2, 3])),
609-
'SetSubclass { 1, 2, 3 }');
610-
assert.equal(util.inspect(new MapSubclass([['foo', 42]])),
611-
'MapSubclass { \'foo\' => 42 }');
612-
assert.equal(util.inspect(new PromiseSubclass(function() {})),
613-
'PromiseSubclass { <pending> }');
604+
{
605+
class ObjectSubclass {}
606+
class ArraySubclass extends Array {}
607+
class SetSubclass extends Set {}
608+
class MapSubclass extends Map {}
609+
class PromiseSubclass extends Promise {}
610+
611+
const x = new ObjectSubclass();
612+
x.foo = 42;
613+
assert.equal(util.inspect(x),
614+
'ObjectSubclass { foo: 42 }');
615+
assert.equal(util.inspect(new ArraySubclass(1, 2, 3)),
616+
'ArraySubclass [ 1, 2, 3 ]');
617+
assert.equal(util.inspect(new SetSubclass([1, 2, 3])),
618+
'SetSubclass { 1, 2, 3 }');
619+
assert.equal(util.inspect(new MapSubclass([['foo', 42]])),
620+
'MapSubclass { \'foo\' => 42 }');
621+
assert.equal(util.inspect(new PromiseSubclass(function() {})),
622+
'PromiseSubclass { <pending> }');
623+
}
614624

615625
// Corner cases.
616-
var x = { constructor: 42 };
617-
assert.equal(util.inspect(x), '{ constructor: 42 }');
618-
619-
var x = {};
620-
Object.defineProperty(x, 'constructor', {
621-
get: function() {
622-
throw new Error('should not access constructor');
623-
},
624-
enumerable: true
625-
});
626-
assert.equal(util.inspect(x), '{ constructor: [Getter] }');
626+
{
627+
const x = { constructor: 42 };
628+
assert.equal(util.inspect(x), '{ constructor: 42 }');
629+
}
627630

628-
var x = new (function() {});
629-
assert.equal(util.inspect(x), '{}');
631+
{
632+
const x = {};
633+
Object.defineProperty(x, 'constructor', {
634+
get: function() {
635+
throw new Error('should not access constructor');
636+
},
637+
enumerable: true
638+
});
639+
assert.equal(util.inspect(x), '{ constructor: [Getter] }');
640+
}
630641

631-
var x = Object.create(null);
632-
assert.equal(util.inspect(x), '{}');
642+
{
643+
const x = new (function() {});
644+
assert.equal(util.inspect(x), '{}');
645+
}
646+
647+
{
648+
const x = Object.create(null);
649+
assert.equal(util.inspect(x), '{}');
650+
}

0 commit comments

Comments
 (0)