Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

Trott
Copy link
Member

@Trott Trott commented Jun 16, 2015

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?

@Trott Trott added test Issues and PRs related to the tests. buffer Issues and PRs related to the buffer subsystem. labels Jun 16, 2015
utf8Slice = b.toString('utf8', offset, offset + Buffer.byteLength(utf8String));
assert.equal(utf8String, utf8Slice);

var sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String.length));
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, copy paste errors...

@Trott
Copy link
Member Author

Trott commented Jun 16, 2015

Pushed a new commit to fix error noted by @brendanashworth

// TODO utf8 slice tests
// UTF-8 slice test

var utf8String = '¡hèlló wôrld!';
Copy link
Contributor

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?

Copy link
Member Author

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 έ.

@Trott
Copy link
Member Author

Trott commented Jun 16, 2015

Pushed a new commit to include a multibyte character per feedback from @trevnorris

@trevnorris
Copy link
Contributor

Trott added a commit that referenced this pull request Jun 17, 2015
PR-URL: #1989
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@trevnorris
Copy link
Contributor

Landed in 0abcf44. Thanks much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants