mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
tail: fix off-by-one issue for +NUM args
Fix an off-by-one issue for `tail -c +NUM` and `tail -n +NUM` command line options.
This commit is contained in:
parent
dc02c36a6a
commit
bc29645531
2 changed files with 48 additions and 1 deletions
|
@ -348,3 +348,47 @@ fn test_negative_indexing() {
|
|||
fn test_sleep_interval() {
|
||||
new_ucmd!().arg("-s").arg("10").arg(FOOBAR_TXT).succeeds();
|
||||
}
|
||||
|
||||
|
||||
/// Test for reading all but the first NUM bytes: `tail -c +3`.
|
||||
#[test]
|
||||
fn test_positive_bytes() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "+3"])
|
||||
.pipe_in("abcde")
|
||||
.succeeds()
|
||||
.stdout_is("cde");
|
||||
}
|
||||
|
||||
|
||||
/// Test for reading all bytes, specified by `tail -c +0`.
|
||||
#[test]
|
||||
fn test_positive_zero_bytes() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "+0"])
|
||||
.pipe_in("abcde")
|
||||
.succeeds()
|
||||
.stdout_is("abcde");
|
||||
}
|
||||
|
||||
|
||||
/// Test for reading all but the first NUM lines: `tail -n +3`.
|
||||
#[test]
|
||||
fn test_positive_lines() {
|
||||
new_ucmd!()
|
||||
.args(&["-n", "+3"])
|
||||
.pipe_in("a\nb\nc\nd\ne\n")
|
||||
.succeeds()
|
||||
.stdout_is("c\nd\ne\n");
|
||||
}
|
||||
|
||||
|
||||
/// Test for reading all lines, specified by `tail -n +0`.
|
||||
#[test]
|
||||
fn test_positive_zero_lines() {
|
||||
new_ucmd!()
|
||||
.args(&["-n", "+0"])
|
||||
.pipe_in("a\nb\nc\nd\ne\n")
|
||||
.succeeds()
|
||||
.stdout_is("a\nb\nc\nd\ne\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue