Skip to content

Commit c533d94

Browse files
committed
test: printf: Add nan, inf, negative zero
Add a few end-to-end tests for printf of unusual floats (nan, infinity, negative zero).
1 parent f86f46f commit c533d94

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/by-util/test_printf.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,30 @@ fn float_with_zero_precision_should_pad() {
878878
.stdout_only("-01");
879879
}
880880

881+
#[test]
882+
fn float_non_finite() {
883+
new_ucmd!()
884+
.args(&[
885+
"%f %f %F %f %f %F",
886+
"nan",
887+
"-nan",
888+
"nan",
889+
"inf",
890+
"-inf",
891+
"inf",
892+
])
893+
.succeeds()
894+
.stdout_only("nan -nan NAN inf -inf INF");
895+
}
896+
897+
#[test]
898+
fn float_zero_neg_zero() {
899+
new_ucmd!()
900+
.args(&["%f %f", "0.0", "-0.0"])
901+
.succeeds()
902+
.stdout_only("0.000000 -0.000000");
903+
}
904+
881905
#[test]
882906
fn precision_check() {
883907
new_ucmd!()

0 commit comments

Comments
 (0)