Fix formatting of bool with FMT_COMPILE and add more tests
This commit is contained in:
parent
e956a14e9e
commit
d702a68df2
@ -3380,7 +3380,8 @@ inline std::string to_string(const T& value) {
|
||||
}
|
||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
inline std::string to_string(T value) {
|
||||
char buffer[detail::digits10<T>() + 2];
|
||||
// Buffer should be large enough to store the number or "false" (for bool).
|
||||
char buffer[(std::max)(detail::digits10<T>() + 2, 5)];
|
||||
char* begin = buffer;
|
||||
char* end = detail::write<char>(begin, value);
|
||||
return std::string(begin, end);
|
||||
|
@ -144,8 +144,15 @@ TEST(CompileTest, EmptyFormatString) {
|
||||
}
|
||||
|
||||
#ifdef __cpp_if_constexpr
|
||||
TEST(CompileTest, Basic) {
|
||||
TEST(CompileTest, FormatDefault) {
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42));
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42u));
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42ll));
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42ull));
|
||||
EXPECT_EQ("true", fmt::format(FMT_COMPILE("{}"), true));
|
||||
EXPECT_EQ("x", fmt::format(FMT_COMPILE("{}"), 'x'));
|
||||
EXPECT_EQ("4.2", fmt::format(FMT_COMPILE("{}"), 4.2));
|
||||
EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), "foo"));
|
||||
EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), std::string("foo")));
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user