From 27b8ba06e8939302244a8b564686fd42e5e2f017 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 10 Dec 2012 11:51:45 -0800 Subject: [PATCH] Test octal formatting. --- format_test.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/format_test.cc b/format_test.cc index 22e47953..83797877 100644 --- a/format_test.cc +++ b/format_test.cc @@ -312,6 +312,27 @@ TEST(FormatterTest, FormatHex) { EXPECT_EQ(buffer, str(Format("{0:x}") << ULONG_MAX)); } +TEST(FormatterTest, FormatOct) { + EXPECT_EQ("0", str(Format("{0:o}") << 0)); + EXPECT_EQ("42", str(Format("{0:o}") << 042)); + EXPECT_EQ("42", str(Format("{0:o}") << 042u)); + EXPECT_EQ("-42", str(Format("{0:o}") << -042)); + EXPECT_EQ("12345670", str(Format("{0:o}") << 012345670)); + char buffer[256]; + sprintf(buffer, "-%o", 0u - INT_MIN); + EXPECT_EQ(buffer, str(Format("{0:o}") << INT_MIN)); + sprintf(buffer, "%o", INT_MAX); + EXPECT_EQ(buffer, str(Format("{0:o}") << INT_MAX)); + sprintf(buffer, "%o", UINT_MAX); + EXPECT_EQ(buffer, str(Format("{0:o}") << UINT_MAX)); + sprintf(buffer, "-%lo", 0ul - LONG_MIN); + EXPECT_EQ(buffer, str(Format("{0:o}") << LONG_MIN)); + sprintf(buffer, "%lo", LONG_MAX); + EXPECT_EQ(buffer, str(Format("{0:o}") << LONG_MAX)); + sprintf(buffer, "%lo", ULONG_MAX); + EXPECT_EQ(buffer, str(Format("{0:o}") << ULONG_MAX)); +} + TEST(FormatterTest, FormatChar) { EXPECT_EQ("a*b", str(Format("{0}{1}{2}") << 'a' << '*' << 'b')); }