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

uucore: format: Pad non-finite numbers with spaces, not zeros

`printf "%05.2f" inf` should print `  inf`, not `00inf`.

Add a test to cover that case, too.
This commit is contained in:
Nicolas Boichat 2025-03-16 20:10:18 +01:00 committed by Sylvestre Ledru
parent ec450d602a
commit 25c492ee19
2 changed files with 27 additions and 2 deletions

View file

@ -990,6 +990,23 @@ fn float_flag_position_space_padding() {
.stdout_only(" +1.0");
}
#[test]
fn float_non_finite_space_padding() {
new_ucmd!()
.args(&["% 5.2f|% 5.2f|% 5.2f|% 5.2f", "inf", "-inf", "nan", "-nan"])
.succeeds()
.stdout_only(" inf| -inf| nan| -nan");
}
#[test]
fn float_non_finite_zero_padding() {
// Zero-padding pads non-finite numbers with spaces.
new_ucmd!()
.args(&["%05.2f|%05.2f|%05.2f|%05.2f", "inf", "-inf", "nan", "-nan"])
.succeeds()
.stdout_only(" inf| -inf| nan| -nan");
}
#[test]
fn float_abs_value_less_than_one() {
new_ucmd!()