test: fix redeclared test-util-* vars
PR-URL: https://github.com/nodejs/node/pull/4994 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
This commit is contained in:
parent
5ea1e7d55f
commit
415625c2a5
@ -160,24 +160,26 @@ for (const showHidden of [true, false]) {
|
|||||||
// the following ways this hash is displayed.
|
// the following ways this hash is displayed.
|
||||||
// See http://codereview.chromium.org/9124004/
|
// See http://codereview.chromium.org/9124004/
|
||||||
|
|
||||||
var out = util.inspect(Object.create({},
|
{
|
||||||
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
|
const out = util.inspect(Object.create({},
|
||||||
if (out !== '{ [hidden]: 2, visible: 1 }' &&
|
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
|
||||||
out !== '{ visible: 1, [hidden]: 2 }') {
|
if (out !== '{ [hidden]: 2, visible: 1 }' &&
|
||||||
assert.ok(false);
|
out !== '{ visible: 1, [hidden]: 2 }') {
|
||||||
|
assert.ok(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Objects without prototype
|
// Objects without prototype
|
||||||
var out = util.inspect(Object.create(null,
|
{
|
||||||
{ name: {value: 'Tim', enumerable: true},
|
const out = util.inspect(Object.create(null,
|
||||||
hidden: {value: 'secret'}}), true);
|
{ name: {value: 'Tim', enumerable: true},
|
||||||
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
|
hidden: {value: 'secret'}}), true);
|
||||||
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
|
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
|
||||||
assert(false);
|
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
util.inspect(Object.create(null,
|
util.inspect(Object.create(null,
|
||||||
{name: {value: 'Tim', enumerable: true},
|
{name: {value: 'Tim', enumerable: true},
|
||||||
@ -244,17 +246,19 @@ assert.equal(util.inspect(a, true), '[ \'foo\', , \'baz\', [length]: 3 ]');
|
|||||||
assert.equal(util.inspect(new Array(5)), '[ , , , , ]');
|
assert.equal(util.inspect(new Array(5)), '[ , , , , ]');
|
||||||
|
|
||||||
// test for Array constructor in different context
|
// test for Array constructor in different context
|
||||||
const Debug = require('vm').runInDebugContext('Debug');
|
{
|
||||||
var map = new Map();
|
const Debug = require('vm').runInDebugContext('Debug');
|
||||||
map.set(1, 2);
|
const map = new Map();
|
||||||
var mirror = Debug.MakeMirror(map.entries(), true);
|
map.set(1, 2);
|
||||||
var vals = mirror.preview();
|
const mirror = Debug.MakeMirror(map.entries(), true);
|
||||||
var valsOutput = [];
|
const vals = mirror.preview();
|
||||||
for (const o of vals) {
|
const valsOutput = [];
|
||||||
valsOutput.push(o);
|
for (const o of vals) {
|
||||||
}
|
valsOutput.push(o);
|
||||||
|
}
|
||||||
|
|
||||||
assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]');
|
assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]');
|
||||||
|
}
|
||||||
|
|
||||||
// test for other constructors in different context
|
// test for other constructors in different context
|
||||||
var obj = require('vm').runInNewContext('(function(){return {}})()', {});
|
var obj = require('vm').runInNewContext('(function(){return {}})()', {});
|
||||||
@ -347,8 +351,10 @@ assert.doesNotThrow(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// GH-2225
|
// GH-2225
|
||||||
var x = { inspect: util.inspect };
|
{
|
||||||
assert.ok(util.inspect(x).indexOf('inspect') != -1);
|
const x = { inspect: util.inspect };
|
||||||
|
assert.ok(util.inspect(x).indexOf('inspect') != -1);
|
||||||
|
}
|
||||||
|
|
||||||
// util.inspect should not display the escaped value of a key.
|
// util.inspect should not display the escaped value of a key.
|
||||||
var w = {
|
var w = {
|
||||||
@ -396,39 +402,41 @@ assert.doesNotThrow(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// new API, accepts an "options" object
|
// new API, accepts an "options" object
|
||||||
var subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } };
|
{
|
||||||
Object.defineProperty(subject, 'hidden', { enumerable: false, value: null });
|
let subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } };
|
||||||
|
Object.defineProperty(subject, 'hidden', { enumerable: false, value: null });
|
||||||
|
|
||||||
assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1);
|
assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1);
|
||||||
assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1);
|
assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1);
|
||||||
assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1);
|
assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1);
|
||||||
assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1);
|
assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1);
|
||||||
assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1);
|
assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1);
|
||||||
assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1);
|
assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1);
|
||||||
assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1);
|
assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1);
|
||||||
|
|
||||||
// "customInspect" option can enable/disable calling inspect() on objects
|
// "customInspect" option can enable/disable calling inspect() on objects
|
||||||
subject = { inspect: function() { return 123; } };
|
subject = { inspect: function() { return 123; } };
|
||||||
|
|
||||||
assert(util.inspect(subject,
|
assert(util.inspect(subject,
|
||||||
{ customInspect: true }).indexOf('123') !== -1);
|
{ customInspect: true }).indexOf('123') !== -1);
|
||||||
assert(util.inspect(subject,
|
assert(util.inspect(subject,
|
||||||
{ customInspect: true }).indexOf('inspect') === -1);
|
{ customInspect: true }).indexOf('inspect') === -1);
|
||||||
assert(util.inspect(subject,
|
assert(util.inspect(subject,
|
||||||
{ customInspect: false }).indexOf('123') === -1);
|
{ customInspect: false }).indexOf('123') === -1);
|
||||||
assert(util.inspect(subject,
|
assert(util.inspect(subject,
|
||||||
{ customInspect: false }).indexOf('inspect') !== -1);
|
{ customInspect: false }).indexOf('inspect') !== -1);
|
||||||
|
|
||||||
// custom inspect() functions should be able to return other Objects
|
// custom inspect() functions should be able to return other Objects
|
||||||
subject.inspect = function() { return { foo: 'bar' }; };
|
subject.inspect = function() { return { foo: 'bar' }; };
|
||||||
|
|
||||||
assert.equal(util.inspect(subject), '{ foo: \'bar\' }');
|
assert.equal(util.inspect(subject), '{ foo: \'bar\' }');
|
||||||
|
|
||||||
subject.inspect = function(depth, opts) {
|
subject.inspect = function(depth, opts) {
|
||||||
assert.strictEqual(opts.customInspectOptions, true);
|
assert.strictEqual(opts.customInspectOptions, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inspect(subject, { customInspectOptions: true });
|
util.inspect(subject, { customInspectOptions: true });
|
||||||
|
}
|
||||||
|
|
||||||
// util.inspect with "colors" option should produce as many lines as without it
|
// util.inspect with "colors" option should produce as many lines as without it
|
||||||
function test_lines(input) {
|
function test_lines(input) {
|
||||||
@ -488,8 +496,8 @@ if (typeof Symbol !== 'undefined') {
|
|||||||
assert.equal(util.inspect([Symbol()]), '[ Symbol() ]');
|
assert.equal(util.inspect([Symbol()]), '[ Symbol() ]');
|
||||||
assert.equal(util.inspect({ foo: Symbol() }), '{ foo: Symbol() }');
|
assert.equal(util.inspect({ foo: Symbol() }), '{ foo: Symbol() }');
|
||||||
|
|
||||||
var options = { showHidden: true };
|
const options = { showHidden: true };
|
||||||
var subject = {};
|
let subject = {};
|
||||||
|
|
||||||
subject[Symbol('symbol')] = 42;
|
subject[Symbol('symbol')] = 42;
|
||||||
|
|
||||||
@ -502,7 +510,6 @@ if (typeof Symbol !== 'undefined') {
|
|||||||
assert.equal(util.inspect(subject), '[ 1, 2, 3 ]');
|
assert.equal(util.inspect(subject), '[ 1, 2, 3 ]');
|
||||||
assert.equal(util.inspect(subject, options),
|
assert.equal(util.inspect(subject, options),
|
||||||
'[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]');
|
'[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test Set
|
// test Set
|
||||||
@ -513,13 +520,15 @@ set.bar = 42;
|
|||||||
assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }');
|
assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }');
|
||||||
|
|
||||||
// test Map
|
// test Map
|
||||||
assert.equal(util.inspect(new Map()), 'Map {}');
|
{
|
||||||
assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])),
|
assert.equal(util.inspect(new Map()), 'Map {}');
|
||||||
'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }');
|
assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])),
|
||||||
var map = new Map([['foo', null]]);
|
'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }');
|
||||||
map.bar = 42;
|
const map = new Map([['foo', null]]);
|
||||||
assert.equal(util.inspect(map, true),
|
map.bar = 42;
|
||||||
'Map { \'foo\' => null, [size]: 1, bar: 42 }');
|
assert.equal(util.inspect(map, true),
|
||||||
|
'Map { \'foo\' => null, [size]: 1, bar: 42 }');
|
||||||
|
}
|
||||||
|
|
||||||
// test Promise
|
// test Promise
|
||||||
assert.equal(util.inspect(Promise.resolve(3)), 'Promise { 3 }');
|
assert.equal(util.inspect(Promise.resolve(3)), 'Promise { 3 }');
|
||||||
@ -592,41 +601,50 @@ checkAlignment(new Map(big_array.map(function(y) { return [y, null]; })));
|
|||||||
|
|
||||||
|
|
||||||
// Test display of constructors
|
// Test display of constructors
|
||||||
|
{
|
||||||
|
class ObjectSubclass {}
|
||||||
|
class ArraySubclass extends Array {}
|
||||||
|
class SetSubclass extends Set {}
|
||||||
|
class MapSubclass extends Map {}
|
||||||
|
class PromiseSubclass extends Promise {}
|
||||||
|
|
||||||
class ObjectSubclass {}
|
const x = new ObjectSubclass();
|
||||||
class ArraySubclass extends Array {}
|
x.foo = 42;
|
||||||
class SetSubclass extends Set {}
|
assert.equal(util.inspect(x),
|
||||||
class MapSubclass extends Map {}
|
'ObjectSubclass { foo: 42 }');
|
||||||
class PromiseSubclass extends Promise {}
|
assert.equal(util.inspect(new ArraySubclass(1, 2, 3)),
|
||||||
|
'ArraySubclass [ 1, 2, 3 ]');
|
||||||
var x = new ObjectSubclass();
|
assert.equal(util.inspect(new SetSubclass([1, 2, 3])),
|
||||||
x.foo = 42;
|
'SetSubclass { 1, 2, 3 }');
|
||||||
assert.equal(util.inspect(x),
|
assert.equal(util.inspect(new MapSubclass([['foo', 42]])),
|
||||||
'ObjectSubclass { foo: 42 }');
|
'MapSubclass { \'foo\' => 42 }');
|
||||||
assert.equal(util.inspect(new ArraySubclass(1, 2, 3)),
|
assert.equal(util.inspect(new PromiseSubclass(function() {})),
|
||||||
'ArraySubclass [ 1, 2, 3 ]');
|
'PromiseSubclass { <pending> }');
|
||||||
assert.equal(util.inspect(new SetSubclass([1, 2, 3])),
|
}
|
||||||
'SetSubclass { 1, 2, 3 }');
|
|
||||||
assert.equal(util.inspect(new MapSubclass([['foo', 42]])),
|
|
||||||
'MapSubclass { \'foo\' => 42 }');
|
|
||||||
assert.equal(util.inspect(new PromiseSubclass(function() {})),
|
|
||||||
'PromiseSubclass { <pending> }');
|
|
||||||
|
|
||||||
// Corner cases.
|
// Corner cases.
|
||||||
var x = { constructor: 42 };
|
{
|
||||||
assert.equal(util.inspect(x), '{ constructor: 42 }');
|
const x = { constructor: 42 };
|
||||||
|
assert.equal(util.inspect(x), '{ constructor: 42 }');
|
||||||
|
}
|
||||||
|
|
||||||
var x = {};
|
{
|
||||||
Object.defineProperty(x, 'constructor', {
|
const x = {};
|
||||||
get: function() {
|
Object.defineProperty(x, 'constructor', {
|
||||||
throw new Error('should not access constructor');
|
get: function() {
|
||||||
},
|
throw new Error('should not access constructor');
|
||||||
enumerable: true
|
},
|
||||||
});
|
enumerable: true
|
||||||
assert.equal(util.inspect(x), '{ constructor: [Getter] }');
|
});
|
||||||
|
assert.equal(util.inspect(x), '{ constructor: [Getter] }');
|
||||||
|
}
|
||||||
|
|
||||||
var x = new (function() {});
|
{
|
||||||
assert.equal(util.inspect(x), '{}');
|
const x = new (function() {});
|
||||||
|
assert.equal(util.inspect(x), '{}');
|
||||||
|
}
|
||||||
|
|
||||||
var x = Object.create(null);
|
{
|
||||||
assert.equal(util.inspect(x), '{}');
|
const x = Object.create(null);
|
||||||
|
assert.equal(util.inspect(x), '{}');
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user