test: add else and error case for TextDecoder

add test for tinyurl.com/codeandlearn-encoding-1
add test for tinyurl.com/codeandlearn-encoding-2

PR-URL: https://github.com/nodejs/node/pull/24162
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Lauri Piisang 2018-11-06 15:29:11 +00:00 committed by Gireesh Punathil
parent 368789fb20
commit 1d9ba7b19e
2 changed files with 20 additions and 0 deletions

View File

@ -88,3 +88,15 @@ bad.forEach((t) => {
assert(!new TextDecoder().fatal);
assert(new TextDecoder('utf-8', { fatal: true }).fatal);
}
{
const notArrayBufferViewExamples = [false, {}, 1, '', new Error()];
notArrayBufferViewExamples.forEach((invalidInputType) => {
common.expectsError(() => {
new TextDecoder(undefined, null).decode(invalidInputType);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
});
}

View File

@ -75,6 +75,14 @@ if (common.hasIntl) {
});
}
// Test TextDecoder, label undefined, options null
{
const dec = new TextDecoder(undefined, null);
assert.strictEqual(dec.encoding, 'utf-8');
assert.strictEqual(dec.fatal, false);
assert.strictEqual(dec.ignoreBOM, false);
}
// Test TextDecoder, UTF-16le
{
const dec = new TextDecoder('utf-16le');