Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 537d954

Browse filesBrowse files
hiroppyItalo A. Casas
authored andcommitted
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: #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>
1 parent 659428f commit 537d954
Copy full SHA for 537d954

File tree

Expand file treeCollapse file tree

2 files changed

+13
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-9
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-string-decoder-end.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-string-decoder-end.js
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ const assert = require('assert');
88
const SD = require('string_decoder').StringDecoder;
99
const encodings = ['base64', 'hex', 'utf8', 'utf16le', 'ucs2'];
1010

11-
const bufs = [ '☃💩', 'asdf' ].map(function(b) {
12-
return Buffer.from(b);
13-
});
11+
const bufs = [ '☃💩', 'asdf' ].map((b) => Buffer.from(b));
1412

1513
// also test just arbitrary bytes from 0-15.
1614
for (let i = 1; i <= 16; i++) {
17-
const bytes = new Array(i).join('.').split('.').map(function(_, j) {
18-
return j + 0x78;
19-
});
15+
const bytes = new Array(i).join('.').split('.').map((_, j) => j + 0x78);
2016
bufs.push(Buffer.from(bytes));
2117
}
2218

@@ -25,7 +21,7 @@ encodings.forEach(testEncoding);
2521
console.log('ok');
2622

2723
function testEncoding(encoding) {
28-
bufs.forEach(function(buf) {
24+
bufs.forEach((buf) => {
2925
testBuf(encoding, buf);
3026
});
3127
}
Collapse file

‎test/parallel/test-string-decoder.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-string-decoder.js
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ assert.strictEqual(decoder.write(Buffer.from('3DD8', 'hex')), '');
104104
assert.strictEqual(decoder.write(Buffer.from('4D', 'hex')), '');
105105
assert.strictEqual(decoder.end(), '\ud83d');
106106

107+
assert.throws(() => {
108+
new StringDecoder(1);
109+
}, /^Error: Unknown encoding: 1$/);
110+
111+
assert.throws(() => {
112+
new StringDecoder('test');
113+
}, /^Error: Unknown encoding: test$/);
114+
107115
// test verifies that StringDecoder will correctly decode the given input
108116
// buffer with the given encoding to the expected output. It will attempt all
109117
// possible ways to write() the input buffer, see writeSequences(). The
@@ -116,10 +124,10 @@ function test(encoding, input, expected, singleSequence) {
116124
} else {
117125
sequences = [singleSequence];
118126
}
119-
sequences.forEach(function(sequence) {
127+
sequences.forEach((sequence) => {
120128
const decoder = new StringDecoder(encoding);
121129
let output = '';
122-
sequence.forEach(function(write) {
130+
sequence.forEach((write) => {
123131
output += decoder.write(input.slice(write[0], write[1]));
124132
});
125133
output += decoder.end();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.