| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/string_split.h" | 5 #include "base/string_split.h" |
| 6 #include "testing/gmock/include/gmock/gmock.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 8 |
| 9 using ::testing::ElementsAre; |
| 10 |
| 8 namespace base { | 11 namespace base { |
| 9 | 12 |
| 10 class SplitStringIntoKeyValuesTest : public testing::Test { | 13 class SplitStringIntoKeyValuesTest : public testing::Test { |
| 11 protected: | 14 protected: |
| 12 std::string key; | 15 std::string key; |
| 13 std::vector<std::string> values; | 16 std::vector<std::string> values; |
| 14 }; | 17 }; |
| 15 | 18 |
| 16 TEST_F(SplitStringIntoKeyValuesTest, EmptyInputMultipleValues) { | 19 TEST_F(SplitStringIntoKeyValuesTest, EmptyInputMultipleValues) { |
| 17 EXPECT_FALSE(SplitStringIntoKeyValues("", // Empty input | 20 EXPECT_FALSE(SplitStringIntoKeyValues("", // Empty input |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 ':', // Key-value delimiters | 125 ':', // Key-value delimiters |
| 123 ',', // Key-value pair delims | 126 ',', // Key-value pair delims |
| 124 &kv_pairs)); | 127 &kv_pairs)); |
| 125 ASSERT_EQ(2U, kv_pairs.size()); | 128 ASSERT_EQ(2U, kv_pairs.size()); |
| 126 EXPECT_EQ("key1", kv_pairs[0].first); | 129 EXPECT_EQ("key1", kv_pairs[0].first); |
| 127 EXPECT_EQ("va:ue1", kv_pairs[0].second); | 130 EXPECT_EQ("va:ue1", kv_pairs[0].second); |
| 128 EXPECT_EQ("key2", kv_pairs[1].first); | 131 EXPECT_EQ("key2", kv_pairs[1].first); |
| 129 EXPECT_EQ("value2", kv_pairs[1].second); | 132 EXPECT_EQ("value2", kv_pairs[1].second); |
| 130 } | 133 } |
| 131 | 134 |
| 135 TEST(SplitStringUsingSubstrTest, EmptyString) { |
| 136 std::vector<std::string> results; |
| 137 SplitStringUsingSubstr("", "DELIMITER", &results); |
| 138 ASSERT_EQ(1u, results.size()); |
| 139 EXPECT_THAT(results, ElementsAre("")); |
| 140 } |
| 141 |
| 142 TEST(SplitStringUsingSubstrTest, StringWithNoDelimiter) { |
| 143 std::vector<std::string> results; |
| 144 SplitStringUsingSubstr("alongwordwithnodelimiter", "DELIMITER", &results); |
| 145 ASSERT_EQ(1u, results.size()); |
| 146 EXPECT_THAT(results, ElementsAre("alongwordwithnodelimiter")); |
| 147 } |
| 148 |
| 149 TEST(SplitStringUsingSubstrTest, LeadingDelimitersSkipped) { |
| 150 std::vector<std::string> results; |
| 151 SplitStringUsingSubstr( |
| 152 "DELIMITERDELIMITERDELIMITERoneDELIMITERtwoDELIMITERthree", |
| 153 "DELIMITER", |
| 154 &results); |
| 155 ASSERT_EQ(6u, results.size()); |
| 156 EXPECT_THAT(results, ElementsAre("", "", "", "one", "two", "three")); |
| 157 } |
| 158 |
| 159 TEST(SplitStringUsingSubstrTest, ConsecutiveDelimitersSkipped) { |
| 160 std::vector<std::string> results; |
| 161 SplitStringUsingSubstr( |
| 162 "unoDELIMITERDELIMITERDELIMITERdosDELIMITERtresDELIMITERDELIMITERcuatro", |
| 163 "DELIMITER", |
| 164 &results); |
| 165 ASSERT_EQ(7u, results.size()); |
| 166 EXPECT_THAT(results, ElementsAre("uno", "", "", "dos", "tres", "", "cuatro")); |
| 167 } |
| 168 |
| 169 TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) { |
| 170 std::vector<std::string> results; |
| 171 SplitStringUsingSubstr( |
| 172 "unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER", |
| 173 "DELIMITER", |
| 174 &results); |
| 175 ASSERT_EQ(7u, results.size()); |
| 176 EXPECT_THAT( |
| 177 results, ElementsAre("un", "deux", "trois", "quatre", "", "", "")); |
| 178 } |
| 179 |
| 132 } // namespace base | 180 } // namespace base |
| OLD | NEW |