diff options
author | asynts <asynts@gmail.com> | 2020-11-09 11:34:44 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-09 16:21:29 +0100 |
commit | 32957745fbc86addd43a56dde979a9d19ef42f0f (patch) | |
tree | f8ffed95deacbc455fd1b4760d3c67466485b39e /AK/Tests/TestFormat.cpp | |
parent | 3b3edbc4d207758e4451568341be07ae53d80418 (diff) | |
download | serenity-32957745fbc86addd43a56dde979a9d19ef42f0f.zip |
AK: Add formatters for floating point numbers.
Diffstat (limited to 'AK/Tests/TestFormat.cpp')
-rw-r--r-- | AK/Tests/TestFormat.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp index d31858e9ec..23431cf730 100644 --- a/AK/Tests/TestFormat.cpp +++ b/AK/Tests/TestFormat.cpp @@ -235,4 +235,27 @@ TEST_CASE(file_descriptor) fclose(file); } +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}", 1.12), "1.1"); + EXPECT_EQ(String::formatted("{}", -1.12), "-1.120000"); + + // 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"); +} + +TEST_CASE(no_precision_no_trailing_number) +{ + EXPECT_EQ(String::formatted("{:.0}", 0.1), "0."); +} + +TEST_CASE(yay_this_implementation_sucks) +{ + EXPECT_EQ(String::formatted("{:.0}", .99999999999), "0."); +} + TEST_MAIN(Format) |