mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Merge pull request #5158 from cakebaker/nl_section_delimiter
nl: implement -d/--section-delimiter
This commit is contained in:
commit
035032cd83
3 changed files with 125 additions and 11 deletions
|
@ -2,7 +2,8 @@
|
|||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
// spell-checker:ignore binvalid finvalid hinvalid iinvalid linvalid ninvalid vinvalid winvalid
|
||||
//
|
||||
// spell-checker:ignore binvalid finvalid hinvalid iinvalid linvalid nabcabc nabcabcabc ninvalid vinvalid winvalid
|
||||
use crate::common::util::TestScenario;
|
||||
|
||||
#[test]
|
||||
|
@ -537,3 +538,83 @@ fn test_line_number_overflow() {
|
|||
.stdout_is(format!("{}\ta\n", i64::MIN))
|
||||
.stderr_is("nl: line number overflow\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_section_delimiter() {
|
||||
for arg in ["-dabc", "--section-delimiter=abc"] {
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\nabcabcabc\nb") // header section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n b\n");
|
||||
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\nabcabc\nb") // body section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n 1\tb\n");
|
||||
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\nabc\nb") // footer section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n b\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_one_char_section_delimiter_expansion() {
|
||||
for arg in ["-da", "--section-delimiter=a"] {
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\na:a:a:\nb") // header section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n b\n");
|
||||
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\na:a:\nb") // body section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n 1\tb\n");
|
||||
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\na:\nb") // footer section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n b\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_non_ascii_one_char_section_delimiter() {
|
||||
for arg in ["-dä", "--section-delimiter=ä"] {
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\näää\nb") // header section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n b\n");
|
||||
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\nää\nb") // body section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n 1\tb\n");
|
||||
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\nä\nb") // footer section
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n\n b\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_section_delimiter() {
|
||||
for arg in ["-d ''", "--section-delimiter=''"] {
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("a\n\nb")
|
||||
.succeeds()
|
||||
.stdout_is(" 1\ta\n \n 2\tb\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue