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

Unified Diff: base/string_util_unittest.cc

Issue 1039001: HttpRequestHeaders refactor. (Closed)
Patch Set: Fix bugs, add tests. Created 10 years, 9 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/string_util.cc ('k') | net/http/http_network_transaction.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util_unittest.cc
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index 78939f5374f0c3206acd943d4fc2f80254aea4b0..8fc8f1579a32d17707f383e58b21cc6c3d5d0a3a 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -11,8 +11,11 @@
#include "base/basictypes.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using ::testing::ElementsAre;
+
namespace base {
namespace {
@@ -1492,4 +1495,49 @@ TEST(StringUtilTest, ContainsOnlyChars) {
EXPECT_FALSE(ContainsOnlyChars("123a", "4321"));
}
-} // base
+TEST(SplitStringUsingSubstrTest, EmptyString) {
+ std::vector<std::string> results;
+ SplitStringUsingSubstr("", "DELIMITER", &results);
+ ASSERT_EQ(1u, results.size());
+ EXPECT_THAT(results, ElementsAre(""));
+}
+
+TEST(SplitStringUsingSubstrTest, StringWithNoDelimiter) {
+ std::vector<std::string> results;
+ SplitStringUsingSubstr("alongwordwithnodelimiter", "DELIMITER", &results);
+ ASSERT_EQ(1u, results.size());
+ EXPECT_THAT(results, ElementsAre("alongwordwithnodelimiter"));
+}
+
+TEST(SplitStringUsingSubstrTest, LeadingDelimitersSkipped) {
+ std::vector<std::string> results;
+ SplitStringUsingSubstr(
+ "DELIMITERDELIMITERDELIMITERoneDELIMITERtwoDELIMITERthree",
+ "DELIMITER",
+ &results);
+ ASSERT_EQ(6u, results.size());
+ EXPECT_THAT(results, ElementsAre("", "", "", "one", "two", "three"));
+}
+
+TEST(SplitStringUsingSubstrTest, ConsecutiveDelimitersSkipped) {
+ std::vector<std::string> results;
+ SplitStringUsingSubstr(
+ "unoDELIMITERDELIMITERDELIMITERdosDELIMITERtresDELIMITERDELIMITERcuatro",
+ "DELIMITER",
+ &results);
+ ASSERT_EQ(7u, results.size());
+ EXPECT_THAT(results, ElementsAre("uno", "", "", "dos", "tres", "", "cuatro"));
+}
+
+TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) {
+ std::vector<std::string> results;
+ SplitStringUsingSubstr(
+ "unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER",
+ "DELIMITER",
+ &results);
+ ASSERT_EQ(7u, results.size());
+ EXPECT_THAT(
+ results, ElementsAre("un", "deux", "trois", "quatre", "", "", ""));
+}
+
+} // namespace base
« no previous file with comments | « base/string_util.cc ('k') | net/http/http_network_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698