Browse Source

TOOLS: Add unit test for ReplaceAll().

pull/567/head
Philippe Liard 14 years ago
committed by Mihaela Rosca
parent
commit
a49d51235c
3 changed files with 15 additions and 1 deletions
  1. +4
    -1
      tools/cpp/src/cpp-build/generate_geocoding_data.cc
  2. +3
    -0
      tools/cpp/src/cpp-build/generate_geocoding_data.h
  3. +8
    -0
      tools/cpp/test/cpp-build/generate_geocoding_data_test.cc

+ 4
- 1
tools/cpp/src/cpp-build/generate_geocoding_data.cc View File

@ -494,9 +494,12 @@ bool WriteCountryLanguages(const map<int32, set<string> >& languages,
}
// Returns a copy of input where all occurences of pattern are replaced with
// value.
// value. If pattern is empty, input is returned unchanged.
string ReplaceAll(const string& input, const string& pattern,
const string& value) {
if (pattern.size() == 0) {
return input;
}
string replaced;
std::back_insert_iterator<string> output = std::back_inserter(replaced);
string::const_iterator begin = input.begin(), end = begin;


+ 3
- 0
tools/cpp/src/cpp-build/generate_geocoding_data.h View File

@ -26,6 +26,9 @@ using std::string;
string MakeStringLiteral(const string& s);
string ReplaceAll(const string& input, const string& pattern,
const string& value);
int Main(int argc, const char* argv[]);
} // namespace phonenumbers


+ 8
- 0
tools/cpp/test/cpp-build/generate_geocoding_data_test.cc View File

@ -27,5 +27,13 @@ TEST(GenerateGeocodingDataTest, TestMakeStringLiteral) {
MakeStringLiteral("Op\xc3\xa9ra"));
}
TEST(GenerateGeocodingDataTest, TestReplaceAll) {
EXPECT_EQ("", ReplaceAll("", "$input$", "cc"));
EXPECT_EQ("accb", ReplaceAll("a$input$b", "$input$", "cc"));
EXPECT_EQ("ab", ReplaceAll("a$input$b", "$input$", ""));
EXPECT_EQ("ab", ReplaceAll("ab", "", "cc"));
EXPECT_EQ("acdc", ReplaceAll("a$input$d$input$", "$input$", "c"));
}
} // namespace phonenumbers
} // namespace i18n

Loading…
Cancel
Save