Skip to content

Commit

Permalink
test: add whatwg-encoding TextDecoder custom inspection with showHidden
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and codebytere committed Jan 29, 2019
1 parent 7920e7b commit 8734c67
Showing 1 changed file with 37 additions and 0 deletions.
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 @@ -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]);
Expand Down Expand Up @@ -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)]: <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

0 comments on commit 8734c67

Please sign in to comment.