Skip to content

Commit 8734c67

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 <[email protected]> PR-URL: #24166 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7920e7b commit 8734c67

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const common = require('../common');
66
constassert=require('assert');
77
const{ TextDecoder, TextEncoder }=require('util');
88
const{customInspectSymbol: inspect}=require('internal/util');
9+
constutil=require('util');
910

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

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

0 commit comments

Comments
(0)