Add FMT_STATIC_FORMAT

This commit is contained in:
Victor Zverovich
2025-09-01 07:42:57 -07:00
parent a57f196cad
commit 02fb76d69b
2 changed files with 50 additions and 16 deletions

View File

@@ -236,6 +236,12 @@ TEST(compile_test, constexpr_formatted_size) {
fmt::formatted_size(FMT_COMPILE("{:s}"), "abc");
EXPECT_EQ(str_size, 3);
}
TEST(compile_test, static_format) {
constexpr auto result = FMT_STATIC_FORMAT("{}", 42);
EXPECT_STREQ(result.c_str(), "42");
EXPECT_EQ(result.str(), "42");
}
# endif
TEST(compile_test, text_and_arg) {
@@ -423,22 +429,16 @@ TEST(compile_time_formatting_test, multibyte_fill) {
#endif
#if FMT_USE_CONSTEXPR_STRING
TEST(compile_test, constexpr_string_format) {
constexpr auto result = []() {
return fmt::format(FMT_COMPILE("{}"), 42) == "42";
}();
EXPECT_TRUE(result);
TEST(compile_test, constexpr_format) {
{
constexpr auto result = []() {
return fmt::format(FMT_COMPILE("{}"), 42) == "42";
}();
EXPECT_TRUE(result);
}
{
// Test with a larger string to avoid small string optimization.
constexpr auto result = []() {
return fmt::format(FMT_COMPILE("{:100}"), ' ') == std::string(100, ' ');
}();
EXPECT_TRUE(result);
}
// Test with a larger string to avoid small string optimization.
constexpr auto big = []() {
return fmt::format(FMT_COMPILE("{:100}"), ' ') == std::string(100, ' ');
}();
EXPECT_TRUE(big);
}
#endif // FMT_USE_CONSTEXPR_STRING