add forgotten template argument to make_format_args which made some u… (#1877)
* add forgotten template argument to make_format_args which made some uses of FMT_COMPILE not work anymore after 54daa0864a
, add more elaborate test cases to compile-test as regression tests
* fix old-style cast which gcc on travis thankfully doesn't accept anymore
* hopefully last forgotten (void*)
This commit is contained in:
parent
0016da7ab3
commit
2696dc9273
@ -444,7 +444,8 @@ template <typename Char, typename T, int N> struct spec_field {
|
|||||||
OutputIt format(OutputIt out, const Args&... args) const {
|
OutputIt format(OutputIt out, const Args&... args) const {
|
||||||
// This ensures that the argument type is convertile to `const T&`.
|
// This ensures that the argument type is convertile to `const T&`.
|
||||||
const T& arg = get<N>(args...);
|
const T& arg = get<N>(args...);
|
||||||
const auto& vargs = make_format_args(args...);
|
const auto& vargs =
|
||||||
|
make_format_args<basic_format_context<OutputIt, Char>>(args...);
|
||||||
basic_format_context<OutputIt, Char> ctx(out, vargs);
|
basic_format_context<OutputIt, Char> ctx(out, vargs);
|
||||||
return fmt.format(arg, ctx);
|
return fmt.format(arg, ctx);
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,9 @@ TEST(CompileTest, FormatWideString) {
|
|||||||
|
|
||||||
TEST(CompileTest, FormatSpecs) {
|
TEST(CompileTest, FormatSpecs) {
|
||||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{:x}"), 0x42));
|
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{:x}"), 0x42));
|
||||||
|
EXPECT_EQ("1.234000:0042:+3.13:str:0x3e8:X",
|
||||||
|
fmt::format(FMT_COMPILE("{:.6f}:{:04}:{:+}:{}:{}:{}"), 1.234, 42,
|
||||||
|
3.13, "str", reinterpret_cast<void*>(1000), 'X'));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompileTest, DynamicWidth) {
|
TEST(CompileTest, DynamicWidth) {
|
||||||
@ -163,18 +166,39 @@ TEST(CompileTest, DynamicWidth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompileTest, FormatTo) {
|
TEST(CompileTest, FormatTo) {
|
||||||
char buf[8];
|
{
|
||||||
auto end = fmt::format_to(buf, FMT_COMPILE("{}"), 42);
|
char buf[8];
|
||||||
*end = '\0';
|
auto end = fmt::format_to(buf, FMT_COMPILE("{}"), 42);
|
||||||
EXPECT_STREQ("42", buf);
|
*end = '\0';
|
||||||
|
EXPECT_STREQ("42", buf);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char buf[100];
|
||||||
|
auto end =
|
||||||
|
fmt::format_to(buf, FMT_COMPILE("{:.6f}:{:04}:{:+}:{}:{}:{}"), 1.234,
|
||||||
|
42, 3.13, "str", reinterpret_cast<void*>(1000), 'X');
|
||||||
|
*end = '\0';
|
||||||
|
EXPECT_STREQ("1.234000:0042:+3.13:str:0x3e8:X", buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompileTest, FormatToNWithCompileMacro) {
|
TEST(CompileTest, FormatToNWithCompileMacro) {
|
||||||
constexpr auto buffer_size = 8;
|
{
|
||||||
char buffer[buffer_size];
|
constexpr auto buffer_size = 8;
|
||||||
auto res = fmt::format_to_n(buffer, buffer_size, FMT_COMPILE("{}"), 42);
|
char buffer[buffer_size];
|
||||||
*res.out = '\0';
|
auto res = fmt::format_to_n(buffer, buffer_size, FMT_COMPILE("{}"), 42);
|
||||||
EXPECT_STREQ("42", buffer);
|
*res.out = '\0';
|
||||||
|
EXPECT_STREQ("42", buffer);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
constexpr auto buffer_size = 100;
|
||||||
|
char buffer[buffer_size];
|
||||||
|
auto res = fmt::format_to_n(
|
||||||
|
buffer, buffer_size, FMT_COMPILE("{:.6f}:{:04}:{:+}:{}:{}:{}"), 1.234,
|
||||||
|
42, 3.13, "str", reinterpret_cast<void*>(1000), 'X');
|
||||||
|
*res.out = '\0';
|
||||||
|
EXPECT_STREQ("1.234000:0042:+3.13:str:0x3e8:X", buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompileTest, TextAndArg) {
|
TEST(CompileTest, TextAndArg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user