-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: add Buffer slice UTF-8 test #1989
Conversation
utf8Slice = b.toString('utf8', offset, offset + Buffer.byteLength(utf8String)); | ||
assert.equal(utf8String, utf8Slice); | ||
|
||
var sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String.length)); |
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.
Are you sure the Buffer.byteLength
call is what you want here? It will coerce the length to a string, then give you the length of that.
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.
Ah, copy paste errors...
Pushed a new commit to fix error noted by @brendanashworth |
// TODO utf8 slice tests | ||
// UTF-8 slice test | ||
|
||
var utf8String = '¡hèlló wôrld!'; |
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.
These characters are all within the latin-1 charset. check via
Buffer('¡hèlló wôrld!','binary').toString('binary') === '¡hèlló wôrld!'
Mind using a two byte utf-8 character?
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.
OK, changed the è to an έ.
Pushed a new commit to include a multibyte character per feedback from @trevnorris |
PR-URL: #1989 Reviewed-By: Trevor Norris <[email protected]>
Landed in 0abcf44. Thanks much. |
Gets rid of another
TODO
comment in the tests.Thing is, I'm not sure this is really needed. There seem to be things in other places in this test file that would trigger
utf8Slice()
, at least on casual inspection.So...@chrisdickinson: I know you ran some code coverage analysis recently. Any chance you could run code coverage on just the one file that's changed here and compare it to the results with the version in master to see if this change results in slightly more coverage? Or point me at the code coverage tool you used and I'll try to get up and running with it to do this myself?