Supporting ? as a string presentation type (#2674)

* Supporting ? as a string presentation type.

* Supporting ? as a char presentation type.

* Adding iterator_category to counting_iterator.
This commit is contained in:
Barry Revzin
2022-01-30 10:55:28 -06:00
committed by GitHub
parent ae1aaaee5f
commit a34a97cc1d
7 changed files with 421 additions and 354 deletions

View File

@@ -1060,7 +1060,7 @@ TEST(format_test, format_short) {
template <typename T>
void check_unknown_types(const T& value, const char* types, const char*) {
char format_str[buffer_size];
const char* special = ".0123456789L}";
const char* special = ".0123456789L?}";
for (int i = CHAR_MIN; i <= CHAR_MAX; ++i) {
char c = static_cast<char>(i);
if (std::strchr(types, c) || std::strchr(special, c) || !c) continue;
@@ -1363,6 +1363,9 @@ TEST(format_test, format_char) {
<< format_str;
}
EXPECT_EQ(fmt::format("{:02X}", n), fmt::format("{:02X}", 'x'));
EXPECT_EQ("\n", fmt::format("{}", '\n'));
EXPECT_EQ("'\\n'", fmt::format("{:?}", '\n'));
}
TEST(format_test, format_volatile_char) {
@@ -1417,12 +1420,17 @@ TEST(format_test, format_enum_class) {
TEST(format_test, format_string) {
EXPECT_EQ(fmt::format("{0}", std::string("test")), "test");
EXPECT_EQ(fmt::format("{0}", std::string("test")), "test");
EXPECT_EQ(fmt::format("{:?}", std::string("test")), "\"test\"");
EXPECT_EQ(fmt::format("{:*^10?}", std::string("test")), "**\"test\"**");
EXPECT_EQ(fmt::format("{:?}", std::string("\test")), "\"\\test\"");
EXPECT_THROW((void)fmt::format(fmt::runtime("{:x}"), std::string("test")),
fmt::format_error);
}
TEST(format_test, format_string_view) {
EXPECT_EQ("test", fmt::format("{}", string_view("test")));
EXPECT_EQ("\"t\\nst\"", fmt::format("{:?}", string_view("t\nst")));
EXPECT_EQ("", fmt::format("{}", string_view()));
}