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:
parent
bc995283c4
commit
17a409532f
2 changed files with 12 additions and 13 deletions
|
@ -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)"
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -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"];
|
|
||||||
|
|
||||||
for number in numbers {
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["--from=iec-i", number])
|
.args(&["--from=iec-i", "10M"])
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(2)
|
.code_is(2)
|
||||||
.stderr_is(format!(
|
.stderr_is("numfmt: missing 'i' suffix in input: '10M' (e.g Ki/Mi/Gi)\n");
|
||||||
"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]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue