diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2021-10-30 10:43:21 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-31 12:15:34 +0100 |
commit | fed9cb5d2d3833c02b27abb4a4e19fed85a6c27e (patch) | |
tree | 8b1d566463331c249a86cec48322b59d71937f68 /Tests/AK/TestFormat.cpp | |
parent | 2c93ee50cd7b247bf01c6f6fabd3ae441d742ea8 (diff) | |
download | serenity-fed9cb5d2d3833c02b27abb4a4e19fed85a6c27e.zip |
AK+Tests: Fix formatting of infinity and NaN values
When I added this code in 1472f6d, I forgot to add tests for it. That's
why I didn't realize that the values were appended to the wrong
FormatBuilder object, so an empty string was returned instead of the
expected "nan"/"inf". This made debugging some FPU issues with the
ScummVM port significantly more difficult.
Diffstat (limited to 'Tests/AK/TestFormat.cpp')
-rw-r--r-- | Tests/AK/TestFormat.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Tests/AK/TestFormat.cpp b/Tests/AK/TestFormat.cpp index a4cc1f642f..dcae6d3c07 100644 --- a/Tests/AK/TestFormat.cpp +++ b/Tests/AK/TestFormat.cpp @@ -9,6 +9,7 @@ #include <AK/String.h> #include <AK/StringBuilder.h> #include <AK/Vector.h> +#include <math.h> TEST_CASE(is_integral_works_properly) { @@ -241,6 +242,10 @@ TEST_CASE(floating_point_numbers) EXPECT_EQ(String::formatted("{:.1}", 1.12), "1.1"); EXPECT_EQ(String::formatted("{}", -1.12), "-1.12"); + EXPECT_EQ(String::formatted("{}", NAN), "nan"); + EXPECT_EQ(String::formatted("{}", INFINITY), "inf"); + EXPECT_EQ(String::formatted("{}", -INFINITY), "-inf"); + // FIXME: There is always the question what we mean with the width field. Do we mean significant digits? // Do we mean the whole width? This is what was the simplest to implement: EXPECT_EQ(String::formatted("{:x>5.1}", 1.12), "xx1.1"); |