diff options
| author | Stefan Boberg <[email protected]> | 2026-03-12 15:02:32 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-12 15:02:32 +0100 |
| commit | faaa8993405b85015fff202746c39ae0374505d8 (patch) | |
| tree | 4bff0ee5ee65c7fe7462b153563d170df1de6e83 /thirdparty/fmt/test/std-test.cc | |
| parent | 5.7.22 (diff) | |
| download | zen-faaa8993405b85015fff202746c39ae0374505d8.tar.xz zen-faaa8993405b85015fff202746c39ae0374505d8.zip | |
update fmt 12.0.0 -> 12.1.0 (#828)
- Update vendored fmt library from 12.0.0 to 12.1.0
- Disable warnings-as-errors for the fmt build target (third-party code)
## Notable changes in fmt 12.1.0
- **Performance**: Optimized `buffer::append`, resulting in up to ~16% improvement on spdlog benchmarks
- **Bug fixes**:
- Worked around ABI incompatibility in `std::locale_ref` between clang and gcc
- Fixed compilation with clang 21 and `-std=c++20`
- Fixed compilation with locales disabled in header-only mode
- Fixed dynamic linking issue with clang-cl
- Fixed compatibility with clang as host compiler for NVCC
- **Formatter improvements**:
- `std::variant` and `std::expected` formatters now work with `format_as`
- Added cv-qualified type support to `std::optional` formatter
- Added demangling support for libc++ and clang-cl
- **C++ modules**: Fixed several compatibility issues, exported `is_compiled_string` and `operator""_cf`
- **Other**: Switched to global `malloc`/`free` to enable allocator customization, made `FMT_USE_CONSTEVAL` user-configurable
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() { |