Skip to content

Commit

Permalink
Merge pull request #3732 from cakebaker/numfmt_auto_suf_si_i
Browse files Browse the repository at this point in the history
numfmt: show "invalid suffix" error for "i" suffix
  • Loading branch information
sylvestre authored Jul 20, 2022
2 parents c5f35aa + 74bd9a2 commit ba24565
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/uu/numfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn parse_suffix(s: &str) -> Result<(f64, Option<Suffix>)> {
Some('E') => Some((RawSuffix::E, with_i)),
Some('Z') => Some((RawSuffix::Z, with_i)),
Some('Y') => Some((RawSuffix::Y, with_i)),
Some('0'..='9') => None,
Some('0'..='9') if !with_i => None,
_ => return Err(format!("invalid suffix in input: {}", s.quote())),
};

Expand Down
15 changes: 10 additions & 5 deletions tests/by-util/test_numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,16 @@ fn test_should_report_invalid_empty_number_on_blank_stdin() {

#[test]
fn test_should_report_invalid_suffix_on_stdin() {
new_ucmd!()
.args(&["--from=auto"])
.pipe_in("1k")
.run()
.stderr_is("numfmt: invalid suffix in input: '1k'\n");
for c in b'a'..=b'z' {
new_ucmd!()
.args(&["--from=auto"])
.pipe_in(format!("1{}", c as char))
.run()
.stderr_is(format!(
"numfmt: invalid suffix in input: '1{}'\n",
c as char
));
}

// GNU numfmt reports this one as “invalid number”
new_ucmd!()
Expand Down

0 comments on commit ba24565

Please sign in to comment.