From a997de90eb737d9573d7d7ee99433cc160660a16 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 25 Jul 2014 07:10:33 -0700 Subject: [PATCH] Fix https://github.com/cppformat/cppformat/issues/57. --- format.cc | 2 +- test/format-test.cc | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/format.cc b/format.cc index f57c0dbd..d5afeaa9 100644 --- a/format.cc +++ b/format.cc @@ -436,7 +436,7 @@ class fmt::internal::ArgFormatter : // TODO: don't duplicate integer format specifiers here case 'd': case 'x': case 'X': case 'b': case 'B': case 'o': writer_.write_int(value, spec_); - break; + return; default: internal::ReportUnknownType(spec_.type_, "char"); } diff --git a/test/format-test.cc b/test/format-test.cc index 7bed6967..96ad6702 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1268,10 +1268,17 @@ TEST(FormatterTest, FormatLongDouble) { } TEST(FormatterTest, FormatChar) { - CheckUnknownTypes('a', "cbBdoxX", "char"); + const char types[] = "cbBdoxX"; + CheckUnknownTypes('a', types, "char"); EXPECT_EQ("a", format("{0}", 'a')); EXPECT_EQ("z", format("{0:c}", 'z')); EXPECT_EQ(L"a", format(L"{0}", 'a')); + int n = 'x'; + for (const char *type = types + 1; *type; ++type) { + std::string format_str = fmt::format("{{:{}}}", *type); + EXPECT_EQ(fmt::format(format_str, n), fmt::format(format_str, 'x')); + } + EXPECT_EQ(fmt::format("{:02X}", n), fmt::format("{:02X}", 'x')); } TEST(FormatterTest, FormatWChar) {