diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-26 03:59:28 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-03 02:20:31 +0200 |
commit | e1e9f1e9eeeb899fb1dad10072fdf22ce5c9827e (patch) | |
tree | 10ada71dd3a165ccaf68d5d18dd1e7a9f7715b45 /test | |
parent | 7aa7971eec258ce1f8895ff66c5de78c6a59710f (diff) | |
download | android-node-v8-e1e9f1e9eeeb899fb1dad10072fdf22ce5c9827e.tar.gz android-node-v8-e1e9f1e9eeeb899fb1dad10072fdf22ce5c9827e.tar.bz2 android-node-v8-e1e9f1e9eeeb899fb1dad10072fdf22ce5c9827e.zip |
util: `inspect()` should not exceed `breakLength`
Using `util.inspect()` with the `compact` option set to a number
could result in output that exceeded the `breakLength` option. This
change makes sure that limit is taken into account.
PR-URL: https://github.com/nodejs/node/pull/26914
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-util-inspect.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 8bead13383..dd44c9c439 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -2233,4 +2233,94 @@ assert.strictEqual( '\u001b[33m3\u001b[39m, \u001b[33m4\u001b[39m ]'; assert.strictEqual(out, expected); + + obj = [ + 'Object', 'Function', 'Array', + 'Number', 'parseFloat', 'parseInt', + 'Infinity', 'NaN', 'undefined', + 'Boolean', 'String', 'Symbol', + 'Date', 'Promise', 'RegExp', + 'Error', 'EvalError', 'RangeError', + 'ReferenceError', 'SyntaxError', 'TypeError', + 'URIError', 'JSON', 'Math', + 'console', 'Intl', 'ArrayBuffer', + 'Uint8Array', 'Int8Array', 'Uint16Array', + 'Int16Array', 'Uint32Array', 'Int32Array', + 'Float32Array', 'Float64Array', 'Uint8ClampedArray', + 'BigUint64Array', 'BigInt64Array', 'DataView', + 'Map', 'BigInt', 'Set', + 'WeakMap', 'WeakSet', 'Proxy', + 'Reflect', 'decodeURI', 'decodeURIComponent', + 'encodeURI', 'encodeURIComponent', 'escape', + 'unescape', 'eval', 'isFinite', + 'isNaN', 'SharedArrayBuffer', 'Atomics', + 'globalThis', 'WebAssembly', 'global', + 'process', 'GLOBAL', 'root', + 'Buffer', 'URL', 'URLSearchParams', + 'TextEncoder', 'TextDecoder', 'clearInterval', + 'clearTimeout', 'setInterval', 'setTimeout', + 'queueMicrotask', 'clearImmediate', 'setImmediate', + 'module', 'require', 'assert', + 'async_hooks', 'buffer', 'child_process', + 'cluster', 'crypto', 'dgram', + 'dns', 'domain', 'events', + 'fs', 'http', 'http2', + 'https', 'inspector', 'net', + 'os', 'path', 'perf_hooks', + 'punycode', 'querystring', 'readline', + 'repl', 'stream', 'string_decoder', + 'tls', 'trace_events', 'tty', + 'url', 'v8', 'vm', + 'worker_threads', 'zlib', '_', + '_error', 'util' + ]; + + out = util.inspect( + obj, + { compact: 3, breakLength: 80, maxArrayLength: 250 } + ); + expected = [ + '[', + " 'Object', 'Function', 'Array',", + " 'Number', 'parseFloat', 'parseInt',", + " 'Infinity', 'NaN', 'undefined',", + " 'Boolean', 'String', 'Symbol',", + " 'Date', 'Promise', 'RegExp',", + " 'Error', 'EvalError', 'RangeError',", + " 'ReferenceError', 'SyntaxError', 'TypeError',", + " 'URIError', 'JSON', 'Math',", + " 'console', 'Intl', 'ArrayBuffer',", + " 'Uint8Array', 'Int8Array', 'Uint16Array',", + " 'Int16Array', 'Uint32Array', 'Int32Array',", + " 'Float32Array', 'Float64Array', 'Uint8ClampedArray',", + " 'BigUint64Array', 'BigInt64Array', 'DataView',", + " 'Map', 'BigInt', 'Set',", + " 'WeakMap', 'WeakSet', 'Proxy',", + " 'Reflect', 'decodeURI', 'decodeURIComponent',", + " 'encodeURI', 'encodeURIComponent', 'escape',", + " 'unescape', 'eval', 'isFinite',", + " 'isNaN', 'SharedArrayBuffer', 'Atomics',", + " 'globalThis', 'WebAssembly', 'global',", + " 'process', 'GLOBAL', 'root',", + " 'Buffer', 'URL', 'URLSearchParams',", + " 'TextEncoder', 'TextDecoder', 'clearInterval',", + " 'clearTimeout', 'setInterval', 'setTimeout',", + " 'queueMicrotask', 'clearImmediate', 'setImmediate',", + " 'module', 'require', 'assert',", + " 'async_hooks', 'buffer', 'child_process',", + " 'cluster', 'crypto', 'dgram',", + " 'dns', 'domain', 'events',", + " 'fs', 'http', 'http2',", + " 'https', 'inspector', 'net',", + " 'os', 'path', 'perf_hooks',", + " 'punycode', 'querystring', 'readline',", + " 'repl', 'stream', 'string_decoder',", + " 'tls', 'trace_events', 'tty',", + " 'url', 'v8', 'vm',", + " 'worker_threads', 'zlib', '_',", + " '_error', 'util'", + ']' + ].join('\n'); + + assert.strictEqual(out, expected); } |