Skip to content

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

Rodrigo Muino Tomonari requested to merge github/fork/Trott/buffer-inspect into master

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

Merge request reports

Loading