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

Side by Side Diff: base/string_split_unittest.cc

Issue 10684003: Make SplitString() and variants clear their outparam vector. (Note that SplitStringIntoKeyValues()… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/string_split.cc ('k') | net/ftp/ftp_directory_listing_parser_vms.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 EXPECT_THAT( 260 EXPECT_THAT(
261 results, ElementsAre("un", "deux", "trois", "quatre", "", "", "")); 261 results, ElementsAre("un", "deux", "trois", "quatre", "", "", ""));
262 } 262 }
263 263
264 TEST(StringSplitTest, StringSplitDontTrim) { 264 TEST(StringSplitTest, StringSplitDontTrim) {
265 std::vector<std::string> r; 265 std::vector<std::string> r;
266 266
267 SplitStringDontTrim(" ", '*', &r); 267 SplitStringDontTrim(" ", '*', &r);
268 ASSERT_EQ(1U, r.size()); 268 ASSERT_EQ(1U, r.size());
269 EXPECT_EQ(r[0], " "); 269 EXPECT_EQ(r[0], " ");
270 r.clear();
271 270
272 SplitStringDontTrim("\t \ta\t ", '\t', &r); 271 SplitStringDontTrim("\t \ta\t ", '\t', &r);
273 ASSERT_EQ(4U, r.size()); 272 ASSERT_EQ(4U, r.size());
274 EXPECT_EQ(r[0], ""); 273 EXPECT_EQ(r[0], "");
275 EXPECT_EQ(r[1], " "); 274 EXPECT_EQ(r[1], " ");
276 EXPECT_EQ(r[2], "a"); 275 EXPECT_EQ(r[2], "a");
277 EXPECT_EQ(r[3], " "); 276 EXPECT_EQ(r[3], " ");
278 r.clear();
279 277
280 SplitStringDontTrim("\ta\t\nb\tcc", '\n', &r); 278 SplitStringDontTrim("\ta\t\nb\tcc", '\n', &r);
281 ASSERT_EQ(2U, r.size()); 279 ASSERT_EQ(2U, r.size());
282 EXPECT_EQ(r[0], "\ta\t"); 280 EXPECT_EQ(r[0], "\ta\t");
283 EXPECT_EQ(r[1], "b\tcc"); 281 EXPECT_EQ(r[1], "b\tcc");
284 r.clear();
285 } 282 }
286 283
287 TEST(StringSplitTest, SplitStringAlongWhitespace) { 284 TEST(StringSplitTest, SplitStringAlongWhitespace) {
288 struct TestData { 285 struct TestData {
289 const char* input; 286 const char* input;
290 const size_t expected_result_count; 287 const size_t expected_result_count;
291 const char* output1; 288 const char* output1;
292 const char* output2; 289 const char* output2;
293 } data[] = { 290 } data[] = {
294 { "a", 1, "a", "" }, 291 { "a", 1, "a", "" },
(...skipping 15 matching lines...) Expand all
310 SplitStringAlongWhitespace(data[i].input, &results); 307 SplitStringAlongWhitespace(data[i].input, &results);
311 ASSERT_EQ(data[i].expected_result_count, results.size()); 308 ASSERT_EQ(data[i].expected_result_count, results.size());
312 if (data[i].expected_result_count > 0) 309 if (data[i].expected_result_count > 0)
313 ASSERT_EQ(data[i].output1, results[0]); 310 ASSERT_EQ(data[i].output1, results[0]);
314 if (data[i].expected_result_count > 1) 311 if (data[i].expected_result_count > 1)
315 ASSERT_EQ(data[i].output2, results[1]); 312 ASSERT_EQ(data[i].output2, results[1]);
316 } 313 }
317 } 314 }
318 315
319 } // namespace base 316 } // namespace base
OLDNEW
« no previous file with comments | « base/string_split.cc ('k') | net/ftp/ftp_directory_listing_parser_vms.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698