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

Merge pull request #3713 from cakebaker/numfmt_missing_i_suffix

numfmt: show error if "i" suffix is missing
This commit is contained in:
Sylvestre Ledru 2022-07-13 10:35:22 +02:00 committed by GitHub
commit 4b27776237
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View file

@ -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()),
}
}

View file

@ -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]