Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <string> |
| 11 | |
Howard Hinnant | 6e0a1f4 | 2010-08-22 00:47:54 +0000 | [diff] [blame] | 12 | // basic_string<charT,traits,Allocator>& |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 13 | // replace(const_iterator i1, const_iterator i2, const basic_string& str); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | #include <string> |
| 18 | #include <algorithm> |
| 19 | #include <cassert> |
| 20 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 21 | #include "../../min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 23 | template <class S> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | void |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 25 | test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 27 | typename S::size_type old_size = s.size(); |
| 28 | typename S::const_iterator first = s.begin() + pos1; |
| 29 | typename S::const_iterator last = s.begin() + pos1 + n1; |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame^] | 30 | typename S::size_type xlen = last - first; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | s.replace(first, last, str); |
| 32 | assert(s.__invariants()); |
| 33 | assert(s == expected); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 34 | typename S::size_type rlen = str.size(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | assert(s.size() == old_size - xlen + rlen); |
| 36 | } |
| 37 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 38 | template <class S> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | void test0() |
| 40 | { |
| 41 | test(S(""), 0, 0, S(""), S("")); |
| 42 | test(S(""), 0, 0, S("12345"), S("12345")); |
| 43 | test(S(""), 0, 0, S("1234567890"), S("1234567890")); |
| 44 | test(S(""), 0, 0, S("12345678901234567890"), S("12345678901234567890")); |
| 45 | test(S("abcde"), 0, 0, S(""), S("abcde")); |
| 46 | test(S("abcde"), 0, 0, S("12345"), S("12345abcde")); |
| 47 | test(S("abcde"), 0, 0, S("1234567890"), S("1234567890abcde")); |
| 48 | test(S("abcde"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcde")); |
| 49 | test(S("abcde"), 0, 1, S(""), S("bcde")); |
| 50 | test(S("abcde"), 0, 1, S("12345"), S("12345bcde")); |
| 51 | test(S("abcde"), 0, 1, S("1234567890"), S("1234567890bcde")); |
| 52 | test(S("abcde"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcde")); |
| 53 | test(S("abcde"), 0, 2, S(""), S("cde")); |
| 54 | test(S("abcde"), 0, 2, S("12345"), S("12345cde")); |
| 55 | test(S("abcde"), 0, 2, S("1234567890"), S("1234567890cde")); |
| 56 | test(S("abcde"), 0, 2, S("12345678901234567890"), S("12345678901234567890cde")); |
| 57 | test(S("abcde"), 0, 4, S(""), S("e")); |
| 58 | test(S("abcde"), 0, 4, S("12345"), S("12345e")); |
| 59 | test(S("abcde"), 0, 4, S("1234567890"), S("1234567890e")); |
| 60 | test(S("abcde"), 0, 4, S("12345678901234567890"), S("12345678901234567890e")); |
| 61 | test(S("abcde"), 0, 5, S(""), S("")); |
| 62 | test(S("abcde"), 0, 5, S("12345"), S("12345")); |
| 63 | test(S("abcde"), 0, 5, S("1234567890"), S("1234567890")); |
| 64 | test(S("abcde"), 0, 5, S("12345678901234567890"), S("12345678901234567890")); |
| 65 | test(S("abcde"), 1, 0, S(""), S("abcde")); |
| 66 | test(S("abcde"), 1, 0, S("12345"), S("a12345bcde")); |
| 67 | test(S("abcde"), 1, 0, S("1234567890"), S("a1234567890bcde")); |
| 68 | test(S("abcde"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcde")); |
| 69 | test(S("abcde"), 1, 1, S(""), S("acde")); |
| 70 | test(S("abcde"), 1, 1, S("12345"), S("a12345cde")); |
| 71 | test(S("abcde"), 1, 1, S("1234567890"), S("a1234567890cde")); |
| 72 | test(S("abcde"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cde")); |
| 73 | test(S("abcde"), 1, 2, S(""), S("ade")); |
| 74 | test(S("abcde"), 1, 2, S("12345"), S("a12345de")); |
| 75 | test(S("abcde"), 1, 2, S("1234567890"), S("a1234567890de")); |
| 76 | test(S("abcde"), 1, 2, S("12345678901234567890"), S("a12345678901234567890de")); |
| 77 | test(S("abcde"), 1, 3, S(""), S("ae")); |
| 78 | test(S("abcde"), 1, 3, S("12345"), S("a12345e")); |
| 79 | test(S("abcde"), 1, 3, S("1234567890"), S("a1234567890e")); |
| 80 | test(S("abcde"), 1, 3, S("12345678901234567890"), S("a12345678901234567890e")); |
| 81 | test(S("abcde"), 1, 4, S(""), S("a")); |
| 82 | test(S("abcde"), 1, 4, S("12345"), S("a12345")); |
| 83 | test(S("abcde"), 1, 4, S("1234567890"), S("a1234567890")); |
| 84 | test(S("abcde"), 1, 4, S("12345678901234567890"), S("a12345678901234567890")); |
| 85 | test(S("abcde"), 2, 0, S(""), S("abcde")); |
| 86 | test(S("abcde"), 2, 0, S("12345"), S("ab12345cde")); |
| 87 | test(S("abcde"), 2, 0, S("1234567890"), S("ab1234567890cde")); |
| 88 | test(S("abcde"), 2, 0, S("12345678901234567890"), S("ab12345678901234567890cde")); |
| 89 | test(S("abcde"), 2, 1, S(""), S("abde")); |
| 90 | test(S("abcde"), 2, 1, S("12345"), S("ab12345de")); |
| 91 | test(S("abcde"), 2, 1, S("1234567890"), S("ab1234567890de")); |
| 92 | test(S("abcde"), 2, 1, S("12345678901234567890"), S("ab12345678901234567890de")); |
| 93 | test(S("abcde"), 2, 2, S(""), S("abe")); |
| 94 | test(S("abcde"), 2, 2, S("12345"), S("ab12345e")); |
| 95 | test(S("abcde"), 2, 2, S("1234567890"), S("ab1234567890e")); |
| 96 | test(S("abcde"), 2, 2, S("12345678901234567890"), S("ab12345678901234567890e")); |
| 97 | test(S("abcde"), 2, 3, S(""), S("ab")); |
| 98 | test(S("abcde"), 2, 3, S("12345"), S("ab12345")); |
| 99 | test(S("abcde"), 2, 3, S("1234567890"), S("ab1234567890")); |
| 100 | test(S("abcde"), 2, 3, S("12345678901234567890"), S("ab12345678901234567890")); |
| 101 | test(S("abcde"), 4, 0, S(""), S("abcde")); |
| 102 | test(S("abcde"), 4, 0, S("12345"), S("abcd12345e")); |
| 103 | test(S("abcde"), 4, 0, S("1234567890"), S("abcd1234567890e")); |
| 104 | test(S("abcde"), 4, 0, S("12345678901234567890"), S("abcd12345678901234567890e")); |
| 105 | test(S("abcde"), 4, 1, S(""), S("abcd")); |
| 106 | test(S("abcde"), 4, 1, S("12345"), S("abcd12345")); |
| 107 | test(S("abcde"), 4, 1, S("1234567890"), S("abcd1234567890")); |
| 108 | test(S("abcde"), 4, 1, S("12345678901234567890"), S("abcd12345678901234567890")); |
| 109 | test(S("abcde"), 5, 0, S(""), S("abcde")); |
| 110 | test(S("abcde"), 5, 0, S("12345"), S("abcde12345")); |
| 111 | test(S("abcde"), 5, 0, S("1234567890"), S("abcde1234567890")); |
| 112 | test(S("abcde"), 5, 0, S("12345678901234567890"), S("abcde12345678901234567890")); |
| 113 | test(S("abcdefghij"), 0, 0, S(""), S("abcdefghij")); |
| 114 | test(S("abcdefghij"), 0, 0, S("12345"), S("12345abcdefghij")); |
| 115 | test(S("abcdefghij"), 0, 0, S("1234567890"), S("1234567890abcdefghij")); |
| 116 | test(S("abcdefghij"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcdefghij")); |
| 117 | test(S("abcdefghij"), 0, 1, S(""), S("bcdefghij")); |
| 118 | test(S("abcdefghij"), 0, 1, S("12345"), S("12345bcdefghij")); |
| 119 | test(S("abcdefghij"), 0, 1, S("1234567890"), S("1234567890bcdefghij")); |
| 120 | test(S("abcdefghij"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcdefghij")); |
| 121 | test(S("abcdefghij"), 0, 5, S(""), S("fghij")); |
| 122 | test(S("abcdefghij"), 0, 5, S("12345"), S("12345fghij")); |
| 123 | test(S("abcdefghij"), 0, 5, S("1234567890"), S("1234567890fghij")); |
| 124 | test(S("abcdefghij"), 0, 5, S("12345678901234567890"), S("12345678901234567890fghij")); |
| 125 | test(S("abcdefghij"), 0, 9, S(""), S("j")); |
| 126 | test(S("abcdefghij"), 0, 9, S("12345"), S("12345j")); |
| 127 | test(S("abcdefghij"), 0, 9, S("1234567890"), S("1234567890j")); |
| 128 | test(S("abcdefghij"), 0, 9, S("12345678901234567890"), S("12345678901234567890j")); |
| 129 | test(S("abcdefghij"), 0, 10, S(""), S("")); |
| 130 | test(S("abcdefghij"), 0, 10, S("12345"), S("12345")); |
| 131 | test(S("abcdefghij"), 0, 10, S("1234567890"), S("1234567890")); |
| 132 | test(S("abcdefghij"), 0, 10, S("12345678901234567890"), S("12345678901234567890")); |
| 133 | test(S("abcdefghij"), 1, 0, S(""), S("abcdefghij")); |
| 134 | test(S("abcdefghij"), 1, 0, S("12345"), S("a12345bcdefghij")); |
| 135 | test(S("abcdefghij"), 1, 0, S("1234567890"), S("a1234567890bcdefghij")); |
| 136 | test(S("abcdefghij"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcdefghij")); |
| 137 | test(S("abcdefghij"), 1, 1, S(""), S("acdefghij")); |
| 138 | test(S("abcdefghij"), 1, 1, S("12345"), S("a12345cdefghij")); |
| 139 | test(S("abcdefghij"), 1, 1, S("1234567890"), S("a1234567890cdefghij")); |
| 140 | test(S("abcdefghij"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cdefghij")); |
| 141 | } |
| 142 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 143 | template <class S> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | void test1() |
| 145 | { |
| 146 | test(S("abcdefghij"), 1, 4, S(""), S("afghij")); |
| 147 | test(S("abcdefghij"), 1, 4, S("12345"), S("a12345fghij")); |
| 148 | test(S("abcdefghij"), 1, 4, S("1234567890"), S("a1234567890fghij")); |
| 149 | test(S("abcdefghij"), 1, 4, S("12345678901234567890"), S("a12345678901234567890fghij")); |
| 150 | test(S("abcdefghij"), 1, 8, S(""), S("aj")); |
| 151 | test(S("abcdefghij"), 1, 8, S("12345"), S("a12345j")); |
| 152 | test(S("abcdefghij"), 1, 8, S("1234567890"), S("a1234567890j")); |
| 153 | test(S("abcdefghij"), 1, 8, S("12345678901234567890"), S("a12345678901234567890j")); |
| 154 | test(S("abcdefghij"), 1, 9, S(""), S("a")); |
| 155 | test(S("abcdefghij"), 1, 9, S("12345"), S("a12345")); |
| 156 | test(S("abcdefghij"), 1, 9, S("1234567890"), S("a1234567890")); |
| 157 | test(S("abcdefghij"), 1, 9, S("12345678901234567890"), S("a12345678901234567890")); |
| 158 | test(S("abcdefghij"), 5, 0, S(""), S("abcdefghij")); |
| 159 | test(S("abcdefghij"), 5, 0, S("12345"), S("abcde12345fghij")); |
| 160 | test(S("abcdefghij"), 5, 0, S("1234567890"), S("abcde1234567890fghij")); |
| 161 | test(S("abcdefghij"), 5, 0, S("12345678901234567890"), S("abcde12345678901234567890fghij")); |
| 162 | test(S("abcdefghij"), 5, 1, S(""), S("abcdeghij")); |
| 163 | test(S("abcdefghij"), 5, 1, S("12345"), S("abcde12345ghij")); |
| 164 | test(S("abcdefghij"), 5, 1, S("1234567890"), S("abcde1234567890ghij")); |
| 165 | test(S("abcdefghij"), 5, 1, S("12345678901234567890"), S("abcde12345678901234567890ghij")); |
| 166 | test(S("abcdefghij"), 5, 2, S(""), S("abcdehij")); |
| 167 | test(S("abcdefghij"), 5, 2, S("12345"), S("abcde12345hij")); |
| 168 | test(S("abcdefghij"), 5, 2, S("1234567890"), S("abcde1234567890hij")); |
| 169 | test(S("abcdefghij"), 5, 2, S("12345678901234567890"), S("abcde12345678901234567890hij")); |
| 170 | test(S("abcdefghij"), 5, 4, S(""), S("abcdej")); |
| 171 | test(S("abcdefghij"), 5, 4, S("12345"), S("abcde12345j")); |
| 172 | test(S("abcdefghij"), 5, 4, S("1234567890"), S("abcde1234567890j")); |
| 173 | test(S("abcdefghij"), 5, 4, S("12345678901234567890"), S("abcde12345678901234567890j")); |
| 174 | test(S("abcdefghij"), 5, 5, S(""), S("abcde")); |
| 175 | test(S("abcdefghij"), 5, 5, S("12345"), S("abcde12345")); |
| 176 | test(S("abcdefghij"), 5, 5, S("1234567890"), S("abcde1234567890")); |
| 177 | test(S("abcdefghij"), 5, 5, S("12345678901234567890"), S("abcde12345678901234567890")); |
| 178 | test(S("abcdefghij"), 9, 0, S(""), S("abcdefghij")); |
| 179 | test(S("abcdefghij"), 9, 0, S("12345"), S("abcdefghi12345j")); |
| 180 | test(S("abcdefghij"), 9, 0, S("1234567890"), S("abcdefghi1234567890j")); |
| 181 | test(S("abcdefghij"), 9, 0, S("12345678901234567890"), S("abcdefghi12345678901234567890j")); |
| 182 | test(S("abcdefghij"), 9, 1, S(""), S("abcdefghi")); |
| 183 | test(S("abcdefghij"), 9, 1, S("12345"), S("abcdefghi12345")); |
| 184 | test(S("abcdefghij"), 9, 1, S("1234567890"), S("abcdefghi1234567890")); |
| 185 | test(S("abcdefghij"), 9, 1, S("12345678901234567890"), S("abcdefghi12345678901234567890")); |
| 186 | test(S("abcdefghij"), 10, 0, S(""), S("abcdefghij")); |
| 187 | test(S("abcdefghij"), 10, 0, S("12345"), S("abcdefghij12345")); |
| 188 | test(S("abcdefghij"), 10, 0, S("1234567890"), S("abcdefghij1234567890")); |
| 189 | test(S("abcdefghij"), 10, 0, S("12345678901234567890"), S("abcdefghij12345678901234567890")); |
| 190 | test(S("abcdefghijklmnopqrst"), 0, 0, S(""), S("abcdefghijklmnopqrst")); |
| 191 | test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), S("12345abcdefghijklmnopqrst")); |
| 192 | test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), S("1234567890abcdefghijklmnopqrst")); |
| 193 | test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst")); |
| 194 | test(S("abcdefghijklmnopqrst"), 0, 1, S(""), S("bcdefghijklmnopqrst")); |
| 195 | test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), S("12345bcdefghijklmnopqrst")); |
| 196 | test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), S("1234567890bcdefghijklmnopqrst")); |
| 197 | test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcdefghijklmnopqrst")); |
| 198 | test(S("abcdefghijklmnopqrst"), 0, 10, S(""), S("klmnopqrst")); |
| 199 | test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), S("12345klmnopqrst")); |
| 200 | test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), S("1234567890klmnopqrst")); |
| 201 | test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), S("12345678901234567890klmnopqrst")); |
| 202 | test(S("abcdefghijklmnopqrst"), 0, 19, S(""), S("t")); |
| 203 | test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), S("12345t")); |
| 204 | test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), S("1234567890t")); |
| 205 | test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), S("12345678901234567890t")); |
| 206 | test(S("abcdefghijklmnopqrst"), 0, 20, S(""), S("")); |
| 207 | test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), S("12345")); |
| 208 | test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), S("1234567890")); |
| 209 | test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), S("12345678901234567890")); |
| 210 | test(S("abcdefghijklmnopqrst"), 1, 0, S(""), S("abcdefghijklmnopqrst")); |
| 211 | test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), S("a12345bcdefghijklmnopqrst")); |
| 212 | test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), S("a1234567890bcdefghijklmnopqrst")); |
| 213 | test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst")); |
| 214 | test(S("abcdefghijklmnopqrst"), 1, 1, S(""), S("acdefghijklmnopqrst")); |
| 215 | test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), S("a12345cdefghijklmnopqrst")); |
| 216 | test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), S("a1234567890cdefghijklmnopqrst")); |
| 217 | test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cdefghijklmnopqrst")); |
| 218 | test(S("abcdefghijklmnopqrst"), 1, 9, S(""), S("aklmnopqrst")); |
| 219 | test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), S("a12345klmnopqrst")); |
| 220 | test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), S("a1234567890klmnopqrst")); |
| 221 | test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), S("a12345678901234567890klmnopqrst")); |
| 222 | test(S("abcdefghijklmnopqrst"), 1, 18, S(""), S("at")); |
| 223 | test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), S("a12345t")); |
| 224 | test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), S("a1234567890t")); |
| 225 | test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), S("a12345678901234567890t")); |
| 226 | test(S("abcdefghijklmnopqrst"), 1, 19, S(""), S("a")); |
| 227 | test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), S("a12345")); |
| 228 | test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), S("a1234567890")); |
| 229 | test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), S("a12345678901234567890")); |
| 230 | test(S("abcdefghijklmnopqrst"), 10, 0, S(""), S("abcdefghijklmnopqrst")); |
| 231 | test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), S("abcdefghij12345klmnopqrst")); |
| 232 | test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), S("abcdefghij1234567890klmnopqrst")); |
| 233 | test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst")); |
| 234 | test(S("abcdefghijklmnopqrst"), 10, 1, S(""), S("abcdefghijlmnopqrst")); |
| 235 | test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), S("abcdefghij12345lmnopqrst")); |
| 236 | test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), S("abcdefghij1234567890lmnopqrst")); |
| 237 | test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), S("abcdefghij12345678901234567890lmnopqrst")); |
| 238 | test(S("abcdefghijklmnopqrst"), 10, 5, S(""), S("abcdefghijpqrst")); |
| 239 | test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), S("abcdefghij12345pqrst")); |
| 240 | test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), S("abcdefghij1234567890pqrst")); |
| 241 | test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), S("abcdefghij12345678901234567890pqrst")); |
| 242 | test(S("abcdefghijklmnopqrst"), 10, 9, S(""), S("abcdefghijt")); |
| 243 | test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), S("abcdefghij12345t")); |
| 244 | test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), S("abcdefghij1234567890t")); |
| 245 | test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), S("abcdefghij12345678901234567890t")); |
| 246 | } |
| 247 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 248 | template <class S> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 249 | void test2() |
| 250 | { |
| 251 | test(S("abcdefghijklmnopqrst"), 10, 10, S(""), S("abcdefghij")); |
| 252 | test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), S("abcdefghij12345")); |
| 253 | test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), S("abcdefghij1234567890")); |
| 254 | test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), S("abcdefghij12345678901234567890")); |
| 255 | test(S("abcdefghijklmnopqrst"), 19, 0, S(""), S("abcdefghijklmnopqrst")); |
| 256 | test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), S("abcdefghijklmnopqrs12345t")); |
| 257 | test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), S("abcdefghijklmnopqrs1234567890t")); |
| 258 | test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t")); |
| 259 | test(S("abcdefghijklmnopqrst"), 19, 1, S(""), S("abcdefghijklmnopqrs")); |
| 260 | test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), S("abcdefghijklmnopqrs12345")); |
| 261 | test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), S("abcdefghijklmnopqrs1234567890")); |
| 262 | test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890")); |
| 263 | test(S("abcdefghijklmnopqrst"), 20, 0, S(""), S("abcdefghijklmnopqrst")); |
| 264 | test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), S("abcdefghijklmnopqrst12345")); |
| 265 | test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), S("abcdefghijklmnopqrst1234567890")); |
| 266 | test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); |
| 267 | } |
| 268 | |
| 269 | int main() |
| 270 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 271 | { |
| 272 | typedef std::string S; |
| 273 | test0<S>(); |
| 274 | test1<S>(); |
| 275 | test2<S>(); |
| 276 | } |
| 277 | #if __cplusplus >= 201103L |
| 278 | { |
| 279 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 280 | test0<S>(); |
| 281 | test1<S>(); |
| 282 | test2<S>(); |
| 283 | } |
| 284 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 | } |