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

Side by Side Diff: base/strings/string_util_unittest.cc

Issue 1237873004: Revert of Move JoinString to the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « base/strings/string_util.cc ('k') | base/test/launcher/test_launcher.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stdarg.h> 8 #include <stdarg.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 662
663 // Verify the lower case as well. 663 // Verify the lower case as well.
664 EXPECT_EQ(10, HexDigitToInt('a')); 664 EXPECT_EQ(10, HexDigitToInt('a'));
665 EXPECT_EQ(11, HexDigitToInt('b')); 665 EXPECT_EQ(11, HexDigitToInt('b'));
666 EXPECT_EQ(12, HexDigitToInt('c')); 666 EXPECT_EQ(12, HexDigitToInt('c'));
667 EXPECT_EQ(13, HexDigitToInt('d')); 667 EXPECT_EQ(13, HexDigitToInt('d'));
668 EXPECT_EQ(14, HexDigitToInt('e')); 668 EXPECT_EQ(14, HexDigitToInt('e'));
669 EXPECT_EQ(15, HexDigitToInt('f')); 669 EXPECT_EQ(15, HexDigitToInt('f'));
670 } 670 }
671 671
672 // Test for JoinString
672 TEST(StringUtilTest, JoinString) { 673 TEST(StringUtilTest, JoinString) {
674 std::vector<std::string> in;
675 EXPECT_EQ("", JoinString(in, ','));
676
677 in.push_back("a");
678 EXPECT_EQ("a", JoinString(in, ','));
679
680 in.push_back("b");
681 in.push_back("c");
682 EXPECT_EQ("a,b,c", JoinString(in, ','));
683
684 in.push_back(std::string());
685 EXPECT_EQ("a,b,c,", JoinString(in, ','));
686 in.push_back(" ");
687 EXPECT_EQ("a|b|c|| ", JoinString(in, '|'));
688 }
689
690 // Test for JoinString overloaded with std::string separator
691 TEST(StringUtilTest, JoinStringWithString) {
673 std::string separator(", "); 692 std::string separator(", ");
674 std::vector<std::string> parts; 693 std::vector<std::string> parts;
675 EXPECT_EQ(std::string(), JoinString(parts, separator)); 694 EXPECT_EQ(std::string(), JoinString(parts, separator));
676 695
677 parts.push_back("a"); 696 parts.push_back("a");
678 EXPECT_EQ("a", JoinString(parts, separator)); 697 EXPECT_EQ("a", JoinString(parts, separator));
679 698
680 parts.push_back("b"); 699 parts.push_back("b");
681 parts.push_back("c"); 700 parts.push_back("c");
682 EXPECT_EQ("a, b, c", JoinString(parts, separator)); 701 EXPECT_EQ("a, b, c", JoinString(parts, separator));
683 702
684 parts.push_back(std::string()); 703 parts.push_back(std::string());
685 EXPECT_EQ("a, b, c, ", JoinString(parts, separator)); 704 EXPECT_EQ("a, b, c, ", JoinString(parts, separator));
686 parts.push_back(" "); 705 parts.push_back(" ");
687 EXPECT_EQ("a|b|c|| ", JoinString(parts, "|")); 706 EXPECT_EQ("a|b|c|| ", JoinString(parts, "|"));
688 } 707 }
689 708
690 TEST(StringUtilTest, JoinString16) { 709 // Test for JoinString overloaded with string16 separator
710 TEST(StringUtilTest, JoinStringWithString16) {
691 string16 separator = ASCIIToUTF16(", "); 711 string16 separator = ASCIIToUTF16(", ");
692 std::vector<string16> parts; 712 std::vector<string16> parts;
693 EXPECT_EQ(string16(), JoinString(parts, separator)); 713 EXPECT_EQ(string16(), JoinString(parts, separator));
694 714
695 parts.push_back(ASCIIToUTF16("a")); 715 parts.push_back(ASCIIToUTF16("a"));
696 EXPECT_EQ(ASCIIToUTF16("a"), JoinString(parts, separator)); 716 EXPECT_EQ(ASCIIToUTF16("a"), JoinString(parts, separator));
697 717
698 parts.push_back(ASCIIToUTF16("b")); 718 parts.push_back(ASCIIToUTF16("b"));
699 parts.push_back(ASCIIToUTF16("c")); 719 parts.push_back(ASCIIToUTF16("c"));
700 EXPECT_EQ(ASCIIToUTF16("a, b, c"), JoinString(parts, separator)); 720 EXPECT_EQ(ASCIIToUTF16("a, b, c"), JoinString(parts, separator));
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 const std::string live = kLive; 1105 const std::string live = kLive;
1086 std::string dead = live; 1106 std::string dead = live;
1087 strncpy(WriteInto(&dead, 5), kDead, 4); 1107 strncpy(WriteInto(&dead, 5), kDead, 4);
1088 EXPECT_EQ(kDead, dead); 1108 EXPECT_EQ(kDead, dead);
1089 EXPECT_EQ(4u, dead.size()); 1109 EXPECT_EQ(4u, dead.size());
1090 EXPECT_EQ(kLive, live); 1110 EXPECT_EQ(kLive, live);
1091 EXPECT_EQ(4u, live.size()); 1111 EXPECT_EQ(4u, live.size());
1092 } 1112 }
1093 1113
1094 } // namespace base 1114 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/string_util.cc ('k') | base/test/launcher/test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698