diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-20 23:54:29 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-20 23:54:29 +0000 |
commit | 65b10ba080448288f0fa625d71dc6c42c9b3a67d (patch) | |
tree | af05e7289d8b79eacbb01c2a4b7b44bbedc61a29 /base/string_util_unittest.cc | |
parent | b94193b72ff5c34d87f0b65df00587eaee2bdf7a (diff) | |
download | chromium_src-65b10ba080448288f0fa625d71dc6c42c9b3a67d.zip chromium_src-65b10ba080448288f0fa625d71dc6c42c9b3a67d.tar.gz chromium_src-65b10ba080448288f0fa625d71dc6c42c9b3a67d.tar.bz2 |
Support more than 9 arguments for ReplaceStringPlaceholders()
- support more than 9 arguments ($1, $2, $3, ..., $9 and $10, $11, $12, ...) for ReplaceStringPlaceholders()
- add the unittest named ReplaceStringPlaceholdersMoreThan9Replacements for testing more than 9 arguments for ReplaceStringPlaceholders()
BUG=16963
TEST=string_util_unittest:StringUtilTest.ReplaceStringPlaceholdersMoreThan9Replacements
Patch by haraken@google.com.
Review URL: http://codereview.chromium.org/6877008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util_unittest.cc')
-rw-r--r-- | base/string_util_unittest.cc | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index cd45642..b53bf54 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -863,6 +863,21 @@ TEST(StringUtilTest, GetStringFWithOffsets) { offsets.clear(); } +TEST(StringUtilTest, ReplaceStringPlaceholdersTooFew) { + // Test whether replacestringplaceholders works as expected when there + // are fewer inputs than outputs. + std::vector<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, ReplaceStringPlaceholders) { std::vector<string16> subst; subst.push_back(ASCIIToUTF16("9a")); @@ -882,19 +897,30 @@ TEST(StringUtilTest, ReplaceStringPlaceholders) { 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. +TEST(StringUtilTest, ReplaceStringPlaceholdersMoreThan9Replacements) { std::vector<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")); + subst.push_back(ASCIIToUTF16("0j")); + subst.push_back(ASCIIToUTF16("-1k")); + subst.push_back(ASCIIToUTF16("-2l")); + subst.push_back(ASCIIToUTF16("-3m")); + subst.push_back(ASCIIToUTF16("-4n")); string16 formatted = ReplaceStringPlaceholders( - ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$1g,$2h,$3i"), subst, NULL); + ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i," + "$10j,$11k,$12l,$13m,$14n,$1"), subst, NULL); - EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,d,e,f,9ag,8bh,7ci")); + EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh," + "1ii,0jj,-1kk,-2ll,-3mm,-4nn,9a")); } TEST(StringUtilTest, StdStringReplaceStringPlaceholders) { |