diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-30 23:48:49 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-30 23:48:49 +0000 |
commit | 657cab96e02528adfe513c90c4f07a036d92bfe6 (patch) | |
tree | 20cb65a55e78e7e6183117b79dd2efe2a259ba6b /base/string_split_unittest.cc | |
parent | 6d9246446121d198c76a0445122757a8dca6709f (diff) | |
download | chromium_src-657cab96e02528adfe513c90c4f07a036d92bfe6.zip chromium_src-657cab96e02528adfe513c90c4f07a036d92bfe6.tar.gz chromium_src-657cab96e02528adfe513c90c4f07a036d92bfe6.tar.bz2 |
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
Diffstat (limited to 'base/string_split_unittest.cc')
-rw-r--r-- | base/string_split_unittest.cc | 21 |
1 files changed, 12 insertions, 9 deletions
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<std::wstring> 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<std::string> 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); |