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

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

Issue 1223153003: Move JoinString to the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: windows 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
673 TEST(StringUtilTest, JoinString) { 672 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) {
692 std::string separator(", "); 673 std::string separator(", ");
693 std::vector<std::string> parts; 674 std::vector<std::string> parts;
694 EXPECT_EQ(std::string(), JoinString(parts, separator)); 675 EXPECT_EQ(std::string(), JoinString(parts, separator));
695 676
696 parts.push_back("a"); 677 parts.push_back("a");
697 EXPECT_EQ("a", JoinString(parts, separator)); 678 EXPECT_EQ("a", JoinString(parts, separator));
698 679
699 parts.push_back("b"); 680 parts.push_back("b");
700 parts.push_back("c"); 681 parts.push_back("c");
701 EXPECT_EQ("a, b, c", JoinString(parts, separator)); 682 EXPECT_EQ("a, b, c", JoinString(parts, separator));
702 683
703 parts.push_back(std::string()); 684 parts.push_back(std::string());
704 EXPECT_EQ("a, b, c, ", JoinString(parts, separator)); 685 EXPECT_EQ("a, b, c, ", JoinString(parts, separator));
705 parts.push_back(" "); 686 parts.push_back(" ");
706 EXPECT_EQ("a|b|c|| ", JoinString(parts, "|")); 687 EXPECT_EQ("a|b|c|| ", JoinString(parts, "|"));
707 } 688 }
708 689
709 // Test for JoinString overloaded with string16 separator 690 TEST(StringUtilTest, JoinString16) {
710 TEST(StringUtilTest, JoinStringWithString16) {
711 string16 separator = ASCIIToUTF16(", "); 691 string16 separator = ASCIIToUTF16(", ");
712 std::vector<string16> parts; 692 std::vector<string16> parts;
713 EXPECT_EQ(string16(), JoinString(parts, separator)); 693 EXPECT_EQ(string16(), JoinString(parts, separator));
714 694
715 parts.push_back(ASCIIToUTF16("a")); 695 parts.push_back(ASCIIToUTF16("a"));
716 EXPECT_EQ(ASCIIToUTF16("a"), JoinString(parts, separator)); 696 EXPECT_EQ(ASCIIToUTF16("a"), JoinString(parts, separator));
717 697
718 parts.push_back(ASCIIToUTF16("b")); 698 parts.push_back(ASCIIToUTF16("b"));
719 parts.push_back(ASCIIToUTF16("c")); 699 parts.push_back(ASCIIToUTF16("c"));
720 EXPECT_EQ(ASCIIToUTF16("a, b, c"), JoinString(parts, separator)); 700 EXPECT_EQ(ASCIIToUTF16("a, b, c"), JoinString(parts, separator));
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 const std::string live = kLive; 1085 const std::string live = kLive;
1106 std::string dead = live; 1086 std::string dead = live;
1107 strncpy(WriteInto(&dead, 5), kDead, 4); 1087 strncpy(WriteInto(&dead, 5), kDead, 4);
1108 EXPECT_EQ(kDead, dead); 1088 EXPECT_EQ(kDead, dead);
1109 EXPECT_EQ(4u, dead.size()); 1089 EXPECT_EQ(4u, dead.size());
1110 EXPECT_EQ(kLive, live); 1090 EXPECT_EQ(kLive, live);
1111 EXPECT_EQ(4u, live.size()); 1091 EXPECT_EQ(4u, live.size());
1112 } 1092 }
1113 1093
1114 } // namespace base 1094 } // 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