diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-10 02:33:08 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-16 16:54:07 +0100 |
commit | 644fdd60d4be49ffa66d0bda1702c4459f607635 (patch) | |
tree | 70da98bc22a5a6c5bd0063e25d6eb729125706bf /test/parallel/test-util-inspect.js | |
parent | caee112e52b64f4bc1118c4a5fa5ad7b4211efea (diff) | |
download | android-node-v8-644fdd60d4be49ffa66d0bda1702c4459f607635.tar.gz android-node-v8-644fdd60d4be49ffa66d0bda1702c4459f607635.tar.bz2 android-node-v8-644fdd60d4be49ffa66d0bda1702c4459f607635.zip |
test: minor refactoring
Add punctuation and comments about code that should not throw.
Also remove a obsolete test and refactor some tests.
PR-URL: https://github.com/nodejs/node/pull/18669
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-util-inspect.js')
-rw-r--r-- | test/parallel/test-util-inspect.js | 113 |
1 files changed, 55 insertions, 58 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 4f717e2d6b..49ef4e0ecd 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -146,7 +146,7 @@ for (const showHidden of [true, false]) { ' y: 1337 }'); } -// Now do the same checks but from a different context +// Now do the same checks but from a different context. for (const showHidden of [true, false]) { const ab = vm.runInNewContext('new ArrayBuffer(4)'); const dv = vm.runInNewContext('new DataView(ab, 1, 2)', { ab }); @@ -211,7 +211,7 @@ for (const showHidden of [true, false]) { ); }); -// Now check that declaring a TypedArray in a different context works the same +// Now check that declaring a TypedArray in a different context works the same. [ Float32Array, Float64Array, Int16Array, @@ -252,7 +252,7 @@ assert.strictEqual( }), { showHidden: true }), '{ visible: 1, [hidden]: 2 }' ); -// Objects without prototype +// Objects without prototype. assert.strictEqual( util.inspect(Object.create(null, { name: { value: 'Tim', enumerable: true }, @@ -269,7 +269,7 @@ assert.strictEqual( '{ name: \'Tim\' }' ); -// Dynamic properties +// Dynamic properties. { assert.strictEqual( util.inspect({ get readonly() {} }), @@ -289,7 +289,7 @@ assert.strictEqual( assert.strictEqual(util.inspect(value), '{ a: [Circular] }'); } -// Array with dynamic properties +// Array with dynamic properties. { const value = [1, 2, 3]; Object.defineProperty( @@ -312,7 +312,7 @@ assert.strictEqual( '[ 1, 2, 3, growingLength: [Getter], \'-1\': -1 ]'); } -// Array with inherited number properties +// Array with inherited number properties. { class CustomArray extends Array {} CustomArray.prototype[5] = 'foo'; @@ -320,7 +320,7 @@ assert.strictEqual( assert.strictEqual(util.inspect(arr), 'CustomArray [ <50 empty items> ]'); } -// Array with extra properties +// Array with extra properties. { const arr = [1, 2, 3, , ]; arr.foo = 'bar'; @@ -352,10 +352,10 @@ assert.strictEqual( assert.strictEqual(util.inspect(arr3), "[ '-1': -1 ]"); } -// Indices out of bounds +// Indices out of bounds. { const arr = []; - arr[2 ** 32] = true; // not a valid array index + arr[2 ** 32] = true; // Not a valid array index. assert.strictEqual(util.inspect(arr), "[ '4294967296': true ]"); arr[0] = true; arr[10] = true; @@ -375,28 +375,28 @@ assert.strictEqual( ].join('\n ')); } -// Function with properties +// Function with properties. { const value = () => {}; value.aprop = 42; assert.strictEqual(util.inspect(value), '{ [Function: value] aprop: 42 }'); } -// Anonymous function with properties +// Anonymous function with properties. { const value = (() => function() {})(); value.aprop = 42; assert.strictEqual(util.inspect(value), '{ [Function] aprop: 42 }'); } -// Regular expressions with properties +// Regular expressions with properties. { const value = /123/ig; value.aprop = 42; assert.strictEqual(util.inspect(value), '{ /123/gi aprop: 42 }'); } -// Dates with properties +// Dates with properties. { const value = new Date('Sun, 14 Feb 2010 11:48:40 GMT'); value.aprop = 42; @@ -404,7 +404,7 @@ assert.strictEqual( '{ 2010-02-14T11:48:40.000Z aprop: 42 }'); } -// test the internal isDate implementation +// Test the internal isDate implementation. { const Date2 = vm.runInNewContext('Date'); const d = new Date2(); @@ -414,13 +414,13 @@ assert.strictEqual( assert.strictEqual(orig, after); } -// test positive/negative zero +// Test positive/negative zero. assert.strictEqual(util.inspect(0), '0'); assert.strictEqual(util.inspect(-0), '-0'); -// edge case from check +// Edge case from check. assert.strictEqual(util.inspect(-5e-324), '-5e-324'); -// test for sparse array +// Test for sparse array. { const a = ['foo', 'bar', 'baz']; assert.strictEqual(util.inspect(a), '[ \'foo\', \'bar\', \'baz\' ]'); @@ -444,7 +444,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); ); } -// test for Array constructor in different context +// Test for Array constructor in different context. { const map = new Map(); map.set(1, 2); @@ -457,7 +457,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]'); } -// test for other constructors in different context +// Test for other constructors in different context. { let obj = vm.runInNewContext('(function(){return {}})()', {}); assert.strictEqual(util.inspect(obj), '{}'); @@ -469,7 +469,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); assert.strictEqual(util.inspect(obj), 'Promise { <pending> }'); } -// test for property descriptors +// Test for property descriptors. { const getter = Object.create(null, { a: { @@ -495,7 +495,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); ); } -// exceptions should print the error message, not '{}' +// Exceptions should print the error message, not '{}'. { const errors = []; errors.push(new Error()); @@ -516,7 +516,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); assert(ex.includes('[message]')); } -// Doesn't capture stack trace +// Doesn't capture stack trace. { function BadCustomError(msg) { Error.call(this); @@ -533,7 +533,6 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); } // GH-1941 -// should not throw: assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}'); // GH-1944 @@ -543,20 +542,20 @@ assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}'); util.inspect(d); } +// Should not throw. { const d = new Date(); d.toISOString = null; util.inspect(d); } +// Should not throw. const r = /regexp/; r.toString = null; util.inspect(r); -// bug with user-supplied inspect function returns non-string -util.inspect([{ - inspect: () => 123 -}]); +// Bug with user-supplied inspect function returns non-string. +util.inspect([{ inspect: () => 123 }]); // GH-2225 { @@ -592,7 +591,7 @@ util.inspect([{ ); } -// util.inspect.styles and util.inspect.colors +// Test util.inspect.styles and util.inspect.colors. { function testColorStyle(style, input, implicit) { const colorName = util.inspect.styles[style]; @@ -619,12 +618,10 @@ util.inspect([{ testColorStyle('regexp', /regexp/); } -// an object with "hasOwnProperty" overwritten should not throw -util.inspect({ - hasOwnProperty: null -}); +// An object with "hasOwnProperty" overwritten should not throw. +util.inspect({ hasOwnProperty: null }); -// new API, accepts an "options" object +// New API, accepts an "options" object. { const subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } }; Object.defineProperty(subject, 'hidden', { enumerable: false, value: null }); @@ -664,7 +661,7 @@ util.inspect({ } { - // "customInspect" option can enable/disable calling inspect() on objects + // "customInspect" option can enable/disable calling inspect() on objects. const subject = { inspect: () => 123 }; assert.strictEqual( @@ -684,7 +681,7 @@ util.inspect({ true ); - // custom inspect() functions should be able to return other Objects + // Custom inspect() functions should be able to return other Objects. subject.inspect = () => ({ foo: 'bar' }); assert.strictEqual(util.inspect(subject), '{ foo: \'bar\' }'); @@ -697,7 +694,7 @@ util.inspect({ } { - // "customInspect" option can enable/disable calling [util.inspect.custom]() + // "customInspect" option can enable/disable calling [util.inspect.custom](). const subject = { [util.inspect.custom]: () => 123 }; assert.strictEqual( @@ -709,7 +706,7 @@ util.inspect({ false ); - // a custom [util.inspect.custom]() should be able to return other Objects + // A custom [util.inspect.custom]() should be able to return other Objects. subject[util.inspect.custom] = () => ({ foo: 'bar' }); assert.strictEqual(util.inspect(subject), '{ foo: \'bar\' }'); @@ -722,7 +719,7 @@ util.inspect({ } { - // [util.inspect.custom] takes precedence over inspect + // [util.inspect.custom] takes precedence over inspect. const subject = { [util.inspect.custom]() { return 123; }, inspect() { return 456; } @@ -757,7 +754,7 @@ util.inspect({ `{ a: 123,\n [Symbol(${UIC})]: [Function: [${UIC}]] }`); } -// 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 testLines(input) { const countLines = (str) => (str.match(/\n/g) || []).length; @@ -781,7 +778,7 @@ util.inspect({ }); } -// test boxed primitives output the correct values +// Test boxed primitives output the correct values. assert.strictEqual(util.inspect(new String('test')), '[String: \'test\']'); assert.strictEqual( util.inspect(Object(Symbol('test'))), @@ -794,7 +791,7 @@ assert.strictEqual(util.inspect(new Number(-0)), '[Number: -0]'); assert.strictEqual(util.inspect(new Number(-1.1)), '[Number: -1.1]'); assert.strictEqual(util.inspect(new Number(13.37)), '[Number: 13.37]'); -// test boxed primitives with own properties +// Test boxed primitives with own properties. { const str = new String('baz'); str.foo = 'bar'; @@ -809,7 +806,7 @@ assert.strictEqual(util.inspect(new Number(13.37)), '[Number: 13.37]'); assert.strictEqual(util.inspect(num), '{ [Number: 13.37] foo: \'bar\' }'); } -// test es6 Symbol +// Test es6 Symbol. if (typeof Symbol !== 'undefined') { assert.strictEqual(util.inspect(Symbol()), 'Symbol()'); assert.strictEqual(util.inspect(Symbol(123)), 'Symbol(123)'); @@ -845,7 +842,7 @@ if (typeof Symbol !== 'undefined') { '[ 1, 2, 3, [Symbol(symbol)]: 42 ]'); } -// test Set +// Test Set. { assert.strictEqual(util.inspect(new Set()), 'Set {}'); assert.strictEqual(util.inspect(new Set([1, 2, 3])), 'Set { 1, 2, 3 }'); @@ -857,14 +854,14 @@ if (typeof Symbol !== 'undefined') { ); } -// Test circular Set +// Test circular Set. { const set = new Set(); set.add(set); assert.strictEqual(util.inspect(set), 'Set { [Circular] }'); } -// test Map +// Test Map. { assert.strictEqual(util.inspect(new Map()), 'Map {}'); assert.strictEqual(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), @@ -875,7 +872,7 @@ if (typeof Symbol !== 'undefined') { 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); } -// Test circular Map +// Test circular Map. { const map = new Map(); map.set(map, 'map'); @@ -887,14 +884,14 @@ if (typeof Symbol !== 'undefined') { assert.strictEqual(util.inspect(map), "Map { 'map' => [Circular] }"); } -// test Promise +// Test Promise. { const resolved = Promise.resolve(3); assert.strictEqual(util.inspect(resolved), 'Promise { 3 }'); const rejected = Promise.reject(3); assert.strictEqual(util.inspect(rejected), 'Promise { <rejected> 3 }'); - // squelch UnhandledPromiseRejection + // Squelch UnhandledPromiseRejection. rejected.catch(() => {}); const pending = new Promise(() => {}); @@ -916,33 +913,33 @@ if (typeof Symbol !== 'undefined') { global.Promise = oldPromise; } -// Test Map iterators +// Test Map iterators. { const map = new Map([['foo', 'bar']]); assert.strictEqual(util.inspect(map.keys()), '[Map Iterator] { \'foo\' }'); assert.strictEqual(util.inspect(map.values()), '[Map Iterator] { \'bar\' }'); assert.strictEqual(util.inspect(map.entries()), '[Map Iterator] { [ \'foo\', \'bar\' ] }'); - // make sure the iterator doesn't get consumed + // Make sure the iterator doesn't get consumed. const keys = map.keys(); assert.strictEqual(util.inspect(keys), '[Map Iterator] { \'foo\' }'); assert.strictEqual(util.inspect(keys), '[Map Iterator] { \'foo\' }'); } -// Test Set iterators +// Test Set iterators. { const aSet = new Set([1, 3]); assert.strictEqual(util.inspect(aSet.keys()), '[Set Iterator] { 1, 3 }'); assert.strictEqual(util.inspect(aSet.values()), '[Set Iterator] { 1, 3 }'); assert.strictEqual(util.inspect(aSet.entries()), '[Set Iterator] { [ 1, 1 ], [ 3, 3 ] }'); - // make sure the iterator doesn't get consumed + // Make sure the iterator doesn't get consumed. const keys = aSet.keys(); assert.strictEqual(util.inspect(keys), '[Set Iterator] { 1, 3 }'); assert.strictEqual(util.inspect(keys), '[Set Iterator] { 1, 3 }'); } -// Test alignment of items in container +// Test alignment of items in container. // Assumes that the first numeric character is the start of an item. { function checkAlignment(container) { @@ -977,7 +974,7 @@ if (typeof Symbol !== 'undefined') { } -// Test display of constructors +// Test display of constructors. { class ObjectSubclass {} class ArraySubclass extends Array {} @@ -1003,7 +1000,7 @@ if (typeof Symbol !== 'undefined') { ); } -// Empty and circular before depth +// Empty and circular before depth. { const arr = [[[[]]]]; assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [] ] ] ]'); @@ -1099,14 +1096,14 @@ if (typeof Symbol !== 'undefined') { assert.strictEqual(twoLines, '{ foo: \'abc\',\n bar: \'xyz\' }'); } -// util.inspect.defaultOptions tests +// util.inspect.defaultOptions tests. { const arr = new Array(101).fill(); const obj = { a: { a: { a: { a: 1 } } } }; const oldOptions = Object.assign({}, util.inspect.defaultOptions); - // Set single option through property assignment + // Set single option through property assignment. util.inspect.defaultOptions.maxArrayLength = null; assert(!/1 more item/.test(util.inspect(arr))); util.inspect.defaultOptions.maxArrayLength = oldOptions.maxArrayLength; @@ -1120,7 +1117,7 @@ if (typeof Symbol !== 'undefined') { JSON.stringify(oldOptions) ); - // Set multiple options through object assignment + // Set multiple options through object assignment. util.inspect.defaultOptions = { maxArrayLength: null, depth: 2 }; assert(!/1 more item/.test(util.inspect(arr))); assert(/Object/.test(util.inspect(obj))); |