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

Fix #7219: from iec-i without suffix are bytes

Signed-off-by: Alex Snaps <alex@wcgw.dev>
This commit is contained in:
Alex Snaps 2025-02-18 17:17:29 -05:00
parent bc995283c4
commit 17a409532f
No known key found for this signature in database
GPG key ID: D95FB9EFA518E173
2 changed files with 12 additions and 13 deletions

View file

@ -135,9 +135,6 @@ fn remove_suffix(i: f64, s: Option<Suffix>, u: &Unit) -> Result<f64> {
RawSuffix::Z => Ok(i * IEC_BASES[7]), RawSuffix::Z => Ok(i * IEC_BASES[7]),
RawSuffix::Y => Ok(i * IEC_BASES[8]), RawSuffix::Y => Ok(i * IEC_BASES[8]),
}, },
(None, &Unit::Iec(true)) => {
Err(format!("missing 'i' suffix in input: '{i}' (e.g Ki/Mi/Gi)"))
}
(Some((raw_suffix, false)), &Unit::Iec(true)) => Err(format!( (Some((raw_suffix, false)), &Unit::Iec(true)) => Err(format!(
"missing 'i' suffix in input: '{i}{raw_suffix:?}' (e.g Ki/Mi/Gi)" "missing 'i' suffix in input: '{i}{raw_suffix:?}' (e.g Ki/Mi/Gi)"
)), )),

View file

@ -56,17 +56,19 @@ fn test_from_iec_i() {
#[test] #[test]
fn test_from_iec_i_requires_suffix() { fn test_from_iec_i_requires_suffix() {
let numbers = vec!["1024", "10M"]; new_ucmd!()
.args(&["--from=iec-i", "10M"])
.fails()
.code_is(2)
.stderr_is("numfmt: missing 'i' suffix in input: '10M' (e.g Ki/Mi/Gi)\n");
}
for number in numbers { #[test]
new_ucmd!() fn test_from_iec_i_without_suffix_are_bytes() {
.args(&["--from=iec-i", number]) new_ucmd!()
.fails() .args(&["--from=iec-i", "1024"])
.code_is(2) .succeeds()
.stderr_is(format!( .stdout_is("1024\n");
"numfmt: missing 'i' suffix in input: '{number}' (e.g Ki/Mi/Gi)\n"
));
}
} }
#[test] #[test]