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