mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
nl: show error if --number-width is zero
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
parent
8e8b825b45
commit
826adc62aa
3 changed files with 42 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
// spell-checker:ignore ninvalid
|
||||
// spell-checker:ignore ninvalid winvalid
|
||||
use crate::common::util::TestScenario;
|
||||
|
||||
#[test]
|
||||
|
@ -122,3 +122,37 @@ fn test_invalid_number_format() {
|
|||
.stderr_contains("invalid value 'invalid'");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_width() {
|
||||
for width in 1..10 {
|
||||
for arg in [format!("-w{width}"), format!("--number-width={width}")] {
|
||||
let spaces = " ".repeat(width - 1);
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.pipe_in("test")
|
||||
.succeeds()
|
||||
.stdout_is(format!("{spaces}1\ttest\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_width_zero() {
|
||||
for arg in ["-w0", "--number-width=0"] {
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.fails()
|
||||
.stderr_contains("Invalid line number field width: ‘0’: Numerical result out of range");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_number_width() {
|
||||
for arg in ["-winvalid", "--number-width=invalid"] {
|
||||
new_ucmd!()
|
||||
.arg(arg)
|
||||
.fails()
|
||||
.stderr_contains("invalid value 'invalid'");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue