Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: TextDecoder custom inspection #24166

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions test/parallel/test-whatwg-encoding-textdecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const common = require('../common');

const assert = require('assert');
const { customInspectSymbol: inspect } = require('internal/util');
const util = require('util');

const buf = Buffer.from([0xef, 0xbb, 0xbf, 0x74, 0x65,
0x73, 0x74, 0xe2, 0x82, 0xac]);
Expand Down Expand Up @@ -97,6 +98,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)]: <Buffer 00 00 00 00 00 00 01> } }'
);
}
}


// 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;
Expand Down