diff --git a/test/compile-test.cc b/test/compile-test.cc index 97251f2c..85b09ae9 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -176,13 +176,7 @@ TEST(CompileTest, TextAndArg) { #endif #if __cplusplus >= 202002L -template struct constexpr_buffer_helper { - template - constexpr constexpr_buffer_helper& modify(Func func) { - func(buffer); - return *this; - } - +template struct test_string { template constexpr bool operator==(const T& rhs) const noexcept { return (std::string_view(rhs).compare(buffer.data()) == 0); } @@ -190,69 +184,52 @@ template struct constexpr_buffer_helper { std::array buffer{}; }; +template +consteval auto test_format(auto format, const Args&... args) { + test_string string{}; + fmt::format_to(string.buffer.data(), format, args...); + return string; +} + TEST(CompileTimeFormattingTest, Bool) { { - constexpr auto result = - constexpr_buffer_helper<5>{}.modify([](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{}"), true); - }); + constexpr auto result = test_format<5>(FMT_COMPILE("{}"), true); EXPECT_EQ(result, "true"); } { - constexpr auto result = - constexpr_buffer_helper<6>{}.modify([](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{}"), false); - }); + constexpr auto result = test_format<6>(FMT_COMPILE("{}"), false); EXPECT_EQ(result, "false"); } } TEST(CompileTimeFormattingTest, Integer) { { - constexpr auto result = - constexpr_buffer_helper<3>{}.modify([](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{}"), 42); - }); + constexpr auto result = test_format<3>(FMT_COMPILE("{}"), 42); EXPECT_EQ(result, "42"); } { - constexpr auto result = - constexpr_buffer_helper<4>{}.modify([](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{}"), 420); - }); + constexpr auto result = test_format<4>(FMT_COMPILE("{}"), 420); EXPECT_EQ(result, "420"); } { - constexpr auto result = - constexpr_buffer_helper<6>{}.modify([](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{} {}"), 42, 42); - }); + constexpr auto result = test_format<6>(FMT_COMPILE("{} {}"), 42, 42); EXPECT_EQ(result, "42 42"); } { constexpr auto result = - constexpr_buffer_helper<6>{}.modify([=](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{} {}"), uint32_t{42}, - uint64_t{42}); - }); + test_format<6>(FMT_COMPILE("{} {}"), uint32_t{42}, uint64_t{42}); EXPECT_EQ(result, "42 42"); } } TEST(CompileTimeFormattingTest, String) { { - constexpr auto result = - constexpr_buffer_helper<3>{}.modify([](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{}"), "42"); - }); + constexpr auto result = test_format<3>(FMT_COMPILE("{}"), "42"); EXPECT_EQ(result, "42"); } { constexpr auto result = - constexpr_buffer_helper<17>{}.modify([](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{} is {}"), "The answer", - "42"); - }); + test_format<17>(FMT_COMPILE("{} is {}"), "The answer", "42"); EXPECT_EQ(result, "The answer is 42"); } } @@ -260,10 +237,7 @@ TEST(CompileTimeFormattingTest, String) { TEST(CompileTimeFormattingTest, Combination) { { constexpr auto result = - constexpr_buffer_helper<18>{}.modify([](auto& buffer) { - fmt::format_to(buffer.data(), FMT_COMPILE("{}, {}, {}"), 420, true, - "answer"); - }); + test_format<18>(FMT_COMPILE("{}, {}, {}"), 420, true, "answer"); EXPECT_EQ(result, "420, true, answer"); } }