summaryrefslogtreecommitdiff
path: root/AK/Tests/TestFormat.cpp
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-04-08 18:50:56 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-08 20:30:56 +0200
commitc4e19250a17bf9145f0c033a556054f33b6ea54f (patch)
treea2a852484246cf61ece741ca9ae1429b4cea0bbd /AK/Tests/TestFormat.cpp
parent4bfd394384f06a791dd1221841d7c404e27aac62 (diff)
downloadserenity-c4e19250a17bf9145f0c033a556054f33b6ea54f.zip
Format: Strip trailing zeroes from floating point values
This is a pretty naive implementation that works well. The precision parameter is interpreted as "maximum precision" instead of "minimum precision", which in my opinion is the most useful interpretation.
Diffstat (limited to 'AK/Tests/TestFormat.cpp')
-rw-r--r--AK/Tests/TestFormat.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp
index a6a4c0b03a..22a754b424 100644
--- a/AK/Tests/TestFormat.cpp
+++ b/AK/Tests/TestFormat.cpp
@@ -252,11 +252,11 @@ TEST_CASE(file_descriptor)
TEST_CASE(floating_point_numbers)
{
- EXPECT_EQ(String::formatted("{}", 1.12), "1.120000");
- EXPECT_EQ(String::formatted("{}", 1.), "1.000000");
- EXPECT_EQ(String::formatted("{:.3}", 1.12), "1.120");
+ EXPECT_EQ(String::formatted("{}", 1.12), "1.12");
+ EXPECT_EQ(String::formatted("{}", 1.), "1");
+ EXPECT_EQ(String::formatted("{:.3}", 1.12), "1.12");
EXPECT_EQ(String::formatted("{:.1}", 1.12), "1.1");
- EXPECT_EQ(String::formatted("{}", -1.12), "-1.120000");
+ EXPECT_EQ(String::formatted("{}", -1.12), "-1.12");
// 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:
@@ -265,12 +265,12 @@ TEST_CASE(floating_point_numbers)
TEST_CASE(no_precision_no_trailing_number)
{
- EXPECT_EQ(String::formatted("{:.0}", 0.1), "0.");
+ EXPECT_EQ(String::formatted("{:.0}", 0.1), "0");
}
TEST_CASE(yay_this_implementation_sucks)
{
- EXPECT_EQ(String::formatted("{:.0}", .99999999999), "0.");
+ EXPECT_EQ(String::formatted("{:.0}", .99999999999), "0");
}
TEST_CASE(format_nullptr)