diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-12-02 23:28:38 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-12-02 23:28:38 +0000 |
commit | b5eb6ed9e27b7bf80a406e4a38ffe42db43889cc (patch) | |
tree | a27bcfbc297ba0f3f3b2b6413166b587f4c8b351 /test | |
parent | 42bf979ce7c107bfc214758e4a511232dd9b2e0a (diff) | |
download | googletest-b5eb6ed9e27b7bf80a406e4a38ffe42db43889cc.tar.gz googletest-b5eb6ed9e27b7bf80a406e4a38ffe42db43889cc.tar.bz2 googletest-b5eb6ed9e27b7bf80a406e4a38ffe42db43889cc.zip |
Makes gtest print string literals correctly when it contains \x escape sequences. Contributed by Yair Chuchem.
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest-printers_test.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/gtest-printers_test.cc b/test/gtest-printers_test.cc index 5eabd235..da1fbc25 100644 --- a/test/gtest-printers_test.cc +++ b/test/gtest-printers_test.cc @@ -658,6 +658,20 @@ TEST(PrintStringTest, StringInStdNamespace) { Print(str)); } +TEST(PrintStringTest, StringAmbiguousHex) { + // "\x6BANANA" is ambiguous, it can be interpreted as starting with either of: + // '\x6', '\x6B', or '\x6BA'. + + // a hex escaping sequence following by a decimal digit + EXPECT_EQ("\"0\\x12\" \"3\"", Print(::std::string("0\x12" "3"))); + // a hex escaping sequence following by a hex digit (lower-case) + EXPECT_EQ("\"mm\\x6\" \"bananas\"", Print(::std::string("mm\x6" "bananas"))); + // a hex escaping sequence following by a hex digit (upper-case) + EXPECT_EQ("\"NOM\\x6\" \"BANANA\"", Print(::std::string("NOM\x6" "BANANA"))); + // a hex escaping sequence following by a non-xdigit + EXPECT_EQ("\"!\\x5-!\"", Print(::std::string("!\x5-!"))); +} + // Tests printing ::wstring and ::std::wstring. #if GTEST_HAS_GLOBAL_WSTRING @@ -680,6 +694,16 @@ TEST(PrintWideStringTest, StringInStdNamespace) { "\\xD3\\x576\\x8D3\\xC74D a\\0\"", Print(str)); } + +TEST(PrintWideStringTest, StringAmbiguousHex) { + // same for wide strings. + EXPECT_EQ("L\"0\\x12\" L\"3\"", Print(::std::wstring(L"0\x12" L"3"))); + EXPECT_EQ("L\"mm\\x6\" L\"bananas\"", + Print(::std::wstring(L"mm\x6" L"bananas"))); + EXPECT_EQ("L\"NOM\\x6\" L\"BANANA\"", + Print(::std::wstring(L"NOM\x6" L"BANANA"))); + EXPECT_EQ("L\"!\\x5-!\"", Print(::std::wstring(L"!\x5-!"))); +} #endif // GTEST_HAS_STD_WSTRING // Tests printing types that support generic streaming (i.e. streaming |