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: update test-buffer-alloc to use template literals #15867

Closed
wants to merge 2 commits into from

Conversation

bwhitty
Copy link
Contributor

@bwhitty bwhitty commented Oct 6, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

tests

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Oct 6, 2017
@bwhitty bwhitty changed the title update test-buffer-alloc to use template literals test: update test-buffer-alloc to use template literals Oct 6, 2017
@bwhitty bwhitty force-pushed the test-buffer-alloc-tpl-lit branch from 4705507 to 3f1b1f5 Compare October 6, 2017 19:14
@mscdex mscdex added the buffer Issues and PRs related to the buffer subsystem. label Oct 6, 2017
@Trott Trott added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Oct 6, 2017
Updated a single usage of string concatenation to use template literals.
There are other usages of string concatenation in this file, but they
are used to make test code more readable.
@bwhitty bwhitty force-pushed the test-buffer-alloc-tpl-lit branch from 3f1b1f5 to 34e7486 Compare October 6, 2017 23:14
Trott
Trott previously requested changes Oct 9, 2017
Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

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

Hi @bwhitty! Welcome and thanks for this!

This change adds leading white space to each line of the string (except the first). What do you think of something more like this?:

const expectedWhite = `${expected.slice(0, 60)}\n` +
                       `${expected.slice(60, 120)}\n` +
...

Alternatively, you can put all the expected.slice() calls into an array and use .join('\n') on the array. (You'll still need to append on '\n' at the end of the array in that case.)

@bwhitty
Copy link
Contributor Author

bwhitty commented Oct 10, 2017

Hey @Trott ! Thanks for the review. This code appears to specifically be testing that whitespace is ignored (see the comment right above my diff) and the test continues to pass... I guess I'd argue this change is actually keeping the test assertion the same, just with more whitespace, and moderately more readable code.

Changing anything in this file to use tpl strings is sketchy at best as it's Buffer tests and so is quite sensitive to even a single char change. Maybe we shouldn't touch this file's tests at all...

What do you think?

@Trott
Copy link
Member

Trott commented Oct 11, 2017

I think this is the way to go:

const expectedWhite = `${expected.slice(0, 60)}\n` +
                       `${expected.slice(60, 120)}\n` +
...

It preserves the exact string already used in the test but gets rid of concatenation within lines.

@bwhitty
Copy link
Contributor Author

bwhitty commented Oct 16, 2017

Fixed up, @Trott !

It still makes me feel uncomfortable that my first change did not cause the tests to fail.

@joyeecheung
Copy link
Member

@jasnell
Copy link
Member

jasnell commented Oct 16, 2017

It all looks unrelated, but there's a bit too much red in that last CI run: https://ci.nodejs.org/job/node-test-pull-request/10759/

@BridgeAR
Copy link
Member

Ping @Trott

@BridgeAR BridgeAR dismissed Trott’s stale review October 18, 2017 20:41

Comment got addressed. Just removing the review to land this.

@BridgeAR
Copy link
Member

Landed in e021de3

Thanks for the PR, and congratulations on becoming a Node.js Contributor 🎉 !

@BridgeAR BridgeAR closed this Oct 19, 2017
BridgeAR pushed a commit that referenced this pull request Oct 19, 2017
PR-URL: #15867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@Trott
Copy link
Member

Trott commented Oct 21, 2017

It still makes me feel uncomfortable that my first change did not cause the tests to fail.

base64 encoding in Buffer.prototype.write() seems to be unaffected by whitespace. I can believe that is correct behavior.

MylesBorins pushed a commit that referenced this pull request Oct 23, 2017
PR-URL: #15867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
PR-URL: nodejs/node#15867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 16, 2017
PR-URL: #15867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Nov 21, 2017
MylesBorins pushed a commit that referenced this pull request Nov 21, 2017
PR-URL: #15867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 28, 2017
PR-URL: #15867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
PR-URL: nodejs/node#15867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
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. code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants