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

Unified Diff: base/string_split_unittest.cc

Issue 464075: Move two generic string split functions from sync API to their own API in base/string_split. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: added .gypi Created 11 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/string_split.cc ('k') | base/string_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_split_unittest.cc
===================================================================
--- base/string_split_unittest.cc (revision 0)
+++ base/string_split_unittest.cc (revision 0)
@@ -0,0 +1,120 @@
+// Copyright (c) 2009 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.
+
+#include "base/string_split.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+class SplitStringIntoKeyValuesTest : public testing::Test {
+ protected:
+ std::string key;
+ std::vector<std::string> values;
+};
+
+TEST_F(SplitStringIntoKeyValuesTest, EmptyInputMultipleValues) {
+ EXPECT_FALSE(SplitStringIntoKeyValues("", // Empty input
+ '\t', // Key separators
+ &key, &values));
+ EXPECT_TRUE(key.empty());
+ EXPECT_TRUE(values.empty());
+}
+
+TEST_F(SplitStringIntoKeyValuesTest, EmptyValueInputMultipleValues) {
+ EXPECT_FALSE(SplitStringIntoKeyValues("key_with_no_value\t",
+ '\t', // Key separators
+ &key, &values));
+ EXPECT_EQ("key_with_no_value", key);
+ EXPECT_TRUE(values.empty());
+}
+
+TEST_F(SplitStringIntoKeyValuesTest, EmptyKeyInputMultipleValues) {
+ EXPECT_TRUE(SplitStringIntoKeyValues("\tvalue for empty key",
+ '\t', // Key separators
+ &key, &values));
+ EXPECT_TRUE(key.empty());
+ ASSERT_EQ(1, values.size());
+}
+
+TEST_F(SplitStringIntoKeyValuesTest, KeyWithMultipleValues) {
+ EXPECT_TRUE(SplitStringIntoKeyValues("key1\tvalue1, value2 value3",
+ '\t', // Key separators
+ &key, &values));
+ EXPECT_EQ("key1", key);
+ ASSERT_EQ(1, values.size());
+ EXPECT_EQ("value1, value2 value3", values[0]);
+}
+
+TEST_F(SplitStringIntoKeyValuesTest, EmptyInputSingleValue) {
+ EXPECT_FALSE(SplitStringIntoKeyValues("", // Empty input
+ '\t', // Key separators
+ &key, &values));
+ EXPECT_TRUE(key.empty());
+ EXPECT_TRUE(values.empty());
+}
+
+TEST_F(SplitStringIntoKeyValuesTest, EmptyValueInputSingleValue) {
+ EXPECT_FALSE(SplitStringIntoKeyValues("key_with_no_value\t",
+ '\t', // Key separators
+ &key, &values));
+ EXPECT_EQ("key_with_no_value", key);
+ EXPECT_TRUE(values.empty());
+}
+
+TEST_F(SplitStringIntoKeyValuesTest, EmptyKeyInputSingleValue) {
+ EXPECT_TRUE(SplitStringIntoKeyValues("\tvalue for empty key",
+ '\t', // Key separators
+ &key, &values));
+ EXPECT_TRUE(key.empty());
+ ASSERT_EQ(1, values.size());
+ EXPECT_EQ("value for empty key", values[0]);
+}
+
+TEST_F(SplitStringIntoKeyValuesTest, KeyWithSingleValue) {
+ EXPECT_TRUE(SplitStringIntoKeyValues("key1\tvalue1, value2 value3",
+ '\t', // Key separators
+ &key, &values));
+ EXPECT_EQ("key1", key);
+ ASSERT_EQ(1, values.size());
+ EXPECT_EQ("value1, value2 value3", values[0]);
+}
+
+class SplitStringIntoKeyValuePairsTest : public testing::Test {
+ protected:
+ std::vector<std::pair<std::string, std::string> > kv_pairs;
+};
+
+TEST_F(SplitStringIntoKeyValuePairsTest, DISABLED_EmptyString) {
+ EXPECT_TRUE(SplitStringIntoKeyValuePairs("",
+ ':', // Key-value delimiters
+ ',', // Key-value pair delims
+ &kv_pairs));
+ EXPECT_TRUE(kv_pairs.empty());
+}
+
+TEST_F(SplitStringIntoKeyValuePairsTest, EmptySecondValue) {
+ EXPECT_FALSE(SplitStringIntoKeyValuePairs("key1:value1 , key2:",
+ ':', // Key-value delimiters
+ ',', // Key-value pair delims
+ &kv_pairs));
+ ASSERT_EQ(2, kv_pairs.size());
+ EXPECT_EQ("key1", kv_pairs[0].first);
+ EXPECT_EQ("value1", kv_pairs[0].second);
+ EXPECT_EQ("key2", kv_pairs[1].first);
+ EXPECT_EQ("", kv_pairs[1].second);
+}
+
+TEST_F(SplitStringIntoKeyValuePairsTest, DelimiterInValue) {
+ EXPECT_TRUE(SplitStringIntoKeyValuePairs("key1:va:ue1 , key2:value2",
+ ':', // Key-value delimiters
+ ',', // Key-value pair delims
+ &kv_pairs));
+ ASSERT_EQ(2, kv_pairs.size());
+ EXPECT_EQ("key1", kv_pairs[0].first);
+ EXPECT_EQ("va:ue1", kv_pairs[0].second);
+ EXPECT_EQ("key2", kv_pairs[1].first);
+ EXPECT_EQ("value2", kv_pairs[1].second);
+}
+
+} // namespace base
« 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