mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
test: increase coverage of string-decoder
Make use of Arrow Function. Add normalizeencoding's test. normalizeEncoding: https://github.com/nodejs/node/blob/master/lib/string_decoder.js#L9 PR-URL: https://github.com/nodejs/node/pull/10863 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
cda593774f
commit
9ac22cdcaf
2 files changed
+16
-12
No files matched your search
@@ -107,6 +107,14 @@ assert.strictEqual(decoder.write(Buffer.from('3DD8', 'hex')), '');
|
||||
assert.strictEqual(decoder.write(Buffer.from('4D', 'hex')), '');
|
||||
assert.strictEqual(decoder.end(), '\ud83d');
|
||||
|
||||
assert.throws(() => {
|
||||
new StringDecoder(1);
|
||||
}, /^Error: Unknown encoding: 1$/);
|
||||
|
||||
assert.throws(() => {
|
||||
new StringDecoder('test');
|
||||
}, /^Error: Unknown encoding: test$/);
|
||||
|
||||
// test verifies that StringDecoder will correctly decode the given input
|
||||
// buffer with the given encoding to the expected output. It will attempt all
|
||||
// possible ways to write() the input buffer, see writeSequences(). The
|
||||
@@ -119,10 +127,10 @@ function test(encoding, input, expected, singleSequence) {
|
||||
} else {
|
||||
sequences = [singleSequence];
|
||||
}
|
||||
sequences.forEach(function(sequence) {
|
||||
var decoder = new StringDecoder(encoding);
|
||||
var output = '';
|
||||
sequence.forEach(function(write) {
|
||||
sequences.forEach((sequence) => {
|
||||
const decoder = new StringDecoder(encoding);
|
||||
let output = '';
|
||||
sequence.forEach((write) => {
|
||||
output += decoder.write(input.slice(write[0], write[1]));
|
||||
});
|
||||
output += decoder.end();
|
||||
|
||||
Reference in new issue
Block a user