From c6d2002ebd41556670280f93fc500349ff507254 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 6 Nov 2019 22:45:45 +0000 Subject: [PATCH] More fmt unit tests added --- test/unit_test/runtime/text_test.cpp | 37 ++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/test/unit_test/runtime/text_test.cpp b/test/unit_test/runtime/text_test.cpp index 9aeec6ca..64414bb4 100644 --- a/test/unit_test/runtime/text_test.cpp +++ b/test/unit_test/runtime/text_test.cpp @@ -567,15 +567,43 @@ TEST_CASE("format string with only %Q should print quantity value only", "[text] { SECTION("integral representation") { - REQUIRE(fmt::format("{:%Q}", 123kmph) == "123"); + SECTION("positive value") + { + REQUIRE(fmt::format("{:%Q}", 123kmph) == "123"); + } + + SECTION("negative value") + { + REQUIRE(fmt::format("{:%Q}", 5m - 10m) == "-5"); + } } SECTION("floating-point representation") { - SECTION("no precision specification") + SECTION("positive value") { REQUIRE(fmt::format("{:%Q}", 221.km / 2h) == "110.5"); } + + SECTION("negative value") + { + REQUIRE(fmt::format("{:%Q}", 3.14m - 10m) == "-6.86"); + } + + SECTION("nan") + { + REQUIRE(fmt::format("{:%Q}", quantity(std::numeric_limits::quiet_NaN())) == "nan"); + } + + SECTION("inf") + { + REQUIRE(fmt::format("{:%Q}", quantity(std::numeric_limits::infinity())) == "inf"); + } + + SECTION("-inf") + { + REQUIRE(fmt::format("{:%Q}", quantity(-std::numeric_limits::infinity())) == "-inf"); + } } } @@ -610,6 +638,11 @@ TEST_CASE("%q an %Q can be put anywhere in a format string", "[text][fmt]") { REQUIRE(fmt::format("{:%Q%n%q}", 123kmph) == "123\nkm/h"); } + + SECTION("% sign") + { + REQUIRE(fmt::format("{:%Q%% %q}", 123kmph) == "123% km/h"); + } } TEST_CASE("precision specification", "[text][fmt]")