Skip to content

Commit d063ebc

Browse files
committed
numfmt: extract test from other test & expand it
1 parent 64dad0c commit d063ebc

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

tests/by-util/test_numfmt.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,31 @@ fn test_should_report_invalid_empty_number_on_blank_stdin() {
239239
}
240240

241241
#[test]
242-
fn test_should_report_invalid_suffix_on_stdin() {
243-
for c in b'a'..=b'z' {
244-
new_ucmd!()
245-
.args(&["--from=auto"])
246-
.pipe_in(format!("1{}", c as char))
247-
.fails()
248-
.stderr_is(format!(
249-
"numfmt: invalid suffix in input: '1{}'\n",
250-
c as char
251-
));
242+
fn test_suffixes() {
243+
// TODO add support for ronna (R) and quetta (Q)
244+
let valid_suffixes = ['K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' /*'R' , 'Q'*/];
245+
246+
// TODO implement special handling of 'K'
247+
for c in ('A'..='Z').into_iter().chain('a'..='z') {
248+
let args = ["--from=si", "--to=si", &format!("1{c}")];
249+
250+
if valid_suffixes.contains(&c) {
251+
new_ucmd!()
252+
.args(&args)
253+
.succeeds()
254+
.stdout_only(format!("1.0{c}\n"));
255+
} else {
256+
new_ucmd!()
257+
.args(&args)
258+
.fails()
259+
.code_is(2)
260+
.stderr_only(format!("numfmt: invalid suffix in input: '1{c}'\n"));
261+
}
252262
}
263+
}
253264

265+
#[test]
266+
fn test_should_report_invalid_suffix_on_nan() {
254267
// GNU numfmt reports this one as “invalid number”
255268
new_ucmd!()
256269
.args(&["--from=auto"])

0 commit comments

Comments
 (0)