1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

tac: correct behavior of -b option (#2523)

* tac: correct behavior of -b option

Correct the behavior of `tac -b` to match that of GNU coreutils
`tac`. Specifically, this changes `tac -b` to assume *leading* line
separators instead of the default *trailing* line separators.

Before this commit, the (incorrect) behavior was

    $ printf "/abc/def" | tac -b -s "/"
    def/abc/

After this commit, the behavior is

    $ printf "/abc/def" | tac -b -s "/"
    /def/abc

Fixes #2262.

* fixup! tac: correct behavior of -b option

* fixup! tac: correct behavior of -b option

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
jfinkels 2021-08-22 15:01:17 -04:00 committed by GitHub
parent 114c9a409c
commit 4ef35d4a96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 63 deletions

View file

@ -1,3 +1,4 @@
// spell-checker:ignore axxbxx bxxaxx
use crate::common::util::*;
#[test]
@ -23,7 +24,7 @@ fn test_stdin_non_newline_separator_before() {
.args(&["-b", "-s", ":"])
.pipe_in("100:200:300:400:500")
.run()
.stdout_is("500:400:300:200:100");
.stdout_is(":500:400:300:200100");
}
#[test]
@ -74,6 +75,56 @@ fn test_no_line_separators() {
new_ucmd!().pipe_in("a").succeeds().stdout_is("a");
}
#[test]
fn test_before_trailing_separator_no_leading_separator() {
new_ucmd!()
.arg("-b")
.pipe_in("a\nb\n")
.succeeds()
.stdout_is("\n\nba");
}
#[test]
fn test_before_trailing_separator_and_leading_separator() {
new_ucmd!()
.arg("-b")
.pipe_in("\na\nb\n")
.succeeds()
.stdout_is("\n\nb\na");
}
#[test]
fn test_before_leading_separator_no_trailing_separator() {
new_ucmd!()
.arg("-b")
.pipe_in("\na\nb")
.succeeds()
.stdout_is("\nb\na");
}
#[test]
fn test_before_no_separator() {
new_ucmd!()
.arg("-b")
.pipe_in("ab")
.succeeds()
.stdout_is("ab");
}
#[test]
fn test_before_empty_file() {
new_ucmd!().arg("-b").pipe_in("").succeeds().stdout_is("");
}
#[test]
fn test_multi_char_separator() {
new_ucmd!()
.args(&["-s", "xx"])
.pipe_in("axxbxx")
.succeeds()
.stdout_is("bxxaxx");
}
#[test]
fn test_null_separator() {
new_ucmd!()