Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Unified Diff: base/strings/string_split_unittest.cc

Issue 1549063003: Don't unnecessarily copy strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add WhitespaceHandling and SplitResult to SplitStringPieceUsingSubstr Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/strings/string_split.cc ('k') | net/http/http_request_headers.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/strings/string_split_unittest.cc
diff --git a/base/strings/string_split_unittest.cc b/base/strings/string_split_unittest.cc
index 0416776b54c7730edf3c942790318f7353897870..72df06f9154f2a28346be6b561b416d2878e1d96 100644
--- a/base/strings/string_split_unittest.cc
+++ b/base/strings/string_split_unittest.cc
@@ -265,6 +265,71 @@ TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) {
results, ElementsAre("un", "deux", "trois", "quatre", "", "", ""));
}
+TEST(SplitStringPieceUsingSubstrTest, StringWithNoDelimiter) {
+ std::vector<base::StringPiece> results =
+ SplitStringPieceUsingSubstr("alongwordwithnodelimiter", "DELIMITER",
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ ASSERT_EQ(1u, results.size());
+ EXPECT_THAT(results, ElementsAre("alongwordwithnodelimiter"));
+}
+
+TEST(SplitStringPieceUsingSubstrTest, LeadingDelimitersSkipped) {
+ std::vector<base::StringPiece> results = SplitStringPieceUsingSubstr(
+ "DELIMITERDELIMITERDELIMITERoneDELIMITERtwoDELIMITERthree", "DELIMITER",
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ ASSERT_EQ(6u, results.size());
+ EXPECT_THAT(results, ElementsAre("", "", "", "one", "two", "three"));
+}
+
+TEST(SplitStringPieceUsingSubstrTest, ConsecutiveDelimitersSkipped) {
+ std::vector<base::StringPiece> results = SplitStringPieceUsingSubstr(
+ "unoDELIMITERDELIMITERDELIMITERdosDELIMITERtresDELIMITERDELIMITERcuatro",
+ "DELIMITER", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ ASSERT_EQ(7u, results.size());
+ EXPECT_THAT(results, ElementsAre("uno", "", "", "dos", "tres", "", "cuatro"));
+}
+
+TEST(SplitStringPieceUsingSubstrTest, TrailingDelimitersSkipped) {
+ std::vector<base::StringPiece> results = SplitStringPieceUsingSubstr(
+ "unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER",
+ "DELIMITER", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ ASSERT_EQ(7u, results.size());
+ EXPECT_THAT(results,
+ ElementsAre("un", "deux", "trois", "quatre", "", "", ""));
+}
+
+TEST(SplitStringPieceUsingSubstrTest, KeepWhitespace) {
+ std::vector<base::StringPiece> results = SplitStringPieceUsingSubstr(
+ "un DELIMITERdeux\tDELIMITERtrois\nDELIMITERquatre", "DELIMITER",
+ base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
+ ASSERT_EQ(4u, results.size());
+ EXPECT_THAT(results, ElementsAre("un ", "deux\t", "trois\n", "quatre"));
+}
+
+TEST(SplitStringPieceUsingSubstrTest, TrimWhitespace) {
+ std::vector<base::StringPiece> results = SplitStringPieceUsingSubstr(
+ "un DELIMITERdeux\tDELIMITERtrois\nDELIMITERquatre", "DELIMITER",
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ ASSERT_EQ(4u, results.size());
+ EXPECT_THAT(results, ElementsAre("un", "deux", "trois", "quatre"));
+}
+
+TEST(SplitStringPieceUsingSubstrTest, SplitWantAll) {
+ std::vector<base::StringPiece> results = SplitStringPieceUsingSubstr(
+ "unDELIMITERdeuxDELIMITERtroisDELIMITERDELIMITER", "DELIMITER",
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ ASSERT_EQ(5u, results.size());
+ EXPECT_THAT(results, ElementsAre("un", "deux", "trois", "", ""));
+}
+
+TEST(SplitStringPieceUsingSubstrTest, SplitWantNonEmpty) {
+ std::vector<base::StringPiece> results = SplitStringPieceUsingSubstr(
+ "unDELIMITERdeuxDELIMITERtroisDELIMITERDELIMITER", "DELIMITER",
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ ASSERT_EQ(3u, results.size());
+ EXPECT_THAT(results, ElementsAre("un", "deux", "trois"));
+}
+
TEST(StringSplitTest, StringSplitKeepWhitespace) {
std::vector<std::string> r;
« no previous file with comments | « base/strings/string_split.cc ('k') | net/http/http_request_headers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698