test: complete coverage of buffer#12831
Closed
DavidCai1111 wants to merge 1 commit intonodejs:masterfrom
Closed
Conversation
aqrln
approved these changes
May 4, 2017
Contributor
There was a problem hiding this comment.
I'd prefer the comment to start with a capital letter, but maybe it's just me, idk :)
test/parallel/test-buffer-write.js
Outdated
benjamingr
approved these changes
May 4, 2017
hiroppy
approved these changes
May 5, 2017
cjihrig
approved these changes
May 5, 2017
Contributor
There was a problem hiding this comment.
Could you use Buffer.isEncoding() here?
8da6576 to
3202a99
Compare
Member
Author
Member
Author
cjihrig
approved these changes
May 5, 2017
jasnell
approved these changes
May 5, 2017
addaleax
approved these changes
May 7, 2017
Member
|
Landed in a710e44 |
addaleax
pushed a commit
that referenced
this pull request
May 7, 2017
PR-URL: #12831 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
anchnk
pushed a commit
to anchnk/node
that referenced
this pull request
May 19, 2017
PR-URL: nodejs#12831 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
3 tasks
Member
|
Should this be backported to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Complete coverage of
lib/buffer.js. According to https://coverage.nodejs.org/coverage-ff001c12b032c33d/root/buffer.js.html , this PR adds the coverage for some missingbreakcases and oneutf-8case which are not get covered in #12714 .PS: When i was writing the test cases for those invalid encodings cases, i found that the way each
BufferAPI treats the invalid value of theencodingparameter seems quite inconsistent, for instance:Buffer.fromtreats all JavaScript falsy values and all other non-string values asutf8Buffer.from('foo', false)equalsBuffer.from('foo', 'utf8')Buffer.from('foo', 123)equalsBuffer.from('foo', 'utf8')buf.toStringonly treatsundefinedasutf8, and throws an error when comes to all other invalid valuesBuffer.from('foo').toString(undefined)equalsBuffer.from('foo').toString('utf8')Buffer.from('foo').toString('u')andBuffer.from('foo').toString(0)will throwbuf.writejust treats all JavaScript falsy value asutf8, and throws an error when comes to all other invalid valuesBuffer.alloc(9).write('foo', 0)equalsBuffer.alloc(9).write('foo', 'utf8')So shall we find a consistent way to deal with this invalid encoding parameter situation to avoid some potential confusions?
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
test