1 // Copyright (C) 2014 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #include "util/string_util.h" 16 17 #include <string> 18 #include <vector> 19 20 #include <gtest/gtest.h> 21 22 namespace { 23 24 using i18n::addressinput::DoReplaceStringPlaceholders; 25 26 TEST(StringUtilTest, Ok) { 27 std::vector<std::string> subst; 28 subst.push_back("A"); 29 subst.push_back("B"); 30 subst.push_back("C"); 31 32 EXPECT_EQ("aA,bB,cC", 33 DoReplaceStringPlaceholders("a$1,b$2,c$3", subst)); 34 } 35 36 TEST(StringUtilTest, FewParameters) { 37 std::vector<std::string> subst; 38 subst.push_back("A"); 39 subst.push_back("B"); 40 subst.push_back("C"); 41 42 EXPECT_EQ("aA,bB,cC,d,aA", 43 DoReplaceStringPlaceholders("a$1,b$2,c$3,d$4,a$1", subst)); 44 } 45 46 TEST(StringUtilTest, MoreThan9Parameters) { 47 std::vector<std::string> subst; 48 subst.push_back("A"); 49 subst.push_back("B"); 50 subst.push_back("C"); 51 subst.push_back("D"); 52 subst.push_back("E"); 53 subst.push_back("F"); 54 subst.push_back("G"); 55 subst.push_back("H"); 56 subst.push_back("I"); 57 subst.push_back("J"); 58 subst.push_back("K"); 59 60 EXPECT_EQ("aA,bB,cC,dD,eE,fF,gG,hH,iI,jJ,kK,aA", 61 DoReplaceStringPlaceholders("a$1,b$2,c$3,d$4,e$5,f$6,g$7,h$8,i$9," 62 "j$10,k$11,a$1", subst)); 63 } 64 65 TEST(StringUtilTest, ConsecutiveDollarSigns) { 66 std::vector<std::string> subst; 67 subst.push_back("A"); 68 subst.push_back("B"); 69 subst.push_back("C"); 70 71 EXPECT_EQ("$1 $$2 $$$3", 72 DoReplaceStringPlaceholders("$$1 $$$2 $$$$3", subst)); 73 } 74 75 } // namespace 76