From 5d041fda2d5fcd800290dcc800cb50d09e847ab6 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 27 Feb 2024 10:23:09 +0100 Subject: [PATCH] test: `unit_symbol()` and `dimension_symbol()` runtime unit tests added --- test/runtime/fmt_test.cpp | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/runtime/fmt_test.cpp b/test/runtime/fmt_test.cpp index 260b1a83..5c1c0ad8 100644 --- a/test/runtime/fmt_test.cpp +++ b/test/runtime/fmt_test.cpp @@ -882,6 +882,58 @@ TEST_CASE("localization with the 'L' specifier", "[text][fmt][localization]") } } +TEST_CASE("unit_symbol", "[text]") +{ + using enum text_encoding; + using enum unit_symbol_solidus; + using enum unit_symbol_separator; + + std::ostringstream os; + + SECTION("default formatting") + { + os << unit_symbol(m / s2); + CHECK(os.str() == "m/s²"); + } + + SECTION("ASCII mode") + { + os << unit_symbol(m / s2); + CHECK(os.str() == "m/s^2"); + } + + SECTION("solidus") + { + os << unit_symbol(m / s2); + CHECK(os.str() == "m s⁻²"); + } + + SECTION("separator") + { + os << unit_symbol(m / s2); + CHECK(os.str() == "m⋅s⁻²"); + } +} + +TEST_CASE("dimension_symbol", "[text]") +{ + using enum text_encoding; + + std::ostringstream os; + + SECTION("default formatting") + { + os << dimension_symbol(isq::power.dimension); + CHECK(os.str() == "L²MT⁻³"); + } + + SECTION("ASCII mode") + { + os << dimension_symbol(isq::power.dimension); + CHECK(os.str() == "L^2MT^-3"); + } +} + TEST_CASE("value_cast", "[text][ostream]") { std::ostringstream os;