From 657cab96e02528adfe513c90c4f07a036d92bfe6 Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Fri, 30 Mar 2012 23:48:49 +0000 Subject: When input is "" (or " " with trim_whitespace true), SplitString() should return an empty vector, not a vector of one empty string. Brett and I discussed this for a while and felt this would be wise, whereas dropping all empty segments entirely (e.g. converting "a,,b" to a vector of two elements instead of three) was probably unwise. This also simplifies the code some. Fixing this also required changing the code in mime_util.cc to handle empty vectors to "are codecs valid" oracle functions (in which case we return false). I also fixed some style issues there. It also required avoiding passing the empty string in a test in extension_api_unittest.cc; Aaron assures me that this code is not expected to be defensive against such inputs, but at his suggestion I also added some CHECK()s to the API. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/9960004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129998 0039d316-1c4b-4281-b951-d872f2087c98 --- base/string_split_unittest.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'base/string_split_unittest.cc') diff --git a/base/string_split_unittest.cc b/base/string_split_unittest.cc index 83e4d74..5d4dafe 100644 --- a/base/string_split_unittest.cc +++ b/base/string_split_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -163,8 +163,7 @@ TEST(StringUtilTest, SplitString) { std::vector r; SplitString(L"", L',', &r); - ASSERT_EQ(1U, r.size()); - EXPECT_EQ(r[0], L""); + EXPECT_EQ(0U, r.size()); r.clear(); SplitString(L"a,b,c", L',', &r); @@ -188,9 +187,8 @@ TEST(StringUtilTest, SplitString) { EXPECT_EQ(r[2], L"c"); r.clear(); - SplitString(L"", L'*', &r); - ASSERT_EQ(1U, r.size()); - EXPECT_EQ(r[0], L""); + SplitString(L" ", L'*', &r); + EXPECT_EQ(0U, r.size()); r.clear(); SplitString(L"foo", L'*', &r); @@ -266,12 +264,17 @@ TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) { TEST(StringSplitTest, StringSplitDontTrim) { std::vector r; - SplitStringDontTrim("\t\ta\t", '\t', &r); + SplitStringDontTrim(" ", '*', &r); + ASSERT_EQ(1U, r.size()); + EXPECT_EQ(r[0], " "); + r.clear(); + + SplitStringDontTrim("\t \ta\t ", '\t', &r); ASSERT_EQ(4U, r.size()); EXPECT_EQ(r[0], ""); - EXPECT_EQ(r[1], ""); + EXPECT_EQ(r[1], " "); EXPECT_EQ(r[2], "a"); - EXPECT_EQ(r[3], ""); + EXPECT_EQ(r[3], " "); r.clear(); SplitStringDontTrim("\ta\t\nb\tcc", '\n', &r); -- cgit v1.1