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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | // replace(size_type pos, size_type n1, size_type n2, charT c); |
| 14 | |
| 15 | #include <string> |
| 16 | #include <stdexcept> |
| 17 | #include <algorithm> |
| 18 | #include <cassert> |
| 19 | |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 20 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 22 | template <class S> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | void |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 24 | test(S s, typename S::size_type pos, typename S::size_type n1, |
| 25 | typename S::size_type n2, typename S::value_type c, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | S expected) |
| 27 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 28 | typename S::size_type old_size = s.size(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 29 | S s0 = s; |
| 30 | try |
| 31 | { |
| 32 | s.replace(pos, n1, n2, c); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 33 | assert(s.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | assert(pos <= old_size); |
| 35 | assert(s == expected); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 36 | typename S::size_type xlen = std::min(n1, old_size - pos); |
| 37 | typename S::size_type rlen = n2; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | assert(s.size() == old_size - xlen + rlen); |
| 39 | } |
| 40 | catch (std::out_of_range&) |
| 41 | { |
| 42 | assert(pos > old_size); |
| 43 | assert(s == s0); |
| 44 | } |
| 45 | } |
| 46 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 47 | template <class S> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | void test0() |
| 49 | { |
| 50 | test(S(""), 0, 0, 0, '2', S("")); |
| 51 | test(S(""), 0, 0, 5, '2', S("22222")); |
| 52 | test(S(""), 0, 0, 10, '2', S("2222222222")); |
| 53 | test(S(""), 0, 0, 20, '2', S("22222222222222222222")); |
| 54 | test(S(""), 0, 1, 0, '2', S("")); |
| 55 | test(S(""), 0, 1, 5, '2', S("22222")); |
| 56 | test(S(""), 0, 1, 10, '2', S("2222222222")); |
| 57 | test(S(""), 0, 1, 20, '2', S("22222222222222222222")); |
| 58 | test(S(""), 1, 0, 0, '2', S("can't happen")); |
| 59 | test(S(""), 1, 0, 5, '2', S("can't happen")); |
| 60 | test(S(""), 1, 0, 10, '2', S("can't happen")); |
| 61 | test(S(""), 1, 0, 20, '2', S("can't happen")); |
| 62 | test(S("abcde"), 0, 0, 0, '2', S("abcde")); |
| 63 | test(S("abcde"), 0, 0, 5, '2', S("22222abcde")); |
| 64 | test(S("abcde"), 0, 0, 10, '2', S("2222222222abcde")); |
| 65 | test(S("abcde"), 0, 0, 20, '2', S("22222222222222222222abcde")); |
| 66 | test(S("abcde"), 0, 1, 0, '2', S("bcde")); |
| 67 | test(S("abcde"), 0, 1, 5, '2', S("22222bcde")); |
| 68 | test(S("abcde"), 0, 1, 10, '2', S("2222222222bcde")); |
| 69 | test(S("abcde"), 0, 1, 20, '2', S("22222222222222222222bcde")); |
| 70 | test(S("abcde"), 0, 2, 0, '2', S("cde")); |
| 71 | test(S("abcde"), 0, 2, 5, '2', S("22222cde")); |
| 72 | test(S("abcde"), 0, 2, 10, '2', S("2222222222cde")); |
| 73 | test(S("abcde"), 0, 2, 20, '2', S("22222222222222222222cde")); |
| 74 | test(S("abcde"), 0, 4, 0, '2', S("e")); |
| 75 | test(S("abcde"), 0, 4, 5, '2', S("22222e")); |
| 76 | test(S("abcde"), 0, 4, 10, '2', S("2222222222e")); |
| 77 | test(S("abcde"), 0, 4, 20, '2', S("22222222222222222222e")); |
| 78 | test(S("abcde"), 0, 5, 0, '2', S("")); |
| 79 | test(S("abcde"), 0, 5, 5, '2', S("22222")); |
| 80 | test(S("abcde"), 0, 5, 10, '2', S("2222222222")); |
| 81 | test(S("abcde"), 0, 5, 20, '2', S("22222222222222222222")); |
| 82 | test(S("abcde"), 0, 6, 0, '2', S("")); |
| 83 | test(S("abcde"), 0, 6, 5, '2', S("22222")); |
| 84 | test(S("abcde"), 0, 6, 10, '2', S("2222222222")); |
| 85 | test(S("abcde"), 0, 6, 20, '2', S("22222222222222222222")); |
| 86 | test(S("abcde"), 1, 0, 0, '2', S("abcde")); |
| 87 | test(S("abcde"), 1, 0, 5, '2', S("a22222bcde")); |
| 88 | test(S("abcde"), 1, 0, 10, '2', S("a2222222222bcde")); |
| 89 | test(S("abcde"), 1, 0, 20, '2', S("a22222222222222222222bcde")); |
| 90 | test(S("abcde"), 1, 1, 0, '2', S("acde")); |
| 91 | test(S("abcde"), 1, 1, 5, '2', S("a22222cde")); |
| 92 | test(S("abcde"), 1, 1, 10, '2', S("a2222222222cde")); |
| 93 | test(S("abcde"), 1, 1, 20, '2', S("a22222222222222222222cde")); |
| 94 | test(S("abcde"), 1, 2, 0, '2', S("ade")); |
| 95 | test(S("abcde"), 1, 2, 5, '2', S("a22222de")); |
| 96 | test(S("abcde"), 1, 2, 10, '2', S("a2222222222de")); |
| 97 | test(S("abcde"), 1, 2, 20, '2', S("a22222222222222222222de")); |
| 98 | test(S("abcde"), 1, 3, 0, '2', S("ae")); |
| 99 | test(S("abcde"), 1, 3, 5, '2', S("a22222e")); |
| 100 | test(S("abcde"), 1, 3, 10, '2', S("a2222222222e")); |
| 101 | test(S("abcde"), 1, 3, 20, '2', S("a22222222222222222222e")); |
| 102 | test(S("abcde"), 1, 4, 0, '2', S("a")); |
| 103 | test(S("abcde"), 1, 4, 5, '2', S("a22222")); |
| 104 | test(S("abcde"), 1, 4, 10, '2', S("a2222222222")); |
| 105 | test(S("abcde"), 1, 4, 20, '2', S("a22222222222222222222")); |
| 106 | test(S("abcde"), 1, 5, 0, '2', S("a")); |
| 107 | test(S("abcde"), 1, 5, 5, '2', S("a22222")); |
| 108 | test(S("abcde"), 1, 5, 10, '2', S("a2222222222")); |
| 109 | test(S("abcde"), 1, 5, 20, '2', S("a22222222222222222222")); |
| 110 | test(S("abcde"), 2, 0, 0, '2', S("abcde")); |
| 111 | test(S("abcde"), 2, 0, 5, '2', S("ab22222cde")); |
| 112 | test(S("abcde"), 2, 0, 10, '2', S("ab2222222222cde")); |
| 113 | test(S("abcde"), 2, 0, 20, '2', S("ab22222222222222222222cde")); |
| 114 | test(S("abcde"), 2, 1, 0, '2', S("abde")); |
| 115 | test(S("abcde"), 2, 1, 5, '2', S("ab22222de")); |
| 116 | test(S("abcde"), 2, 1, 10, '2', S("ab2222222222de")); |
| 117 | test(S("abcde"), 2, 1, 20, '2', S("ab22222222222222222222de")); |
| 118 | test(S("abcde"), 2, 2, 0, '2', S("abe")); |
| 119 | test(S("abcde"), 2, 2, 5, '2', S("ab22222e")); |
| 120 | test(S("abcde"), 2, 2, 10, '2', S("ab2222222222e")); |
| 121 | test(S("abcde"), 2, 2, 20, '2', S("ab22222222222222222222e")); |
| 122 | test(S("abcde"), 2, 3, 0, '2', S("ab")); |
| 123 | test(S("abcde"), 2, 3, 5, '2', S("ab22222")); |
| 124 | test(S("abcde"), 2, 3, 10, '2', S("ab2222222222")); |
| 125 | test(S("abcde"), 2, 3, 20, '2', S("ab22222222222222222222")); |
| 126 | test(S("abcde"), 2, 4, 0, '2', S("ab")); |
| 127 | test(S("abcde"), 2, 4, 5, '2', S("ab22222")); |
| 128 | test(S("abcde"), 2, 4, 10, '2', S("ab2222222222")); |
| 129 | test(S("abcde"), 2, 4, 20, '2', S("ab22222222222222222222")); |
| 130 | test(S("abcde"), 4, 0, 0, '2', S("abcde")); |
| 131 | test(S("abcde"), 4, 0, 5, '2', S("abcd22222e")); |
| 132 | test(S("abcde"), 4, 0, 10, '2', S("abcd2222222222e")); |
| 133 | test(S("abcde"), 4, 0, 20, '2', S("abcd22222222222222222222e")); |
| 134 | test(S("abcde"), 4, 1, 0, '2', S("abcd")); |
| 135 | test(S("abcde"), 4, 1, 5, '2', S("abcd22222")); |
| 136 | test(S("abcde"), 4, 1, 10, '2', S("abcd2222222222")); |
| 137 | test(S("abcde"), 4, 1, 20, '2', S("abcd22222222222222222222")); |
| 138 | test(S("abcde"), 4, 2, 0, '2', S("abcd")); |
| 139 | test(S("abcde"), 4, 2, 5, '2', S("abcd22222")); |
| 140 | test(S("abcde"), 4, 2, 10, '2', S("abcd2222222222")); |
| 141 | test(S("abcde"), 4, 2, 20, '2', S("abcd22222222222222222222")); |
| 142 | test(S("abcde"), 5, 0, 0, '2', S("abcde")); |
| 143 | test(S("abcde"), 5, 0, 5, '2', S("abcde22222")); |
| 144 | test(S("abcde"), 5, 0, 10, '2', S("abcde2222222222")); |
| 145 | test(S("abcde"), 5, 0, 20, '2', S("abcde22222222222222222222")); |
| 146 | test(S("abcde"), 5, 1, 0, '2', S("abcde")); |
| 147 | test(S("abcde"), 5, 1, 5, '2', S("abcde22222")); |
| 148 | test(S("abcde"), 5, 1, 10, '2', S("abcde2222222222")); |
| 149 | test(S("abcde"), 5, 1, 20, '2', S("abcde22222222222222222222")); |
| 150 | } |
| 151 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 152 | template <class S> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 153 | void test1() |
| 154 | { |
| 155 | test(S("abcde"), 6, 0, 0, '2', S("can't happen")); |
| 156 | test(S("abcde"), 6, 0, 5, '2', S("can't happen")); |
| 157 | test(S("abcde"), 6, 0, 10, '2', S("can't happen")); |
| 158 | test(S("abcde"), 6, 0, 20, '2', S("can't happen")); |
| 159 | test(S("abcdefghij"), 0, 0, 0, '2', S("abcdefghij")); |
| 160 | test(S("abcdefghij"), 0, 0, 5, '2', S("22222abcdefghij")); |
| 161 | test(S("abcdefghij"), 0, 0, 10, '2', S("2222222222abcdefghij")); |
| 162 | test(S("abcdefghij"), 0, 0, 20, '2', S("22222222222222222222abcdefghij")); |
| 163 | test(S("abcdefghij"), 0, 1, 0, '2', S("bcdefghij")); |
| 164 | test(S("abcdefghij"), 0, 1, 5, '2', S("22222bcdefghij")); |
| 165 | test(S("abcdefghij"), 0, 1, 10, '2', S("2222222222bcdefghij")); |
| 166 | test(S("abcdefghij"), 0, 1, 20, '2', S("22222222222222222222bcdefghij")); |
| 167 | test(S("abcdefghij"), 0, 5, 0, '2', S("fghij")); |
| 168 | test(S("abcdefghij"), 0, 5, 5, '2', S("22222fghij")); |
| 169 | test(S("abcdefghij"), 0, 5, 10, '2', S("2222222222fghij")); |
| 170 | test(S("abcdefghij"), 0, 5, 20, '2', S("22222222222222222222fghij")); |
| 171 | test(S("abcdefghij"), 0, 9, 0, '2', S("j")); |
| 172 | test(S("abcdefghij"), 0, 9, 5, '2', S("22222j")); |
| 173 | test(S("abcdefghij"), 0, 9, 10, '2', S("2222222222j")); |
| 174 | test(S("abcdefghij"), 0, 9, 20, '2', S("22222222222222222222j")); |
| 175 | test(S("abcdefghij"), 0, 10, 0, '2', S("")); |
| 176 | test(S("abcdefghij"), 0, 10, 5, '2', S("22222")); |
| 177 | test(S("abcdefghij"), 0, 10, 10, '2', S("2222222222")); |
| 178 | test(S("abcdefghij"), 0, 10, 20, '2', S("22222222222222222222")); |
| 179 | test(S("abcdefghij"), 0, 11, 0, '2', S("")); |
| 180 | test(S("abcdefghij"), 0, 11, 5, '2', S("22222")); |
| 181 | test(S("abcdefghij"), 0, 11, 10, '2', S("2222222222")); |
| 182 | test(S("abcdefghij"), 0, 11, 20, '2', S("22222222222222222222")); |
| 183 | test(S("abcdefghij"), 1, 0, 0, '2', S("abcdefghij")); |
| 184 | test(S("abcdefghij"), 1, 0, 5, '2', S("a22222bcdefghij")); |
| 185 | test(S("abcdefghij"), 1, 0, 10, '2', S("a2222222222bcdefghij")); |
| 186 | test(S("abcdefghij"), 1, 0, 20, '2', S("a22222222222222222222bcdefghij")); |
| 187 | test(S("abcdefghij"), 1, 1, 0, '2', S("acdefghij")); |
| 188 | test(S("abcdefghij"), 1, 1, 5, '2', S("a22222cdefghij")); |
| 189 | test(S("abcdefghij"), 1, 1, 10, '2', S("a2222222222cdefghij")); |
| 190 | test(S("abcdefghij"), 1, 1, 20, '2', S("a22222222222222222222cdefghij")); |
| 191 | test(S("abcdefghij"), 1, 4, 0, '2', S("afghij")); |
| 192 | test(S("abcdefghij"), 1, 4, 5, '2', S("a22222fghij")); |
| 193 | test(S("abcdefghij"), 1, 4, 10, '2', S("a2222222222fghij")); |
| 194 | test(S("abcdefghij"), 1, 4, 20, '2', S("a22222222222222222222fghij")); |
| 195 | test(S("abcdefghij"), 1, 8, 0, '2', S("aj")); |
| 196 | test(S("abcdefghij"), 1, 8, 5, '2', S("a22222j")); |
| 197 | test(S("abcdefghij"), 1, 8, 10, '2', S("a2222222222j")); |
| 198 | test(S("abcdefghij"), 1, 8, 20, '2', S("a22222222222222222222j")); |
| 199 | test(S("abcdefghij"), 1, 9, 0, '2', S("a")); |
| 200 | test(S("abcdefghij"), 1, 9, 5, '2', S("a22222")); |
| 201 | test(S("abcdefghij"), 1, 9, 10, '2', S("a2222222222")); |
| 202 | test(S("abcdefghij"), 1, 9, 20, '2', S("a22222222222222222222")); |
| 203 | test(S("abcdefghij"), 1, 10, 0, '2', S("a")); |
| 204 | test(S("abcdefghij"), 1, 10, 5, '2', S("a22222")); |
| 205 | test(S("abcdefghij"), 1, 10, 10, '2', S("a2222222222")); |
| 206 | test(S("abcdefghij"), 1, 10, 20, '2', S("a22222222222222222222")); |
| 207 | test(S("abcdefghij"), 5, 0, 0, '2', S("abcdefghij")); |
| 208 | test(S("abcdefghij"), 5, 0, 5, '2', S("abcde22222fghij")); |
| 209 | test(S("abcdefghij"), 5, 0, 10, '2', S("abcde2222222222fghij")); |
| 210 | test(S("abcdefghij"), 5, 0, 20, '2', S("abcde22222222222222222222fghij")); |
| 211 | test(S("abcdefghij"), 5, 1, 0, '2', S("abcdeghij")); |
| 212 | test(S("abcdefghij"), 5, 1, 5, '2', S("abcde22222ghij")); |
| 213 | test(S("abcdefghij"), 5, 1, 10, '2', S("abcde2222222222ghij")); |
| 214 | test(S("abcdefghij"), 5, 1, 20, '2', S("abcde22222222222222222222ghij")); |
| 215 | test(S("abcdefghij"), 5, 2, 0, '2', S("abcdehij")); |
| 216 | test(S("abcdefghij"), 5, 2, 5, '2', S("abcde22222hij")); |
| 217 | test(S("abcdefghij"), 5, 2, 10, '2', S("abcde2222222222hij")); |
| 218 | test(S("abcdefghij"), 5, 2, 20, '2', S("abcde22222222222222222222hij")); |
| 219 | test(S("abcdefghij"), 5, 4, 0, '2', S("abcdej")); |
| 220 | test(S("abcdefghij"), 5, 4, 5, '2', S("abcde22222j")); |
| 221 | test(S("abcdefghij"), 5, 4, 10, '2', S("abcde2222222222j")); |
| 222 | test(S("abcdefghij"), 5, 4, 20, '2', S("abcde22222222222222222222j")); |
| 223 | test(S("abcdefghij"), 5, 5, 0, '2', S("abcde")); |
| 224 | test(S("abcdefghij"), 5, 5, 5, '2', S("abcde22222")); |
| 225 | test(S("abcdefghij"), 5, 5, 10, '2', S("abcde2222222222")); |
| 226 | test(S("abcdefghij"), 5, 5, 20, '2', S("abcde22222222222222222222")); |
| 227 | test(S("abcdefghij"), 5, 6, 0, '2', S("abcde")); |
| 228 | test(S("abcdefghij"), 5, 6, 5, '2', S("abcde22222")); |
| 229 | test(S("abcdefghij"), 5, 6, 10, '2', S("abcde2222222222")); |
| 230 | test(S("abcdefghij"), 5, 6, 20, '2', S("abcde22222222222222222222")); |
| 231 | test(S("abcdefghij"), 9, 0, 0, '2', S("abcdefghij")); |
| 232 | test(S("abcdefghij"), 9, 0, 5, '2', S("abcdefghi22222j")); |
| 233 | test(S("abcdefghij"), 9, 0, 10, '2', S("abcdefghi2222222222j")); |
| 234 | test(S("abcdefghij"), 9, 0, 20, '2', S("abcdefghi22222222222222222222j")); |
| 235 | test(S("abcdefghij"), 9, 1, 0, '2', S("abcdefghi")); |
| 236 | test(S("abcdefghij"), 9, 1, 5, '2', S("abcdefghi22222")); |
| 237 | test(S("abcdefghij"), 9, 1, 10, '2', S("abcdefghi2222222222")); |
| 238 | test(S("abcdefghij"), 9, 1, 20, '2', S("abcdefghi22222222222222222222")); |
| 239 | test(S("abcdefghij"), 9, 2, 0, '2', S("abcdefghi")); |
| 240 | test(S("abcdefghij"), 9, 2, 5, '2', S("abcdefghi22222")); |
| 241 | test(S("abcdefghij"), 9, 2, 10, '2', S("abcdefghi2222222222")); |
| 242 | test(S("abcdefghij"), 9, 2, 20, '2', S("abcdefghi22222222222222222222")); |
| 243 | test(S("abcdefghij"), 10, 0, 0, '2', S("abcdefghij")); |
| 244 | test(S("abcdefghij"), 10, 0, 5, '2', S("abcdefghij22222")); |
| 245 | test(S("abcdefghij"), 10, 0, 10, '2', S("abcdefghij2222222222")); |
| 246 | test(S("abcdefghij"), 10, 0, 20, '2', S("abcdefghij22222222222222222222")); |
| 247 | test(S("abcdefghij"), 10, 1, 0, '2', S("abcdefghij")); |
| 248 | test(S("abcdefghij"), 10, 1, 5, '2', S("abcdefghij22222")); |
| 249 | test(S("abcdefghij"), 10, 1, 10, '2', S("abcdefghij2222222222")); |
| 250 | test(S("abcdefghij"), 10, 1, 20, '2', S("abcdefghij22222222222222222222")); |
| 251 | test(S("abcdefghij"), 11, 0, 0, '2', S("can't happen")); |
| 252 | test(S("abcdefghij"), 11, 0, 5, '2', S("can't happen")); |
| 253 | test(S("abcdefghij"), 11, 0, 10, '2', S("can't happen")); |
| 254 | test(S("abcdefghij"), 11, 0, 20, '2', S("can't happen")); |
| 255 | } |
| 256 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 257 | template <class S> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 258 | void test2() |
| 259 | { |
| 260 | test(S("abcdefghijklmnopqrst"), 0, 0, 0, '2', S("abcdefghijklmnopqrst")); |
| 261 | test(S("abcdefghijklmnopqrst"), 0, 0, 5, '2', S("22222abcdefghijklmnopqrst")); |
| 262 | test(S("abcdefghijklmnopqrst"), 0, 0, 10, '2', S("2222222222abcdefghijklmnopqrst")); |
| 263 | test(S("abcdefghijklmnopqrst"), 0, 0, 20, '2', S("22222222222222222222abcdefghijklmnopqrst")); |
| 264 | test(S("abcdefghijklmnopqrst"), 0, 1, 0, '2', S("bcdefghijklmnopqrst")); |
| 265 | test(S("abcdefghijklmnopqrst"), 0, 1, 5, '2', S("22222bcdefghijklmnopqrst")); |
| 266 | test(S("abcdefghijklmnopqrst"), 0, 1, 10, '2', S("2222222222bcdefghijklmnopqrst")); |
| 267 | test(S("abcdefghijklmnopqrst"), 0, 1, 20, '2', S("22222222222222222222bcdefghijklmnopqrst")); |
| 268 | test(S("abcdefghijklmnopqrst"), 0, 10, 0, '2', S("klmnopqrst")); |
| 269 | test(S("abcdefghijklmnopqrst"), 0, 10, 5, '2', S("22222klmnopqrst")); |
| 270 | test(S("abcdefghijklmnopqrst"), 0, 10, 10, '2', S("2222222222klmnopqrst")); |
| 271 | test(S("abcdefghijklmnopqrst"), 0, 10, 20, '2', S("22222222222222222222klmnopqrst")); |
| 272 | test(S("abcdefghijklmnopqrst"), 0, 19, 0, '2', S("t")); |
| 273 | test(S("abcdefghijklmnopqrst"), 0, 19, 5, '2', S("22222t")); |
| 274 | test(S("abcdefghijklmnopqrst"), 0, 19, 10, '2', S("2222222222t")); |
| 275 | test(S("abcdefghijklmnopqrst"), 0, 19, 20, '2', S("22222222222222222222t")); |
| 276 | test(S("abcdefghijklmnopqrst"), 0, 20, 0, '2', S("")); |
| 277 | test(S("abcdefghijklmnopqrst"), 0, 20, 5, '2', S("22222")); |
| 278 | test(S("abcdefghijklmnopqrst"), 0, 20, 10, '2', S("2222222222")); |
| 279 | test(S("abcdefghijklmnopqrst"), 0, 20, 20, '2', S("22222222222222222222")); |
| 280 | test(S("abcdefghijklmnopqrst"), 0, 21, 0, '2', S("")); |
| 281 | test(S("abcdefghijklmnopqrst"), 0, 21, 5, '2', S("22222")); |
| 282 | test(S("abcdefghijklmnopqrst"), 0, 21, 10, '2', S("2222222222")); |
| 283 | test(S("abcdefghijklmnopqrst"), 0, 21, 20, '2', S("22222222222222222222")); |
| 284 | test(S("abcdefghijklmnopqrst"), 1, 0, 0, '2', S("abcdefghijklmnopqrst")); |
| 285 | test(S("abcdefghijklmnopqrst"), 1, 0, 5, '2', S("a22222bcdefghijklmnopqrst")); |
| 286 | test(S("abcdefghijklmnopqrst"), 1, 0, 10, '2', S("a2222222222bcdefghijklmnopqrst")); |
| 287 | test(S("abcdefghijklmnopqrst"), 1, 0, 20, '2', S("a22222222222222222222bcdefghijklmnopqrst")); |
| 288 | test(S("abcdefghijklmnopqrst"), 1, 1, 0, '2', S("acdefghijklmnopqrst")); |
| 289 | test(S("abcdefghijklmnopqrst"), 1, 1, 5, '2', S("a22222cdefghijklmnopqrst")); |
| 290 | test(S("abcdefghijklmnopqrst"), 1, 1, 10, '2', S("a2222222222cdefghijklmnopqrst")); |
| 291 | test(S("abcdefghijklmnopqrst"), 1, 1, 20, '2', S("a22222222222222222222cdefghijklmnopqrst")); |
| 292 | test(S("abcdefghijklmnopqrst"), 1, 9, 0, '2', S("aklmnopqrst")); |
| 293 | test(S("abcdefghijklmnopqrst"), 1, 9, 5, '2', S("a22222klmnopqrst")); |
| 294 | test(S("abcdefghijklmnopqrst"), 1, 9, 10, '2', S("a2222222222klmnopqrst")); |
| 295 | test(S("abcdefghijklmnopqrst"), 1, 9, 20, '2', S("a22222222222222222222klmnopqrst")); |
| 296 | test(S("abcdefghijklmnopqrst"), 1, 18, 0, '2', S("at")); |
| 297 | test(S("abcdefghijklmnopqrst"), 1, 18, 5, '2', S("a22222t")); |
| 298 | test(S("abcdefghijklmnopqrst"), 1, 18, 10, '2', S("a2222222222t")); |
| 299 | test(S("abcdefghijklmnopqrst"), 1, 18, 20, '2', S("a22222222222222222222t")); |
| 300 | test(S("abcdefghijklmnopqrst"), 1, 19, 0, '2', S("a")); |
| 301 | test(S("abcdefghijklmnopqrst"), 1, 19, 5, '2', S("a22222")); |
| 302 | test(S("abcdefghijklmnopqrst"), 1, 19, 10, '2', S("a2222222222")); |
| 303 | test(S("abcdefghijklmnopqrst"), 1, 19, 20, '2', S("a22222222222222222222")); |
| 304 | test(S("abcdefghijklmnopqrst"), 1, 20, 0, '2', S("a")); |
| 305 | test(S("abcdefghijklmnopqrst"), 1, 20, 5, '2', S("a22222")); |
| 306 | test(S("abcdefghijklmnopqrst"), 1, 20, 10, '2', S("a2222222222")); |
| 307 | test(S("abcdefghijklmnopqrst"), 1, 20, 20, '2', S("a22222222222222222222")); |
| 308 | test(S("abcdefghijklmnopqrst"), 10, 0, 0, '2', S("abcdefghijklmnopqrst")); |
| 309 | test(S("abcdefghijklmnopqrst"), 10, 0, 5, '2', S("abcdefghij22222klmnopqrst")); |
| 310 | test(S("abcdefghijklmnopqrst"), 10, 0, 10, '2', S("abcdefghij2222222222klmnopqrst")); |
| 311 | test(S("abcdefghijklmnopqrst"), 10, 0, 20, '2', S("abcdefghij22222222222222222222klmnopqrst")); |
| 312 | test(S("abcdefghijklmnopqrst"), 10, 1, 0, '2', S("abcdefghijlmnopqrst")); |
| 313 | test(S("abcdefghijklmnopqrst"), 10, 1, 5, '2', S("abcdefghij22222lmnopqrst")); |
| 314 | test(S("abcdefghijklmnopqrst"), 10, 1, 10, '2', S("abcdefghij2222222222lmnopqrst")); |
| 315 | test(S("abcdefghijklmnopqrst"), 10, 1, 20, '2', S("abcdefghij22222222222222222222lmnopqrst")); |
| 316 | test(S("abcdefghijklmnopqrst"), 10, 5, 0, '2', S("abcdefghijpqrst")); |
| 317 | test(S("abcdefghijklmnopqrst"), 10, 5, 5, '2', S("abcdefghij22222pqrst")); |
| 318 | test(S("abcdefghijklmnopqrst"), 10, 5, 10, '2', S("abcdefghij2222222222pqrst")); |
| 319 | test(S("abcdefghijklmnopqrst"), 10, 5, 20, '2', S("abcdefghij22222222222222222222pqrst")); |
| 320 | test(S("abcdefghijklmnopqrst"), 10, 9, 0, '2', S("abcdefghijt")); |
| 321 | test(S("abcdefghijklmnopqrst"), 10, 9, 5, '2', S("abcdefghij22222t")); |
| 322 | test(S("abcdefghijklmnopqrst"), 10, 9, 10, '2', S("abcdefghij2222222222t")); |
| 323 | test(S("abcdefghijklmnopqrst"), 10, 9, 20, '2', S("abcdefghij22222222222222222222t")); |
| 324 | test(S("abcdefghijklmnopqrst"), 10, 10, 0, '2', S("abcdefghij")); |
| 325 | test(S("abcdefghijklmnopqrst"), 10, 10, 5, '2', S("abcdefghij22222")); |
| 326 | test(S("abcdefghijklmnopqrst"), 10, 10, 10, '2', S("abcdefghij2222222222")); |
| 327 | test(S("abcdefghijklmnopqrst"), 10, 10, 20, '2', S("abcdefghij22222222222222222222")); |
| 328 | test(S("abcdefghijklmnopqrst"), 10, 11, 0, '2', S("abcdefghij")); |
| 329 | test(S("abcdefghijklmnopqrst"), 10, 11, 5, '2', S("abcdefghij22222")); |
| 330 | test(S("abcdefghijklmnopqrst"), 10, 11, 10, '2', S("abcdefghij2222222222")); |
| 331 | test(S("abcdefghijklmnopqrst"), 10, 11, 20, '2', S("abcdefghij22222222222222222222")); |
| 332 | test(S("abcdefghijklmnopqrst"), 19, 0, 0, '2', S("abcdefghijklmnopqrst")); |
| 333 | test(S("abcdefghijklmnopqrst"), 19, 0, 5, '2', S("abcdefghijklmnopqrs22222t")); |
| 334 | test(S("abcdefghijklmnopqrst"), 19, 0, 10, '2', S("abcdefghijklmnopqrs2222222222t")); |
| 335 | test(S("abcdefghijklmnopqrst"), 19, 0, 20, '2', S("abcdefghijklmnopqrs22222222222222222222t")); |
| 336 | test(S("abcdefghijklmnopqrst"), 19, 1, 0, '2', S("abcdefghijklmnopqrs")); |
| 337 | test(S("abcdefghijklmnopqrst"), 19, 1, 5, '2', S("abcdefghijklmnopqrs22222")); |
| 338 | test(S("abcdefghijklmnopqrst"), 19, 1, 10, '2', S("abcdefghijklmnopqrs2222222222")); |
| 339 | test(S("abcdefghijklmnopqrst"), 19, 1, 20, '2', S("abcdefghijklmnopqrs22222222222222222222")); |
| 340 | test(S("abcdefghijklmnopqrst"), 19, 2, 0, '2', S("abcdefghijklmnopqrs")); |
| 341 | test(S("abcdefghijklmnopqrst"), 19, 2, 5, '2', S("abcdefghijklmnopqrs22222")); |
| 342 | test(S("abcdefghijklmnopqrst"), 19, 2, 10, '2', S("abcdefghijklmnopqrs2222222222")); |
| 343 | test(S("abcdefghijklmnopqrst"), 19, 2, 20, '2', S("abcdefghijklmnopqrs22222222222222222222")); |
| 344 | test(S("abcdefghijklmnopqrst"), 20, 0, 0, '2', S("abcdefghijklmnopqrst")); |
| 345 | test(S("abcdefghijklmnopqrst"), 20, 0, 5, '2', S("abcdefghijklmnopqrst22222")); |
| 346 | test(S("abcdefghijklmnopqrst"), 20, 0, 10, '2', S("abcdefghijklmnopqrst2222222222")); |
| 347 | test(S("abcdefghijklmnopqrst"), 20, 0, 20, '2', S("abcdefghijklmnopqrst22222222222222222222")); |
| 348 | test(S("abcdefghijklmnopqrst"), 20, 1, 0, '2', S("abcdefghijklmnopqrst")); |
| 349 | test(S("abcdefghijklmnopqrst"), 20, 1, 5, '2', S("abcdefghijklmnopqrst22222")); |
| 350 | test(S("abcdefghijklmnopqrst"), 20, 1, 10, '2', S("abcdefghijklmnopqrst2222222222")); |
| 351 | test(S("abcdefghijklmnopqrst"), 20, 1, 20, '2', S("abcdefghijklmnopqrst22222222222222222222")); |
| 352 | test(S("abcdefghijklmnopqrst"), 21, 0, 0, '2', S("can't happen")); |
| 353 | test(S("abcdefghijklmnopqrst"), 21, 0, 5, '2', S("can't happen")); |
| 354 | test(S("abcdefghijklmnopqrst"), 21, 0, 10, '2', S("can't happen")); |
| 355 | test(S("abcdefghijklmnopqrst"), 21, 0, 20, '2', S("can't happen")); |
| 356 | } |
| 357 | |
| 358 | int main() |
| 359 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 360 | { |
| 361 | typedef std::string S; |
| 362 | test0<S>(); |
| 363 | test1<S>(); |
| 364 | test2<S>(); |
| 365 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 366 | #if __cplusplus >= 201103L |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 367 | { |
| 368 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 369 | test0<S>(); |
| 370 | test1<S>(); |
| 371 | test2<S>(); |
| 372 | } |
| 373 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | } |