From 1b3ac7601934c76280c87796f916c2074c52405b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 21 Jan 2013 10:50:51 -0800 Subject: [PATCH] Check that hex and oct don't conflict with IO manipulators. --- format_test.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/format_test.cc b/format_test.cc index bfcf2db3..f606016f 100644 --- a/format_test.cc +++ b/format_test.cc @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include "format.h" @@ -50,9 +51,7 @@ using fmt::Formatter; using fmt::Format; using fmt::FormatError; using fmt::StringRef; -using fmt::hex; using fmt::hexu; -using fmt::oct; using fmt::pad; #define FORMAT_TEST_THROW_(statement, expected_exception, message, fail) \ @@ -1065,6 +1064,7 @@ TEST(TempFormatterTest, Examples) { } TEST(StrTest, oct) { + using fmt::oct; EXPECT_EQ("12", (BasicFormatter() << oct(static_cast(012))).str()); EXPECT_EQ("12", (BasicFormatter() << oct(012)).str()); EXPECT_EQ("34", (BasicFormatter() << oct(034u)).str()); @@ -1073,6 +1073,7 @@ TEST(StrTest, oct) { } TEST(StrTest, hex) { + using fmt::hex; fmt::IntFormatter > (*phex)(int value) = hex; phex(42); // This shouldn't compile: @@ -1107,6 +1108,7 @@ public: ISO8601DateFormatter iso8601(const Date &d) { return ISO8601DateFormatter(d); } TEST(StrTest, pad) { + using fmt::hex; EXPECT_EQ(" cafe", (BasicFormatter() << pad(hex(0xcafe), 8)).str()); EXPECT_EQ(" babe", (BasicFormatter() << pad(hex(0xbabeu), 8)).str()); EXPECT_EQ(" dead", (BasicFormatter() << pad(hex(0xdeadl), 8)).str()); @@ -1129,6 +1131,13 @@ TEST(StrTest, pad) { EXPECT_EQ("2012-01-09", f.str()); } +TEST(StrTest, NoConflictWithIOManip) { + using namespace std; + using namespace fmt; + EXPECT_EQ("cafe", (BasicFormatter() << hex(0xcafe)).str()); + EXPECT_EQ("12", (BasicFormatter() << oct(012)).str()); +} + template std::string str(const T &value) { return fmt::str(fmt::Format("{0}") << value);