diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 00:21:58 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 00:21:58 +0000 |
commit | 0078ffb91ddeea8c35cdd75ffe161623030d8dbf (patch) | |
tree | 96089176d6afd0030fa4eb77a8b6ca7bcbb4ec59 /base/string_util_unittest.cc | |
parent | 849a62a1aa77e5d7887bc310233d86cf33ebf393 (diff) | |
download | chromium_src-0078ffb91ddeea8c35cdd75ffe161623030d8dbf.zip chromium_src-0078ffb91ddeea8c35cdd75ffe161623030d8dbf.tar.gz chromium_src-0078ffb91ddeea8c35cdd75ffe161623030d8dbf.tar.bz2 |
Allow the new tab page to be themed (you may want to review DOMUIThemeSource as a whole and not just these changes).
Change global std::strings to chars* in browser theme provider.
Add ability for ReplaceStringPlaceHolder to take up to 9 replacements.
BUG=11235,11685
Review URL: http://codereview.chromium.org/115172
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util_unittest.cc')
-rw-r--r-- | base/string_util_unittest.cc | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index ed6b68f..581cb1f 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -1423,11 +1423,13 @@ TEST(StringUtilTest, StartsWith) { } TEST(StringUtilTest, GetStringFWithOffsets) { + std::vector<const string16> subst; + subst.push_back(ASCIIToUTF16("1")); + subst.push_back(ASCIIToUTF16("2")); std::vector<size_t> offsets; ReplaceStringPlaceholders(ASCIIToUTF16("Hello, $1. Your number is $2."), - ASCIIToUTF16("1"), - ASCIIToUTF16("2"), + subst, &offsets); EXPECT_EQ(2U, offsets.size()); EXPECT_EQ(7U, offsets[0]); @@ -1435,8 +1437,7 @@ TEST(StringUtilTest, GetStringFWithOffsets) { offsets.clear(); ReplaceStringPlaceholders(ASCIIToUTF16("Hello, $2. Your number is $1."), - ASCIIToUTF16("1"), - ASCIIToUTF16("2"), + subst, &offsets); EXPECT_EQ(2U, offsets.size()); EXPECT_EQ(25U, offsets[0]); @@ -1444,6 +1445,40 @@ TEST(StringUtilTest, GetStringFWithOffsets) { offsets.clear(); } +TEST(StringUtilTest, ReplaceStringPlaceholders) { + std::vector<const string16> subst; + subst.push_back(ASCIIToUTF16("9a")); + subst.push_back(ASCIIToUTF16("8b")); + subst.push_back(ASCIIToUTF16("7c")); + subst.push_back(ASCIIToUTF16("6d")); + subst.push_back(ASCIIToUTF16("5e")); + subst.push_back(ASCIIToUTF16("4f")); + subst.push_back(ASCIIToUTF16("3g")); + subst.push_back(ASCIIToUTF16("2h")); + subst.push_back(ASCIIToUTF16("1i")); + + string16 formatted = + ReplaceStringPlaceholders( + ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i"), subst, NULL); + + EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii")); +} + +TEST(StringUtilTest, ReplaceStringPlaceholdersTooFew) { + // Test whether replacestringplaceholders works as expected when there + // are fewer inputs than outputs. + std::vector<const string16> subst; + subst.push_back(ASCIIToUTF16("9a")); + subst.push_back(ASCIIToUTF16("8b")); + subst.push_back(ASCIIToUTF16("7c")); + + string16 formatted = + ReplaceStringPlaceholders( + ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$1g,$2h,$3i"), subst, NULL); + + EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,d,e,f,9ag,8bh,7ci")); +} + TEST(StringUtilTest, SplitStringAlongWhitespace) { struct TestData { const std::wstring input; |