Skip to content

buffer: add tests for Buffer.prototype.inspect() and refactor#11600

Closed
Trott wants to merge 2 commits intonodejs:masterfrom
Trott:buffer-inspect
Closed

buffer: add tests for Buffer.prototype.inspect() and refactor#11600
Trott wants to merge 2 commits intonodejs:masterfrom
Trott:buffer-inspect

Conversation

@Trott
Copy link
Member

@Trott Trott commented Feb 28, 2017

First commit: lib/buffer.js defines Buffer.prototype.inspect() to override how buffers are presented by util.inspect(). Add basic tests for it. (This test completes code coverage for the function. Previously, the condition where the this.length > 0 was always true during test runs. This adds a test where it will be false.)

Second commit: Now that tests are in place, refactor. Replace toString().match().join() with toString().replace().trim(). This enables the elimination of a length check becuase replace() will return empty string if Buffer is empty whereas match() returns null. (To be clear, I don't think the .length check is a performance liability or anything like that. I just think that fewer logic branches usually makes for code that is easier to understand.)

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

buffer test

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

8 participants