-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: increase coverage of string-decoder #10863
test: increase coverage of string-decoder #10863
Conversation
@@ -8,13 +8,13 @@ const assert = require('assert'); | |||
const SD = require('string_decoder').StringDecoder; | |||
const encodings = ['base64', 'hex', 'utf8', 'utf16le', 'ucs2']; | |||
|
|||
const bufs = [ '☃💩', 'asdf' ].map(function(b) { | |||
const bufs = [ '☃💩', 'asdf' ].map((b) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: This could just be (b) => Buffer.from(b)
. (The current code base does have a mixture of using {...}
and return
when it's not required vs. omitting them, so either should be fine, but omitting them is definitely more common.)
return Buffer.from(b); | ||
}); | ||
|
||
// also test just arbitrary bytes from 0-15. | ||
for (let i = 1; i <= 16; i++) { | ||
const bytes = new Array(i).join('.').split('.').map(function(_, j) { | ||
const bytes = new Array(i).join('.').split('.').map((_, j) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, this arrow function could be (_, j) => j + 0x78
if you like.
s/starting/string/ in commit message |
46a0454
to
7d5c020
Compare
7d5c020
to
075cb4b
Compare
Oops... updated. Thanks :) |
@@ -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(() => { | |||
decoder = new StringDecoder(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: does the linter complain if the assignment is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. I deleted the assignment.
075cb4b
to
bed8892
Compare
Make use of Arrow Function. Add normalizeencoding's test. normalizeEncoding: https://github.com/nodejs/node/blob/master/lib/string_decoder.js#L9
bed8892
to
dfebdc6
Compare
Landed in aebcc1a0d95b5f9e138da3c185c0ba25e5cd0fef |
@addaleax commit title seems a bit off: "starting-decoder"? |
@lpinca thanks for catching, force-pushed to fix 😅 |
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>
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>
Make use of Arrow Function. Add normalizeencoding's test. normalizeEncoding: https://github.com/nodejs/node/blob/master/lib/string_decoder.js#L9 PR-URL: nodejs#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>
Make use of Arrow Function. Add normalizeencoding's test. normalizeEncoding: https://github.com/nodejs/node/blob/master/lib/string_decoder.js#L9 PR-URL: nodejs#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>
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>
Landed in v6. This will need a backport PR if it needs to land on v4 |
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>
Add normalizeencoding's test.
normalizeEncoding: https://github.com/nodejs/node/blob/master/lib/string_decoder.js#L9
Make use of Arrow Function.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test