mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-29 18:27:40 +02:00
Fix fallback to runtime API from compile-time API (#2143)
* fix fallback to the runtime API, add FMT_ENABLE_FALLBACK_TO_RUNTIME_API define, add test * remove `FMT_ENABLE_FALLBACK_TO_RUNTIME_API` * pass format string to format_to() inside format_to_n() in compile-time API instead of compiling it inside format_to_n(), to eliminate code duplication
This commit is contained in:
@ -229,6 +229,23 @@ TEST(CompileTest, TextAndArg) {
|
||||
EXPECT_EQ("42!", fmt::format(FMT_COMPILE("{}!"), 42));
|
||||
}
|
||||
|
||||
TEST(CompileTest, UnknownFormatFallback) {
|
||||
EXPECT_EQ(" 42 ",
|
||||
fmt::format(FMT_COMPILE("{name:^4}"), fmt::arg("name", 42)));
|
||||
|
||||
std::vector<char> v;
|
||||
fmt::format_to(std::back_inserter(v), FMT_COMPILE("{name:^4}"),
|
||||
fmt::arg("name", 42));
|
||||
EXPECT_EQ(" 42 ", fmt::string_view(v.data(), v.size()));
|
||||
|
||||
char buffer[4];
|
||||
auto result = fmt::format_to_n(buffer, 4, FMT_COMPILE("{name:^5}"),
|
||||
fmt::arg("name", 42));
|
||||
EXPECT_EQ(5u, result.size);
|
||||
EXPECT_EQ(buffer + 4, result.out);
|
||||
EXPECT_EQ(" 42 ", fmt::string_view(buffer, 4));
|
||||
}
|
||||
|
||||
TEST(CompileTest, Empty) { EXPECT_EQ("", fmt::format(FMT_COMPILE(""))); }
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user