diff --git a/test/format-test.cc b/test/format-test.cc index 2096110b..01c06bbb 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1659,35 +1659,27 @@ TEST(FormatTest, EmptyCustomOutput) { EXPECT_EQ("", fmt::format("{}", EmptyTest())); } -class CustomArgFormatter : - public fmt::internal::ArgFormatterBase { +class MockArgFormatter : + public fmt::internal::ArgFormatterBase { public: - typedef fmt::internal::ArgFormatterBase Base; + typedef fmt::internal::ArgFormatterBase Base; - CustomArgFormatter(fmt::BasicFormatter &f, - fmt::FormatSpec &s, const char *) - : fmt::internal::ArgFormatterBase(f.writer(), s) { + MockArgFormatter(fmt::BasicFormatter &f, + fmt::FormatSpec &s, const char *) + : fmt::internal::ArgFormatterBase(f.writer(), s) { + EXPECT_CALL(*this, visit_int(42)); } - void visit_int(int value) { - fmt::FormatSpec &spec = this->spec(); - if (spec.type() == 'x') - visit_uint(value); // convert to unsigned and format - else - Base::visit_int(value); - } + MOCK_METHOD1(visit_int, void (int value)); }; -std::string custom_format(const char *format_str, fmt::ArgList args) { +void custom_format(const char *format_str, fmt::ArgList args) { fmt::MemoryWriter writer; - fmt::BasicFormatter formatter(args, writer); + fmt::BasicFormatter formatter(args, writer); formatter.format(format_str); - return writer.str(); } -FMT_VARIADIC(std::string, custom_format, const char *) +FMT_VARIADIC(void, custom_format, const char *) TEST(FormatTest, CustomArgFormatter) { - int x = -0xbeef; - EXPECT_EQ(fmt::format("{:x}", static_cast(x)), - custom_format("{:x}", x)); + custom_format("{}", 42); }