From 92a291b71de716657102224bb32d1c3e410e8d14 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Fri, 7 Mar 2025 12:48:22 +0100 Subject: [PATCH] test: printf: Add nan, inf, negative zero Add a few end-to-end tests for printf of unusual floats (nan, infinity, negative zero). --- tests/by-util/test_printf.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/by-util/test_printf.rs b/tests/by-util/test_printf.rs index 5d1d300dd..098218d6c 100644 --- a/tests/by-util/test_printf.rs +++ b/tests/by-util/test_printf.rs @@ -886,6 +886,30 @@ fn float_with_zero_precision_should_pad() { .stdout_only("-01"); } +#[test] +fn float_non_finite() { + new_ucmd!() + .args(&[ + "%f %f %F %f %f %F", + "nan", + "-nan", + "nan", + "inf", + "-inf", + "inf", + ]) + .succeeds() + .stdout_only("nan -nan NAN inf -inf INF"); +} + +#[test] +fn float_zero_neg_zero() { + new_ucmd!() + .args(&["%f %f", "0.0", "-0.0"]) + .succeeds() + .stdout_only("0.000000 -0.000000"); +} + #[test] fn precision_check() { new_ucmd!()