mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
Merge pull request #3716 from cakebaker/numfmt_reject_suffix
numfmt: reject suffix if unit is "none"
This commit is contained in:
commit
8938b1f9e1
2 changed files with 22 additions and 0 deletions
|
@ -130,6 +130,12 @@ fn remove_suffix(i: f64, s: Option<Suffix>, u: &Unit) -> Result<f64> {
|
|||
"missing 'i' suffix in input: '{}{:?}' (e.g Ki/Mi/Gi)",
|
||||
i, raw_suffix
|
||||
)),
|
||||
(Some((raw_suffix, with_i)), &Unit::None) => Err(format!(
|
||||
"rejecting suffix in input: '{}{:?}{}' (consider using --from)",
|
||||
i,
|
||||
raw_suffix,
|
||||
if with_i { "i" } else { "" }
|
||||
)),
|
||||
(None, _) => Ok(i),
|
||||
(_, _) => Err("This suffix is unsupported for specified unit".to_owned()),
|
||||
}
|
||||
|
|
|
@ -646,3 +646,19 @@ fn test_invalid_unit_size() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_valid_but_forbidden_suffix() {
|
||||
let numbers = vec!["12K", "12Ki"];
|
||||
|
||||
for number in numbers {
|
||||
new_ucmd!()
|
||||
.arg(number)
|
||||
.fails()
|
||||
.code_is(2)
|
||||
.stderr_contains(format!(
|
||||
"rejecting suffix in input: '{}' (consider using --from)",
|
||||
number
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue