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

Merge pull request #7323 from alexsnaps/issue-7219

numfmt: fix from iec-i without suffix are bytes
This commit is contained in:
Sylvestre Ledru 2025-02-19 09:41:20 +01:00 committed by GitHub
commit 447b087ec4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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::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!(
"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]
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 {
new_ucmd!()
.args(&["--from=iec-i", number])
.fails()
.code_is(2)
.stderr_is(format!(
"numfmt: missing 'i' suffix in input: '{number}' (e.g Ki/Mi/Gi)\n"
));
}
#[test]
fn test_from_iec_i_without_suffix_are_bytes() {
new_ucmd!()
.args(&["--from=iec-i", "1024"])
.succeeds()
.stdout_is("1024\n");
}
#[test]