Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-05-03 17:46:03 +0200
committerGitHub2019-05-03 17:46:03 +0200
commit92ad9ee355945a4f2b494d1934faaa4bb412ae40 (patch)
tree0d51a85922fbe7f9abee77d3e3a36a3fc2d13e04 /projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
parent9c741fe96073ed620ffc032afbed1f3c789d2b68 (diff)
parente2862a8d7150da6afd13b6af58c79d4d06a024eb (diff)
downloadcatch3-92ad9ee355945a4f2b494d1934faaa4bb412ae40.tar.gz
Merge pull request #1614 from mlimber/master
Allow custom precision in error reports for floating-point numbers
Diffstat (limited to 'projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp')
-rw-r--r--projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
index 09ac3045..69d6320d 100644
--- a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
+++ b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
@@ -128,6 +128,40 @@ TEST_CASE("String views are stringified like other strings", "[toString][approva
#endif
+TEST_CASE("Precision of floating point stringification can be set", "[toString][floatingPoint]") {
+ SECTION("Floats") {
+ using sm = Catch::StringMaker<float>;
+ const auto oldPrecision = sm::precision;
+
+ const float testFloat = 1.12345678901234567899f;
+ auto str1 = sm::convert(testFloat);
+ sm::precision = 5;
+ // "1." prefix = 2 chars, f suffix is another char
+ CHECK(str1.size() == 3 + 5);
+
+ sm::precision = 10;
+ auto str2 = sm::convert(testFloat);
+ REQUIRE(str2.size() == 3 + 10);
+ sm::precision = oldPrecision;
+ }
+ SECTION("Double") {
+ using sm = Catch::StringMaker<double>;
+ const auto oldPrecision = sm::precision;
+
+ const double testDouble = 1.123456789012345678901234567899;
+ sm::precision = 5;
+ auto str1 = sm::convert(testDouble);
+ // "1." prefix = 2 chars
+ CHECK(str1.size() == 2 + 5);
+
+ sm::precision = 15;
+ auto str2 = sm::convert(testDouble);
+ REQUIRE(str2.size() == 2 + 15);
+
+ sm::precision = oldPrecision;
+ }
+}
+
namespace {
struct WhatException : std::exception {