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

Side by Side Diff: base/string_split_unittest.cc

Issue 5004002: base: Move StringSplitAlongWhitespace to string_split.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unittests Created 10 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/string_split.cc ('k') | base/string_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gmock/include/gmock/gmock.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 using ::testing::ElementsAre; 9 using ::testing::ElementsAre;
10 10
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 EXPECT_EQ(r[3], ""); 255 EXPECT_EQ(r[3], "");
256 r.clear(); 256 r.clear();
257 257
258 SplitStringDontTrim("\ta\t\nb\tcc", '\n', &r); 258 SplitStringDontTrim("\ta\t\nb\tcc", '\n', &r);
259 ASSERT_EQ(2U, r.size()); 259 ASSERT_EQ(2U, r.size());
260 EXPECT_EQ(r[0], "\ta\t"); 260 EXPECT_EQ(r[0], "\ta\t");
261 EXPECT_EQ(r[1], "b\tcc"); 261 EXPECT_EQ(r[1], "b\tcc");
262 r.clear(); 262 r.clear();
263 } 263 }
264 264
265 TEST(StringSplitTest, SplitStringAlongWhitespace) {
266 struct TestData {
267 const std::wstring input;
268 const size_t expected_result_count;
269 const std::wstring output1;
270 const std::wstring output2;
271 } data[] = {
272 { L"a", 1, L"a", L"" },
273 { L" ", 0, L"", L"" },
274 { L" a", 1, L"a", L"" },
275 { L" ab ", 1, L"ab", L"" },
276 { L" ab c", 2, L"ab", L"c" },
277 { L" ab c ", 2, L"ab", L"c" },
278 { L" ab cd", 2, L"ab", L"cd" },
279 { L" ab cd ", 2, L"ab", L"cd" },
280 { L" \ta\t", 1, L"a", L"" },
281 { L" b\ta\t", 2, L"b", L"a" },
282 { L" b\tat", 2, L"b", L"at" },
283 { L"b\tat", 2, L"b", L"at" },
284 { L"b\t at", 2, L"b", L"at" },
285 };
286 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
287 std::vector<std::wstring> results;
288 SplitStringAlongWhitespace(data[i].input, &results);
289 ASSERT_EQ(data[i].expected_result_count, results.size());
290 if (data[i].expected_result_count > 0)
291 ASSERT_EQ(data[i].output1, results[0]);
292 if (data[i].expected_result_count > 1)
293 ASSERT_EQ(data[i].output2, results[1]);
294 }
295 }
296
265 } // namespace base 297 } // namespace base
OLDNEW
« no previous file with comments | « base/string_split.cc ('k') | base/string_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698