diff options
author | abouthiroppy <git@about-hiroppy.com> | 2017-01-18 10:25:31 +0900 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-01-21 10:13:02 +0100 |
commit | 492163c74cf8ed5bf581231a348d75e61809b9a2 (patch) | |
tree | da2cfa63997620bbb1ce29ffc1a1d1c59edf4a34 /test/parallel/test-string-decoder.js | |
parent | 0c58193d1b1f9ac492a3fd44644e151996a94cb6 (diff) | |
download | android-node-v8-492163c74cf8ed5bf581231a348d75e61809b9a2.tar.gz android-node-v8-492163c74cf8ed5bf581231a348d75e61809b9a2.tar.bz2 android-node-v8-492163c74cf8ed5bf581231a348d75e61809b9a2.zip |
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>
Diffstat (limited to 'test/parallel/test-string-decoder.js')
-rw-r--r-- | test/parallel/test-string-decoder.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/test/parallel/test-string-decoder.js b/test/parallel/test-string-decoder.js index 77ffbfcc73..a8fdb999a0 100644 --- a/test/parallel/test-string-decoder.js +++ b/test/parallel/test-string-decoder.js @@ -104,6 +104,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 @@ -116,10 +124,10 @@ function test(encoding, input, expected, singleSequence) { } else { sequences = [singleSequence]; } - sequences.forEach(function(sequence) { + sequences.forEach((sequence) => { const decoder = new StringDecoder(encoding); let output = ''; - sequence.forEach(function(write) { + sequence.forEach((write) => { output += decoder.write(input.slice(write[0], write[1])); }); output += decoder.end(); |