csplit: fix bug when --suppress-matched flag is active and positive/negative offset is present#7088
Merged
cakebaker merged 6 commits intouutils:mainfrom Jan 9, 2025
Merged
Conversation
…atched according to issue uutils#7052 and modified also test_up_to_match_negative_offset_option_suppress_matched
…d-matched flag is active
|
GNU testsuite comparison: |
…atched according to issue uutils#7052 and modified also test_up_to_match_negative_offset_option_suppress_matched
…d-matched flag is active
2796cc1 to
c1b9509
Compare
|
GNU testsuite comparison: |
cakebaker
reviewed
Jan 8, 2025
src/uu/csplit/src/csplit.rs
Outdated
Comment on lines
441
to
446
| } else { | ||
| // since offset_usize is for sure greater than 0 | ||
| // the first element of the buffer should be removed and this | ||
| // line inserted to be coherent with GNU implementation | ||
| input_iter.add_line_to_buffer(ln, l); | ||
| } |
Contributor
There was a problem hiding this comment.
A detail: I would swap the if and else blocks. It allows you to get rid of the ! in the condition for better readability.
…ils into csplit_suppressed_matched
Contributor
Author
|
Thanks, I have swapped the |
|
GNU testsuite comparison: |
Contributor
|
Thanks!
I don't remember what the error was then, sometimes it simply fails randomly :| |
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.
I modified the test cases
test_up_to_match_offset_option_suppress_matchedaccording to the issue #7052 and also the testtest_up_to_match_negative_offset_option_suppress_matchedbecause the output was different with the GNU implementation.The code should fix the bug:
In case of positive offset: the code checks if the offset is greater than 0, so the last line should be skipped
In case of negative offset: when the regex is matched, the first element of the buffer should be deleted and the current line inserted.