Clean API
This commit is contained in:
@@ -15,9 +15,10 @@ using fmt::printf_arg_formatter;
|
||||
// A custom argument formatter that doesn't print `-` for floating-point values
|
||||
// rounded to 0.
|
||||
class CustomArgFormatter :
|
||||
public fmt::arg_formatter<fmt::internal::dynamic_range<fmt::buffer>> {
|
||||
public fmt::arg_formatter<
|
||||
fmt::internal::dynamic_range<fmt::internal::buffer>> {
|
||||
public:
|
||||
using range = fmt::internal::dynamic_range<fmt::buffer>;
|
||||
using range = fmt::internal::dynamic_range<fmt::internal::buffer>;
|
||||
using base = fmt::arg_formatter<range>;
|
||||
|
||||
CustomArgFormatter(range r, fmt::basic_context<range> &ctx,
|
||||
|
||||
@@ -374,20 +374,17 @@ TEST(WriterTest, WWriter) {
|
||||
}
|
||||
|
||||
TEST(FormatToTest, FormatWithoutArgs) {
|
||||
fmt::memory_buffer buffer;
|
||||
format_to(buffer, "test");
|
||||
EXPECT_EQ("test", std::string(buffer.data(), buffer.size()));
|
||||
std::string s;
|
||||
fmt::format_to(std::back_inserter(s), "test");
|
||||
EXPECT_EQ("test", s);
|
||||
}
|
||||
|
||||
TEST(FormatToTest, Format) {
|
||||
fmt::memory_buffer buffer;
|
||||
format_to(buffer, "part{0}", 1);
|
||||
EXPECT_EQ(strlen("part1"), buffer.size());
|
||||
EXPECT_EQ("part1", std::string(buffer.data(), buffer.size()));
|
||||
format_to(buffer, "part{0}", 2);
|
||||
EXPECT_EQ(strlen("part1part2"), buffer.size());
|
||||
EXPECT_EQ("part1part2", std::string(buffer.data(), buffer.size()));
|
||||
EXPECT_EQ("part1part2", to_string(buffer));
|
||||
std::string s;
|
||||
fmt::format_to(std::back_inserter(s), "part{0}", 1);
|
||||
EXPECT_EQ("part1", s);
|
||||
fmt::format_to(std::back_inserter(s), "part{0}", 2);
|
||||
EXPECT_EQ("part1part2", s);
|
||||
}
|
||||
|
||||
TEST(FormatterTest, Escape) {
|
||||
@@ -1484,7 +1481,7 @@ TEST(FormatTest, Enum) {
|
||||
EXPECT_EQ("0", fmt::format("{}", A));
|
||||
}
|
||||
|
||||
using buffer_range = fmt::internal::dynamic_range<fmt::buffer>;
|
||||
using buffer_range = fmt::internal::dynamic_range<fmt::internal::buffer>;
|
||||
|
||||
class mock_arg_formatter :
|
||||
public fmt::internal::arg_formatter_base<buffer_range> {
|
||||
@@ -1908,17 +1905,6 @@ TEST(FormatTest, FormatStringErrors) {
|
||||
int, int);
|
||||
}
|
||||
|
||||
TEST(FormatTest, OutputIterator) {
|
||||
|
||||
std::string s;
|
||||
fmt::format_to(std::back_inserter(s), "{}", 42);
|
||||
std::vector<char> v;
|
||||
fmt::format_to(std::back_inserter(v), "{}", 42);
|
||||
|
||||
EXPECT_EQ("42", s);
|
||||
EXPECT_EQ("42", std::string(v.begin(), v.end()));
|
||||
}
|
||||
|
||||
TEST(StringTest, ToString) {
|
||||
EXPECT_EQ("42", fmt::to_string(42));
|
||||
}
|
||||
|
||||
@@ -58,10 +58,10 @@ TEST(OStreamTest, Enum) {
|
||||
EXPECT_EQ("0", fmt::format("{}", A));
|
||||
}
|
||||
|
||||
struct TestArgFormatter
|
||||
: fmt::arg_formatter<fmt::internal::dynamic_range<fmt::buffer>> {
|
||||
using base = fmt::arg_formatter<fmt::internal::dynamic_range<fmt::buffer>>;
|
||||
TestArgFormatter(fmt::buffer &buf, fmt::context &ctx, fmt::format_specs &s)
|
||||
struct test_arg_formatter : fmt::arg_formatter<fmt::context::range_type> {
|
||||
using base = fmt::arg_formatter<fmt::context::range_type>;
|
||||
test_arg_formatter(fmt::internal::buffer &buf, fmt::context &ctx,
|
||||
fmt::format_specs &s)
|
||||
: base(buf, ctx, s) {}
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ TEST(OStreamTest, CustomArg) {
|
||||
fmt::memory_buffer buffer;
|
||||
fmt::context ctx(buffer, "", fmt::format_args());
|
||||
fmt::format_specs spec;
|
||||
TestArgFormatter af(buffer, ctx, spec);
|
||||
test_arg_formatter af(buffer, ctx, spec);
|
||||
visit(af, fmt::internal::make_arg<fmt::context>(TestEnum()));
|
||||
EXPECT_EQ("TestEnum", std::string(buffer.data(), buffer.size()));
|
||||
}
|
||||
@@ -136,7 +136,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
|
||||
if (max_size <= fmt::internal::to_unsigned(max_streamsize))
|
||||
return;
|
||||
|
||||
struct test_buffer : fmt::buffer {
|
||||
struct test_buffer : fmt::internal::buffer {
|
||||
explicit test_buffer(std::size_t size) { resize(size); }
|
||||
void grow(std::size_t) {}
|
||||
} buffer(max_size);
|
||||
|
||||
@@ -720,7 +720,7 @@ TEST(UtilTest, UTF16ToUTF8Convert) {
|
||||
#endif // _WIN32
|
||||
|
||||
typedef void (*FormatErrorMessage)(
|
||||
fmt::buffer &out, int error_code, string_view message);
|
||||
fmt::internal::buffer &out, int error_code, string_view message);
|
||||
|
||||
template <typename Error>
|
||||
void check_throw_error(int error_code, FormatErrorMessage format) {
|
||||
|
||||
Reference in New Issue
Block a user