mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
numfmt: show error if "i" suffix is missing
This commit is contained in:
parent
de65d4d649
commit
aef24db90f
2 changed files with 21 additions and 6 deletions
|
@ -98,7 +98,6 @@ fn parse_suffix(s: &str) -> Result<(f64, Option<Suffix>)> {
|
|||
|
||||
fn remove_suffix(i: f64, s: Option<Suffix>, u: &Unit) -> Result<f64> {
|
||||
match (s, u) {
|
||||
(None, _) => Ok(i),
|
||||
(Some((raw_suffix, false)), &Unit::Auto) | (Some((raw_suffix, false)), &Unit::Si) => {
|
||||
match raw_suffix {
|
||||
RawSuffix::K => Ok(i * 1e3),
|
||||
|
@ -123,6 +122,15 @@ fn remove_suffix(i: f64, s: Option<Suffix>, u: &Unit) -> Result<f64> {
|
|||
RawSuffix::Z => Ok(i * IEC_BASES[7]),
|
||||
RawSuffix::Y => Ok(i * IEC_BASES[8]),
|
||||
},
|
||||
(None, &Unit::Iec(true)) => Err(format!(
|
||||
"missing 'i' suffix in input: '{}' (e.g Ki/Mi/Gi)",
|
||||
i
|
||||
)),
|
||||
(Some((raw_suffix, false)), &Unit::Iec(true)) => Err(format!(
|
||||
"missing 'i' suffix in input: '{}{:?}' (e.g Ki/Mi/Gi)",
|
||||
i, raw_suffix
|
||||
)),
|
||||
(None, _) => Ok(i),
|
||||
(_, _) => Err("This suffix is unsupported for specified unit".to_owned()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,19 @@ fn test_from_iec_i() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore] // FIXME: GNU from iec-i requires suffix
|
||||
fn test_from_iec_i_requires_suffix() {
|
||||
new_ucmd!()
|
||||
.args(&["--from=iec-i", "1024"])
|
||||
.fails()
|
||||
.stderr_is("numfmt: missing 'i' suffix in input: '1024' (e.g Ki/Mi/Gi)");
|
||||
let numbers = vec!["1024", "10M"];
|
||||
|
||||
for number in numbers {
|
||||
new_ucmd!()
|
||||
.args(&["--from=iec-i", number])
|
||||
.fails()
|
||||
.code_is(2)
|
||||
.stderr_is(format!(
|
||||
"numfmt: missing 'i' suffix in input: '{}' (e.g Ki/Mi/Gi)",
|
||||
number
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue