Bug fixes and improvements for corner cases#89
Merged
bitfield merged 4 commits intobitfield:masterfrom Jan 1, 2022
Merged
Conversation
Author
|
@bitfield Hi, would you please take a look at this pull request? Many thanks. |
Fix the defect that Column crashes on zero or negative input. Fix the defect that Last() crashes on negative input; Fix the defect that Regex filters crashes on nil regex expression; Add unit test for WithError(); close the pipe when a non-nil error is set; Add ExecForEach, Reject(), and RejectRegexp to doMethodsOnPipe tests; Improve coverage by adding equal counts in the testcase of Freq; Use io.Copy() in Stdout() to improve efficiency.
Previously, pipes always wrote to os.Stdout on calling Stdout(). This made it awkward to test. Now you can set a 'fake stdout' by calling WithStdout(io.Writer) on the pipe.
a78c3cf to
6189603
Compare
Owner
|
Excellent work @gty929, thanks a lot! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When working on #88 , I noticed some defects in the current library, so I'd like to submit this separate patch, which does the following:
Fix the defect that Column() crashes on zero or a negative input
The library panics when the following code is run
After the change, the program will return an empty pipe.
Fix the defect that Last() crashes on a negative input
The library panics when the following code is run
After the change, the program will return an empty pipe.
Fix the defect that Regex filters crash on a nil regex expression
The library panics when the following code is run
After the change, the program will return a pipe with the error "nil regular expression"
Add unit test for WithError(); close the pipe when a non-nil error is set
When fixing the regex defect, I just wrote
Then, I realized that
pwill not be automatically closed, since the subsequent filters and sinks will catch the error and return immediately. To fix this problem and prevent contributors from making the same mistake in the future, I think the best approach is to just close the pipe reader when a non-nil error is set.Add ExecForEach, Reject(), and RejectRegexp to doMethodsOnPipe tests
Just some jobs that previous contributors forgot.
Improve coverage by adding equal counts in the test case of Freq
To test that lines are sorted in alphabetical order when there is a tie.
Use io.Copy() in Stdout() to improve efficiency
It seems unnecessary to write the pipe's reader into a string and then print it.
By the way, after all the changes, the total line coverage has risen from 92.7% to 93.8%.