From ab08bce982a00b04015fb09db90f9153813d7154 Mon Sep 17 00:00:00 2001 From: Ivan Lazaric Date: Sun, 27 Sep 2026 14:06:21 +0200 Subject: [PATCH] Update tests to use `FMT_CONSTEXPR` and `FMT_USE_CONSTEXPR_STRING`. --- test/compile-test.cc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/test/compile-test.cc b/test/compile-test.cc index 77a7bce2..bb59459a 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -495,26 +495,36 @@ TEST(compile_test, format_as) { EXPECT_EQ("[42]", fmt::format(FMT_COMPILE("[{}]"), type_with_format_as{42})); } -#if FMT_CPLUSPLUS >= 202000L -struct consteval_printable {}; +struct constexpr_enabled {}; -template<> -struct fmt::formatter { +template <> struct fmt::formatter { bool debug = false; - consteval auto parse(auto& ctx) { + FMT_CONSTEXPR auto parse(auto& ctx) { if (ctx.begin() != ctx.end() && *ctx.begin() == '?') { debug = true; ctx.advance_to(ctx.begin() + 1); } return ctx.begin(); } - consteval auto format(consteval_printable, auto& ctx) const { - return fmt::formatter{}.format(debug ? "debug" : "regular", ctx); + FMT_CONSTEXPR auto format(constexpr_enabled, auto& ctx) const { + return fmt::formatter{}.format( + debug ? "debug" : "regular", ctx); } }; -static_assert(fmt::format(FMT_COMPILE("{}"), consteval_printable{}) == "regular"); -static_assert(fmt::format(FMT_COMPILE("[{}]"), consteval_printable{}) == "[regular]"); -static_assert(fmt::format(FMT_COMPILE("{:?}"), consteval_printable{}) == "debug"); -static_assert(fmt::format(FMT_COMPILE("[{:?}]"), consteval_printable{}) == "[debug]"); -#endif // FMT_CPLUSPLUS >= 202000L +TEST(compile_test, constexpr_enabled_runtime_form) { + EXPECT_EQ("regular", fmt::format(FMT_COMPILE("{}"), constexpr_enabled{})); + EXPECT_EQ("[regular]", fmt::format(FMT_COMPILE("[{}]"), constexpr_enabled{})); + EXPECT_EQ("debug", fmt::format(FMT_COMPILE("{:?}"), constexpr_enabled{})); + EXPECT_EQ("[debug]", fmt::format(FMT_COMPILE("[{:?}]"), constexpr_enabled{})); +} + +// constexpr_enabled compile time form +#if FMT_USE_CONSTEXPR_STRING +static_assert(fmt::format(FMT_COMPILE("{}"), constexpr_enabled{}) == "regular"); +static_assert(fmt::format(FMT_COMPILE("[{}]"), constexpr_enabled{}) == + "[regular]"); +static_assert(fmt::format(FMT_COMPILE("{:?}"), constexpr_enabled{}) == "debug"); +static_assert(fmt::format(FMT_COMPILE("[{:?}]"), constexpr_enabled{}) == + "[debug]"); +#endif // FMT_USE_CONSTEXPR_STRING