From 8734c679f81c33e8d542944f829aa4c6caffa6eb Mon Sep 17 00:00:00 2001 From: ZauberNerd Date: Tue, 6 Nov 2018 16:40:53 +0100 Subject: [PATCH] test: add whatwg-encoding TextDecoder custom inspection with showHidden These tests ensure hidden fields are shown when inspecting with `showHidden` and that passing negative `depth` prints simplified value. Co-authored-by: Robin Drexler PR-URL: https://github.com/nodejs/node/pull/24166 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: Daijiro Wachi Reviewed-By: James M Snell --- .../test-whatwg-encoding-textdecoder.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/parallel/test-whatwg-encoding-textdecoder.js b/test/parallel/test-whatwg-encoding-textdecoder.js index 10f2c8ea0197e8..531368f0b731d2 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder.js +++ b/test/parallel/test-whatwg-encoding-textdecoder.js @@ -6,6 +6,7 @@ const common = require('../common'); const assert = require('assert'); const { TextDecoder, TextEncoder } = require('util'); const { customInspectSymbol: inspect } = require('internal/util'); +const util = require('util'); const buf = Buffer.from([0xef, 0xbb, 0xbf, 0x74, 0x65, 0x73, 0x74, 0xe2, 0x82, 0xac]); @@ -98,6 +99,42 @@ if (common.hasIntl) { assert.strictEqual(res, 'test€'); } +// Test TextDecoder inspect with hidden fields +{ + const dec = new TextDecoder('utf-8', { ignoreBOM: true }); + if (common.hasIntl) { + assert.strictEqual( + util.inspect(dec, { showHidden: true }), + 'TextDecoder {\n encoding: \'utf-8\',\n fatal: false,\n ' + + 'ignoreBOM: true,\n [Symbol(flags)]: 4,\n [Symbol(handle)]: {} }' + ); + } else { + assert.strictEqual( + util.inspect(dec, { showHidden: true }), + 'TextDecoder {\n encoding: \'utf-8\',\n fatal: false,\n ' + + 'ignoreBOM: true,\n [Symbol(flags)]: 4,\n [Symbol(handle)]:\n ' + + 'StringDecoder {\n encoding: \'utf8\',\n ' + + '[Symbol(kNativeDecoder)]: } }' + ); + } +} + + +// Test TextDecoder inspect without hidden fields +{ + const dec = new TextDecoder('utf-8', { ignoreBOM: true }); + assert.strictEqual( + util.inspect(dec, { showHidden: false }), + 'TextDecoder { encoding: \'utf-8\', fatal: false, ignoreBOM: true }' + ); +} + +// Test TextDecoder inspect with negative depth +{ + const dec = new TextDecoder(); + assert.strictEqual(util.inspect(dec, { depth: -1 }), '[Object]'); +} + { const inspectFn = TextDecoder.prototype[inspect]; const decodeFn = TextDecoder.prototype.decode;