Skip to content

Commit 8f18f0d

Browse files
ZauberNerdrobin-drexler
authored andcommitted
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 <drexler.robin@gmail.com> PR-URL: #24166 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6d147ef commit 8f18f0d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/parallel/test-whatwg-encoding-textdecoder.js

+37
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const common = require('../common');
55

66
const assert = require('assert');
77
const { customInspectSymbol: inspect } = require('internal/util');
8+
const util = require('util');
89

910
const buf = Buffer.from([0xef, 0xbb, 0xbf, 0x74, 0x65,
1011
0x73, 0x74, 0xe2, 0x82, 0xac]);
@@ -97,6 +98,42 @@ if (common.hasIntl) {
9798
assert.strictEqual(res, 'test€');
9899
}
99100

101+
// Test TextDecoder inspect with hidden fields
102+
{
103+
const dec = new TextDecoder('utf-8', { ignoreBOM: true });
104+
if (common.hasIntl) {
105+
assert.strictEqual(
106+
util.inspect(dec, { showHidden: true }),
107+
'TextDecoder {\n encoding: \'utf-8\',\n fatal: false,\n ' +
108+
'ignoreBOM: true,\n [Symbol(flags)]: 4,\n [Symbol(handle)]: {} }'
109+
);
110+
} else {
111+
assert.strictEqual(
112+
util.inspect(dec, { showHidden: true }),
113+
'TextDecoder {\n encoding: \'utf-8\',\n fatal: false,\n ' +
114+
'ignoreBOM: true,\n [Symbol(flags)]: 4,\n [Symbol(handle)]:\n ' +
115+
'StringDecoder {\n encoding: \'utf8\',\n ' +
116+
'[Symbol(kNativeDecoder)]: <Buffer 00 00 00 00 00 00 01> } }'
117+
);
118+
}
119+
}
120+
121+
122+
// Test TextDecoder inspect without hidden fields
123+
{
124+
const dec = new TextDecoder('utf-8', { ignoreBOM: true });
125+
assert.strictEqual(
126+
util.inspect(dec, { showHidden: false }),
127+
'TextDecoder { encoding: \'utf-8\', fatal: false, ignoreBOM: true }'
128+
);
129+
}
130+
131+
// Test TextDecoder inspect with negative depth
132+
{
133+
const dec = new TextDecoder();
134+
assert.strictEqual(util.inspect(dec, { depth: -1 }), '[Object]');
135+
}
136+
100137
{
101138
const inspectFn = TextDecoder.prototype[inspect];
102139
const decodeFn = TextDecoder.prototype.decode;

0 commit comments

Comments
 (0)