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

Merge pull request #7694 from drinkcat/printf-fix-empty

uucore: parser: num_parser: Return error if no digit has been parsed
uucore: parser: num_parser: Ignore empty exponents
uucore: parser: num_parser: Parse "0x"/"0b" as PartialMatch
This commit is contained in:
Dorian Péron 2025-04-16 23:32:39 +02:00 committed by GitHub
commit 349e56897c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 246 additions and 13 deletions

View file

@ -826,6 +826,12 @@ fn partial_integer() {
.fails_with_code(1)
.stdout_is("42 is a lot")
.stderr_is("printf: '42x23': value not completely converted\n");
new_ucmd!()
.args(&["%d is not %s", "0xwa", "a lot"])
.fails_with_code(1)
.stdout_is("0 is not a lot")
.stderr_is("printf: '0xwa': value not completely converted\n");
}
#[test]
@ -1280,6 +1286,80 @@ fn float_switch_switch_decimal_scientific() {
.stdout_only("1e-05");
}
#[test]
fn float_arg_zero() {
new_ucmd!()
.args(&["%f", "0."])
.succeeds()
.stdout_only("0.000000");
new_ucmd!()
.args(&["%f", ".0"])
.succeeds()
.stdout_only("0.000000");
new_ucmd!()
.args(&["%f", ".0e100000"])
.succeeds()
.stdout_only("0.000000");
}
#[test]
fn float_arg_invalid() {
// Just a dot fails.
new_ucmd!()
.args(&["%f", "."])
.fails()
.stdout_is("0.000000")
.stderr_contains("expected a numeric value");
new_ucmd!()
.args(&["%f", "-."])
.fails()
.stdout_is("0.000000")
.stderr_contains("expected a numeric value");
// Just an exponent indicator fails.
new_ucmd!()
.args(&["%f", "e"])
.fails()
.stdout_is("0.000000")
.stderr_contains("expected a numeric value");
// No digit but only exponent fails
new_ucmd!()
.args(&["%f", ".e12"])
.fails()
.stdout_is("0.000000")
.stderr_contains("expected a numeric value");
// No exponent partially fails
new_ucmd!()
.args(&["%f", "123e"])
.fails()
.stdout_is("123.000000")
.stderr_contains("value not completely converted");
// Nothing past `0x` parses as zero
new_ucmd!()
.args(&["%f", "0x"])
.fails()
.stdout_is("0.000000")
.stderr_contains("value not completely converted");
new_ucmd!()
.args(&["%f", "0x."])
.fails()
.stdout_is("0.000000")
.stderr_contains("value not completely converted");
new_ucmd!()
.args(&["%f", "0xp12"])
.fails()
.stdout_is("0.000000")
.stderr_contains("value not completely converted");
}
#[test]
fn float_arg_with_whitespace() {
new_ucmd!()