Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8734c67

Browse filesBrowse 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 7920e7b commit 8734c67
Copy full SHA for 8734c67

File tree

Expand file treeCollapse file tree

1 file changed

+37
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+37
-0
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-encoding-textdecoder.js
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const common = require('../common');
66
const assert = require('assert');
77
const { TextDecoder, TextEncoder } = require('util');
88
const { customInspectSymbol: inspect } = require('internal/util');
9+
const util = require('util');
910

1011
const buf = 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+
const dec = new TextDecoder('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+
const dec = new TextDecoder('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+
const dec = new TextDecoder();
135+
assert.strictEqual(util.inspect(dec, { depth: -1 }), '[Object]');
136+
}
137+
101138
{
102139
const inspectFn = TextDecoder.prototype[inspect];
103140
const decodeFn = TextDecoder.prototype.decode;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.