diff options
author | Abseil Team <absl-team@google.com> | 2019-09-03T17·53-0700 |
---|---|---|
committer | Gennadiy Rozental <rogeeff@google.com> | 2019-09-03T17·56-0400 |
commit | 9ddac555b7861dc178d0dbe758a1cfbed718784b (patch) | |
tree | 1a63f7fffbddbc7796ad671b38b38252200f01be /absl/strings/str_cat_test.cc | |
parent | 1948f6f967e34db9793cfa8b4bcbaf370d039fd8 (diff) |
Export of internal Abseil changes
-- 35f516d528f4b53694ebe1f7debc023f1383cf4a by Shaindel Schwartz <shaindel@google.com>: Internal change PiperOrigin-RevId: 266967228 -- 40a0b91769133c48e3799a99f4dd2a7ce58bac91 by Derek Mauro <dmauro@google.com>: Prevent absl::StrCat() and absl::StrAppend() from dereferencing std::string::end() Fixes #374 PiperOrigin-RevId: 266447391 GitOrigin-RevId: 35f516d528f4b53694ebe1f7debc023f1383cf4a Change-Id: I82e3a1bec5fa528db90a2f67dd3bc000e8dca8ab
Diffstat (limited to 'absl/strings/str_cat_test.cc')
-rw-r--r-- | absl/strings/str_cat_test.cc | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/absl/strings/str_cat_test.cc b/absl/strings/str_cat_test.cc index 29db9c023781..be39880be78e 100644 --- a/absl/strings/str_cat_test.cc +++ b/absl/strings/str_cat_test.cc @@ -195,6 +195,21 @@ TEST(StrCat, Basics) { EXPECT_EQ(result, "12333444455555666666777777788888888999999999"); } +TEST(StrCat, CornerCases) { + std::string result; + + result = absl::StrCat(""); // NOLINT + EXPECT_EQ(result, ""); + result = absl::StrCat("", ""); + EXPECT_EQ(result, ""); + result = absl::StrCat("", "", ""); + EXPECT_EQ(result, ""); + result = absl::StrCat("", "", "", ""); + EXPECT_EQ(result, ""); + result = absl::StrCat("", "", "", "", ""); + EXPECT_EQ(result, ""); +} + // A minimal allocator that uses malloc(). template <typename T> struct Mallocator { @@ -433,10 +448,34 @@ TEST(StrAppend, Death) { } #endif // GTEST_HAS_DEATH_TEST -TEST(StrAppend, EmptyString) { - std::string s = ""; - absl::StrAppend(&s, s); - EXPECT_EQ(s, ""); +TEST(StrAppend, CornerCases) { + std::string result; + absl::StrAppend(&result, ""); + EXPECT_EQ(result, ""); + absl::StrAppend(&result, "", ""); + EXPECT_EQ(result, ""); + absl::StrAppend(&result, "", "", ""); + EXPECT_EQ(result, ""); + absl::StrAppend(&result, "", "", "", ""); + EXPECT_EQ(result, ""); + absl::StrAppend(&result, "", "", "", "", ""); + EXPECT_EQ(result, ""); +} + +TEST(StrAppend, CornerCasesNonEmptyAppend) { + for (std::string result : {"hello", "a std::string too long to fit in the SSO"}) { + const std::string expected = result; + absl::StrAppend(&result, ""); + EXPECT_EQ(result, expected); + absl::StrAppend(&result, "", ""); + EXPECT_EQ(result, expected); + absl::StrAppend(&result, "", "", ""); + EXPECT_EQ(result, expected); + absl::StrAppend(&result, "", "", "", ""); + EXPECT_EQ(result, expected); + absl::StrAppend(&result, "", "", "", "", ""); + EXPECT_EQ(result, expected); + } } template <typename IntType> |