Simplify API

This commit is contained in:
Victor Zverovich
2017-02-05 06:41:39 -08:00
parent 7ae8bd7073
commit 624c58682d
11 changed files with 82 additions and 85 deletions
+3 -3
View File
@@ -16,7 +16,7 @@ using fmt::PrintfArgFormatter;
// rounded to 0.
class CustomArgFormatter : public fmt::ArgFormatter<char> {
public:
CustomArgFormatter(fmt::writer &w, fmt::basic_format_context<char> &ctx,
CustomArgFormatter(fmt::writer &w, fmt::basic_context<char> &ctx,
fmt::format_specs &s)
: fmt::ArgFormatter<char>(w, ctx, s) {}
@@ -54,7 +54,7 @@ std::string custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
template <typename... Args>
std::string custom_format(const char *format_str, const Args & ... args) {
auto va = fmt::make_format_args(args...);
auto va = fmt::make_args(args...);
return custom_vformat(format_str, va);
}
@@ -72,7 +72,7 @@ std::string custom_vsprintf(
template <typename... Args>
std::string custom_sprintf(const char *format_str, const Args & ... args) {
auto va = fmt::make_xformat_args<CustomPrintfFormatter>(args...);
auto va = fmt::make_args<CustomPrintfFormatter>(args...);
return custom_vsprintf(format_str, va);
}
+2 -2
View File
@@ -57,9 +57,9 @@ struct ValueExtractor {
TEST(FormatTest, ArgConverter) {
using fmt::format_arg;
fmt::LongLong value = std::numeric_limits<fmt::LongLong>::max();
format_arg arg = fmt::internal::make_arg<fmt::format_context>(value);
format_arg arg = fmt::internal::make_arg<fmt::context>(value);
visit(fmt::internal::ArgConverter<
fmt::LongLong, fmt::format_context>(arg, 'd'), arg);
fmt::LongLong, fmt::context>(arg, 'd'), arg);
EXPECT_EQ(value, visit(ValueExtractor<fmt::LongLong>(), arg));
}
+5 -5
View File
@@ -1366,7 +1366,7 @@ TEST(FormatterTest, FormatCStringRef) {
EXPECT_EQ("test", format("{0}", CStringRef("test")));
}
void format_value(fmt::writer &w, const Date &d, fmt::format_context &) {
void format_value(fmt::writer &w, const Date &d, fmt::context &) {
w.write(d.year());
w.write('-');
w.write(d.month());
@@ -1383,7 +1383,7 @@ TEST(FormatterTest, FormatCustom) {
class Answer {};
template <typename Char>
void format_value(basic_writer<Char> &w, Answer, fmt::format_context &) {
void format_value(basic_writer<Char> &w, Answer, fmt::context &) {
w.write("42");
}
@@ -1575,7 +1575,7 @@ std::string vformat_message(int id, const char *format, fmt::format_args args) {
template <typename... Args>
std::string format_message(int id, const char *format, const Args & ... args) {
auto va = fmt::make_format_args(args...);
auto va = fmt::make_args(args...);
return vformat_message(id, format, va);
}
@@ -1643,7 +1643,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
public:
typedef fmt::internal::ArgFormatterBase<char> Base;
MockArgFormatter(fmt::writer &w, fmt::format_context &ctx,
MockArgFormatter(fmt::writer &w, fmt::context &ctx,
fmt::format_specs &s)
: fmt::internal::ArgFormatterBase<char>(w, s) {
EXPECT_CALL(*this, call(42));
@@ -1663,7 +1663,7 @@ void custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
template <typename... Args>
void custom_format(const char *format_str, const Args & ... args) {
auto va = fmt::make_format_args(args...);
auto va = fmt::make_args(args...);
return custom_vformat(format_str, va);
}
+3 -4
View File
@@ -59,17 +59,16 @@ TEST(OStreamTest, Enum) {
}
struct TestArgFormatter : fmt::ArgFormatter<char> {
TestArgFormatter(fmt::writer &w, fmt::format_context &ctx,
fmt::format_specs &s)
TestArgFormatter(fmt::writer &w, fmt::context &ctx, fmt::format_specs &s)
: fmt::ArgFormatter<char>(w, ctx, s) {}
};
TEST(OStreamTest, CustomArg) {
fmt::MemoryWriter writer;
fmt::format_context ctx("}", fmt::format_args());
fmt::context ctx("}", fmt::format_args());
fmt::format_specs spec;
TestArgFormatter af(writer, ctx, spec);
visit(af, fmt::internal::make_arg<fmt::format_context>(TestEnum()));
visit(af, fmt::internal::make_arg<fmt::context>(TestEnum()));
EXPECT_EQ("TestEnum", writer.str());
}
+4 -4
View File
@@ -69,7 +69,7 @@ struct Test {};
template <typename Char>
void format_value(fmt::basic_writer<Char> &w, Test,
fmt::basic_format_context<Char> &) {
fmt::basic_context<Char> &) {
w.write("test");
}
@@ -487,7 +487,7 @@ VISIT_TYPE(float, double);
#define CHECK_ARG_(Char, expected, value) { \
testing::StrictMock<MockVisitor<decltype(expected)>> visitor; \
EXPECT_CALL(visitor, visit(expected)); \
fmt::visit(visitor, make_arg<fmt::basic_format_context<Char>>(value)); \
fmt::visit(visitor, make_arg<fmt::basic_context<Char>>(value)); \
}
#define CHECK_ARG(value) { \
@@ -570,12 +570,12 @@ TEST(UtilTest, CustomArg) {
testing::Invoke([&](fmt::internal::CustomValue<char> custom) {
EXPECT_EQ(&test, custom.value);
fmt::MemoryWriter w;
fmt::format_context ctx("}", fmt::format_args());
fmt::context ctx("}", fmt::format_args());
custom.format(w, &test, &ctx);
EXPECT_EQ("test", w.str());
return Visitor::Result();
}));
fmt::visit(visitor, make_arg<fmt::format_context>(test));
fmt::visit(visitor, make_arg<fmt::context>(test));
}
TEST(ArgVisitorTest, VisitInvalidArg) {