(w)context -> (w)format_context

This commit is contained in:
Victor Zverovich
2018-04-08 07:03:44 -07:00
parent 26aa34f319
commit fd0b07a75a
9 changed files with 44 additions and 41 deletions

View File

@@ -16,7 +16,7 @@ class custom_arg_formatter :
typedef fmt::back_insert_range<fmt::internal::buffer> range;
typedef fmt::arg_formatter<range> base;
custom_arg_formatter(fmt::context &ctx, fmt::format_specs &s)
custom_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
: base(ctx, s) {}
using base::operator();

View File

@@ -38,8 +38,9 @@ struct ValueExtractor: fmt::internal::function<T> {
TEST(FormatTest, ArgConverter) {
long long value = std::numeric_limits<long long>::max();
auto arg = fmt::internal::make_arg<fmt::context>(value);
visit(fmt::internal::arg_converter<long long, fmt::context>(arg, 'd'), arg);
auto arg = fmt::internal::make_arg<fmt::format_context>(value);
visit(fmt::internal::arg_converter<long long, fmt::format_context>(arg, 'd'),
arg);
EXPECT_EQ(value, visit(ValueExtractor<long long>(), arg));
}

View File

@@ -1101,7 +1101,7 @@ struct formatter<Date> {
return it;
}
auto format(const Date &d, context &ctx) -> decltype(ctx.begin()) {
auto format(const Date &d, format_context &ctx) -> decltype(ctx.begin()) {
format_to(ctx.begin(), "{}-{}-{}", d.year(), d.month(), d.day());
return ctx.begin();
}
@@ -1119,7 +1119,7 @@ class Answer {};
namespace fmt {
template <>
struct formatter<Answer> : formatter<int> {
auto format(Answer, fmt::context &ctx) -> decltype(ctx.begin()) {
auto format(Answer, fmt::format_context &ctx) -> decltype(ctx.begin()) {
return formatter<int>::format(42, ctx);
}
};
@@ -1409,7 +1409,7 @@ class mock_arg_formatter:
typedef fmt::internal::arg_formatter_base<buffer_range> base;
typedef buffer_range range;
mock_arg_formatter(fmt::context &ctx, fmt::format_specs &s)
mock_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
: base(fmt::internal::get_container(ctx.begin()), s) {
EXPECT_CALL(*this, call(42));
}
@@ -1421,7 +1421,7 @@ class mock_arg_formatter:
return base::operator()(value);
}
iterator operator()(fmt::basic_format_arg<fmt::context>::handle) {
iterator operator()(fmt::basic_format_arg<fmt::format_context>::handle) {
return base::operator()(fmt::monostate());
}
};
@@ -1454,7 +1454,7 @@ struct variant {
namespace fmt {
template <>
struct formatter<variant> : dynamic_formatter<> {
auto format(variant value, context& ctx) -> decltype(ctx.begin()) {
auto format(variant value, format_context& ctx) -> decltype(ctx.begin()) {
if (value.type == variant::INT)
return dynamic_formatter<>::format(42, ctx);
return dynamic_formatter<>::format("foo", ctx);

View File

@@ -41,17 +41,17 @@ TEST(OStreamTest, Enum) {
typedef fmt::back_insert_range<fmt::internal::buffer> range;
struct test_arg_formatter: fmt::arg_formatter<range> {
test_arg_formatter(fmt::context &ctx, fmt::format_specs &s)
test_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
: fmt::arg_formatter<range>(ctx, s) {}
};
TEST(OStreamTest, CustomArg) {
fmt::memory_buffer buffer;
fmt::internal::buffer &base = buffer;
fmt::context ctx(std::back_inserter(base), "", fmt::format_args());
fmt::format_context ctx(std::back_inserter(base), "", fmt::format_args());
fmt::format_specs spec;
test_arg_formatter af(ctx, spec);
visit(af, fmt::internal::make_arg<fmt::context>(TestEnum()));
visit(af, fmt::internal::make_arg<fmt::format_context>(TestEnum()));
EXPECT_EQ("TestEnum", std::string(buffer.data(), buffer.size()));
}

View File

@@ -580,10 +580,10 @@ TEST(UtilTest, PointerArg) {
}
struct check_custom {
Result operator()(fmt::basic_format_arg<fmt::context>::handle h) const {
Result operator()(fmt::basic_format_arg<fmt::format_context>::handle h) const {
fmt::memory_buffer buffer;
fmt::internal::basic_buffer<char> &base = buffer;
fmt::context ctx(std::back_inserter(base), "", fmt::format_args());
fmt::format_context ctx(std::back_inserter(base), "", fmt::format_args());
h.format(ctx);
EXPECT_EQ("test", std::string(buffer.data(), buffer.size()));
return Result();
@@ -592,17 +592,18 @@ struct check_custom {
TEST(UtilTest, CustomArg) {
::Test test;
typedef MockVisitor<fmt::basic_format_arg<fmt::context>::handle> visitor;
typedef MockVisitor<fmt::basic_format_arg<fmt::format_context>::handle>
visitor;
testing::StrictMock<visitor> v;
EXPECT_CALL(v, visit(_)).WillOnce(testing::Invoke(check_custom()));
fmt::visit(v, make_arg<fmt::context>(test));
fmt::visit(v, make_arg<fmt::format_context>(test));
}
TEST(ArgVisitorTest, VisitInvalidArg) {
typedef MockVisitor<fmt::monostate> Visitor;
testing::StrictMock<Visitor> visitor;
EXPECT_CALL(visitor, visit(_));
fmt::basic_format_arg<fmt::context> arg;
fmt::basic_format_arg<fmt::format_context> arg;
visit(visitor, arg);
}