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

Side by Side Diff: base/string_util_unittest.cc

Issue 10828217: string_util support for joining strings using strings not just chars. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: string_util support for joining strings on strings in addition to chars. Created 8 years, 4 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
« no previous file with comments | « base/string_util.cc ('k') | no next file » | 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 <math.h> 5 #include <math.h>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 7
8 #include <limits> 8 #include <limits>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 in.push_back("b"); 760 in.push_back("b");
761 in.push_back("c"); 761 in.push_back("c");
762 EXPECT_EQ("a,b,c", JoinString(in, ',')); 762 EXPECT_EQ("a,b,c", JoinString(in, ','));
763 763
764 in.push_back(""); 764 in.push_back("");
765 EXPECT_EQ("a,b,c,", JoinString(in, ',')); 765 EXPECT_EQ("a,b,c,", JoinString(in, ','));
766 in.push_back(" "); 766 in.push_back(" ");
767 EXPECT_EQ("a|b|c|| ", JoinString(in, '|')); 767 EXPECT_EQ("a|b|c|| ", JoinString(in, '|'));
768 } 768 }
769 769
770 // Test for JoinString overloaded with std::string separator
771 TEST(StringUtilTest, JoinStringWithString) {
772 std::string separator(", ");
773 std::vector<std::string> parts;
774 EXPECT_EQ(std::string(), JoinString(parts, separator));
775
776 parts.push_back("a");
777 EXPECT_EQ("a", JoinString(parts, separator));
778
779 parts.push_back("b");
780 parts.push_back("c");
781 EXPECT_EQ("a, b, c", JoinString(parts, separator));
782
783 parts.push_back("");
784 EXPECT_EQ("a, b, c, ", JoinString(parts, separator));
785 parts.push_back(" ");
786 EXPECT_EQ("a|b|c|| ", JoinString(parts, "|"));
787 }
788
789 // Test for JoinString overloaded with string16 separator
790 TEST(StringUtilTest, JoinStringWithString16) {
791 string16 separator = ASCIIToUTF16(", ");
792 std::vector<string16> parts;
793 EXPECT_EQ(string16(), JoinString(parts, separator));
794
795 parts.push_back(ASCIIToUTF16("a"));
796 EXPECT_EQ(ASCIIToUTF16("a"), JoinString(parts, separator));
797
798 parts.push_back(ASCIIToUTF16("b"));
799 parts.push_back(ASCIIToUTF16("c"));
800 EXPECT_EQ(ASCIIToUTF16("a, b, c"), JoinString(parts, separator));
801
802 parts.push_back(ASCIIToUTF16(""));
803 EXPECT_EQ(ASCIIToUTF16("a, b, c, "), JoinString(parts, separator));
804 parts.push_back(ASCIIToUTF16(" "));
805 EXPECT_EQ(ASCIIToUTF16("a|b|c|| "), JoinString(parts, ASCIIToUTF16("|")));
806 }
807
770 TEST(StringUtilTest, StartsWith) { 808 TEST(StringUtilTest, StartsWith) {
771 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true)); 809 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true));
772 EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true)); 810 EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true));
773 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false)); 811 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false));
774 EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false)); 812 EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false));
775 EXPECT_FALSE(StartsWithASCII("java", "javascript", true)); 813 EXPECT_FALSE(StartsWithASCII("java", "javascript", true));
776 EXPECT_FALSE(StartsWithASCII("java", "javascript", false)); 814 EXPECT_FALSE(StartsWithASCII("java", "javascript", false));
777 EXPECT_FALSE(StartsWithASCII("", "javascript", false)); 815 EXPECT_FALSE(StartsWithASCII("", "javascript", false));
778 EXPECT_FALSE(StartsWithASCII("", "javascript", true)); 816 EXPECT_FALSE(StartsWithASCII("", "javascript", true));
779 EXPECT_TRUE(StartsWithASCII("java", "", false)); 817 EXPECT_TRUE(StartsWithASCII("java", "", false));
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 const std::string live = kLive; 1181 const std::string live = kLive;
1144 std::string dead = live; 1182 std::string dead = live;
1145 strncpy(WriteInto(&dead, 5), kDead, 4); 1183 strncpy(WriteInto(&dead, 5), kDead, 4);
1146 EXPECT_EQ(kDead, dead); 1184 EXPECT_EQ(kDead, dead);
1147 EXPECT_EQ(4u, dead.size()); 1185 EXPECT_EQ(4u, dead.size());
1148 EXPECT_EQ(kLive, live); 1186 EXPECT_EQ(kLive, live);
1149 EXPECT_EQ(4u, live.size()); 1187 EXPECT_EQ(4u, live.size());
1150 } 1188 }
1151 1189
1152 } // namespace base 1190 } // namespace base
OLDNEW
« no previous file with comments | « base/string_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698