From db38cf27c236dee8f4f112809c8cc9870bf32ac4 Mon Sep 17 00:00:00 2001 From: Emil Sivervik Date: Sun, 3 Jan 2021 13:16:22 +0100 Subject: [PATCH] test: increase inspect coverage 1. Truncate output for Primitives with 1 character left Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/internal/util/inspect.js.html#L1359 2. Truncate output for ArrayBuffers using plural or singular bytes Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/internal/util/inspect.js.html#L1465 PR-URL: https://github.com/nodejs/node/pull/36755 Reviewed-By: Zijian Liu Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum --- test/parallel/test-util-inspect.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 4e4ef3f30df952..8314b64c5ac345 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -210,6 +210,17 @@ assert(!/Object/.test( 'ArrayBuffer { (detached), byteLength: 0 }'); } +// Truncate output for ArrayBuffers using plural or singular bytes +{ + const ab = new ArrayBuffer(3); + assert.strictEqual(util.inspect(ab, { showHidden: true, maxArrayLength: 2 }), + 'ArrayBuffer { [Uint8Contents]' + + ': <00 00 ... 1 more byte>, byteLength: 3 }'); + assert.strictEqual(util.inspect(ab, { showHidden: true, maxArrayLength: 1 }), + 'ArrayBuffer { [Uint8Contents]' + + ': <00 ... 2 more bytes>, byteLength: 3 }'); +} + // Now do the same checks but from a different context. { const showHidden = false; @@ -2915,6 +2926,12 @@ assert.strictEqual( assert.strictEqual(inspect(undetectable), '{}'); } +// Truncate output for Primitives with 1 character left +{ + assert.strictEqual(util.inspect('bl', { maxStringLength: 1 }), + "'b'... 1 more character"); +} + { const x = 'a'.repeat(1e6); assert(util.inspect(x).endsWith('... 990000 more characters'));