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

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

Issue 1220793010: [ui/base;css] adding string template expression replacement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment change; merge with master 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
« base/strings/string_util.cc ('K') | « base/strings/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 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 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"), true)); 876 EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"), true));
877 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), false)); 877 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), false));
878 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), true)); 878 EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), true));
879 EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), 879 EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"),
880 ASCIIToUTF16(".plugin"), false)); 880 ASCIIToUTF16(".plugin"), false));
881 EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"), true)); 881 EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"), true));
882 EXPECT_TRUE(EndsWith(string16(), string16(), false)); 882 EXPECT_TRUE(EndsWith(string16(), string16(), false));
883 EXPECT_TRUE(EndsWith(string16(), string16(), true)); 883 EXPECT_TRUE(EndsWith(string16(), string16(), true));
884 } 884 }
885 885
886 TEST(StringUtilTest, StdStringReplaceStringPlaceholdersWithMap) {
887 std::map<std::string, std::string> subst;
888 subst.insert(std::pair<std::string, std::string>("one", "9a"));
889 subst.insert(std::pair<std::string, std::string>("b", "8b"));
890 subst.insert(std::pair<std::string, std::string>("cc", "7c"));
891 subst.insert(std::pair<std::string, std::string>("four", "6d"));
892 subst.insert(
893 std::pair<std::string, std::string>("very long with spaces", "5e"));
894 subst.insert(std::pair<std::string, std::string>("", "4f"));
895 subst.insert(std::pair<std::string, std::string>("&", "3g"));
896 subst.insert(std::pair<std::string, std::string>("$", "2h"));
897 subst.insert(std::pair<std::string, std::string>("$$", "1i"));
898
899 std::string formatted = ReplaceStringPlaceholders(
900 "${one}a,${b}b,${cc}c,${four}d,${very long with "
901 "spaces}e,${}f,${&}g,${$}h,${$$}i",
902 subst);
903
904 EXPECT_EQ(formatted, "9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii");
905 }
906
907 TEST(StringUtilTest, ReplaceStringPlaceholdersConsecutiveDollarSignsWithMap) {
908 std::map<std::string, std::string> subst;
909 subst.insert(std::pair<std::string, std::string>("a", "9a"));
910 subst.insert(std::pair<std::string, std::string>("b", "8b"));
911 subst.insert(std::pair<std::string, std::string>("c", "7c"));
912 EXPECT_EQ(ReplaceStringPlaceholders("$${a} $$${b} $$$${c} $$", subst),
913 "${a} $${b} $$${c} $");
Dan Beam 2015/07/07 02:23:31 please add one like $12 and ensure 12 is left over
dschuyler 2015/07/07 23:05:30 Done.
914 EXPECT_EQ(ReplaceStringPlaceholders("$$", subst), "$");
915 EXPECT_EQ(ReplaceStringPlaceholders("$", subst), "");
916 }
917
886 TEST(StringUtilTest, GetStringFWithOffsets) { 918 TEST(StringUtilTest, GetStringFWithOffsets) {
887 std::vector<string16> subst; 919 std::vector<string16> subst;
888 subst.push_back(ASCIIToUTF16("1")); 920 subst.push_back(ASCIIToUTF16("1"));
889 subst.push_back(ASCIIToUTF16("2")); 921 subst.push_back(ASCIIToUTF16("2"));
890 std::vector<size_t> offsets; 922 std::vector<size_t> offsets;
891 923
892 ReplaceStringPlaceholders(ASCIIToUTF16("Hello, $1. Your number is $2."), 924 ReplaceStringPlaceholders(ASCIIToUTF16("Hello, $1. Your number is $2."),
893 subst, 925 subst,
894 &offsets); 926 &offsets);
895 EXPECT_EQ(2U, offsets.size()); 927 EXPECT_EQ(2U, offsets.size());
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 const std::string live = kLive; 1219 const std::string live = kLive;
1188 std::string dead = live; 1220 std::string dead = live;
1189 strncpy(WriteInto(&dead, 5), kDead, 4); 1221 strncpy(WriteInto(&dead, 5), kDead, 4);
1190 EXPECT_EQ(kDead, dead); 1222 EXPECT_EQ(kDead, dead);
1191 EXPECT_EQ(4u, dead.size()); 1223 EXPECT_EQ(4u, dead.size());
1192 EXPECT_EQ(kLive, live); 1224 EXPECT_EQ(kLive, live);
1193 EXPECT_EQ(4u, live.size()); 1225 EXPECT_EQ(4u, live.size());
1194 } 1226 }
1195 1227
1196 } // namespace base 1228 } // namespace base
OLDNEW
« base/strings/string_util.cc ('K') | « base/strings/string_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698