diff options
| author | Dan Engelbrecht <[email protected]> | 2026-03-23 20:39:32 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2026-03-23 20:39:32 +0100 |
| commit | 840b600525c7c6fd43395863c15ce955d9216b71 (patch) | |
| tree | 79e017fd6ced67650defddb3f10f40c6efc3d841 /thirdparty/fmt/test/std-test.cc | |
| parent | 5.7.25 (diff) | |
| parent | Cross-platform process metrics support (#887) (diff) | |
| download | zen-de/v5.7.25-hotpatch.tar.xz zen-de/v5.7.25-hotpatch.zip | |
Merge remote-tracking branch 'origin/main' into de/v5.7.25-hotpatchde/v5.7.25-hotpatch
Diffstat (limited to 'thirdparty/fmt/test/std-test.cc')
| -rw-r--r-- | thirdparty/fmt/test/std-test.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/thirdparty/fmt/test/std-test.cc b/thirdparty/fmt/test/std-test.cc index f5b4e7e85..18f6bd3fc 100644 --- a/thirdparty/fmt/test/std-test.cc +++ b/thirdparty/fmt/test/std-test.cc @@ -13,6 +13,7 @@ #include <vector> #include "fmt/os.h" // fmt::system_category +#include "fmt/ranges.h" #include "gtest-extra.h" // StartsWith #ifdef __cpp_lib_filesystem @@ -145,6 +146,7 @@ TEST(std_test, optional) { EXPECT_FALSE((fmt::is_formattable<unformattable>::value)); EXPECT_FALSE((fmt::is_formattable<std::optional<unformattable>>::value)); EXPECT_TRUE((fmt::is_formattable<std::optional<int>>::value)); + EXPECT_TRUE((fmt::is_formattable<std::optional<const int>>::value)); #endif } @@ -196,7 +198,33 @@ class my_class { return fmt::to_string(elm.av); } }; + +class my_class_int { + public: + int av; + + private: + friend auto format_as(const my_class_int& elm) -> int { return elm.av; } +}; } // namespace my_nso + +TEST(std_test, expected_format_as) { +#ifdef __cpp_lib_expected + EXPECT_EQ( + fmt::format( + "{}", std::expected<my_nso::my_number, int>{my_nso::my_number::one}), + "expected(\"first\")"); + EXPECT_EQ( + fmt::format("{}", + std::expected<my_nso::my_class, int>{my_nso::my_class{7}}), + "expected(\"7\")"); + EXPECT_EQ(fmt::format("{}", + std::expected<my_nso::my_class_int, int>{ + my_nso::my_class_int{8}}), + "expected(8)"); +#endif +} + TEST(std_test, optional_format_as) { #ifdef __cpp_lib_optional EXPECT_EQ(fmt::format("{}", std::optional<my_nso::my_number>{}), "none"); @@ -205,6 +233,8 @@ TEST(std_test, optional_format_as) { EXPECT_EQ(fmt::format("{}", std::optional<my_nso::my_class>{}), "none"); EXPECT_EQ(fmt::format("{}", std::optional{my_nso::my_class{7}}), "optional(\"7\")"); + EXPECT_EQ(fmt::format("{}", std::optional{my_nso::my_class_int{8}}), + "optional(8)"); #endif } @@ -274,6 +304,24 @@ TEST(std_test, variant) { #endif } +TEST(std_test, variant_format_as) { +#ifdef __cpp_lib_variant + + EXPECT_EQ(fmt::format("{}", std::variant<my_nso::my_number>{}), + "variant(\"first\")"); + EXPECT_EQ(fmt::format( + "{}", std::variant<my_nso::my_number>{my_nso::my_number::one}), + "variant(\"first\")"); + EXPECT_EQ( + fmt::format("{}", std::variant<my_nso::my_class>{my_nso::my_class{7}}), + "variant(\"7\")"); + EXPECT_EQ( + fmt::format("{}", + std::variant<my_nso::my_class_int>{my_nso::my_class_int{8}}), + "variant(8)"); +#endif +} + TEST(std_test, error_code) { auto& generic = std::generic_category(); EXPECT_EQ(fmt::format("{}", std::error_code(42, generic)), "generic:42"); @@ -288,6 +336,10 @@ TEST(std_test, error_code) { EXPECT_EQ(fmt::format("{:s}", ec), ec.message()); EXPECT_EQ(fmt::format("{:?}", std::error_code(42, generic)), "\"generic:42\""); + EXPECT_EQ(fmt::format("{}", + std::map<std::error_code, int>{ + {std::error_code(42, generic), 0}}), + "{\"generic:42\": 0}"); } template <typename Catch> void exception_test() { |