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(const_iterator i1, const_iterator i2, const charT* s, size_type n);
13
14 #include <string>
15 #include <algorithm>
16 #include <cassert>
17
18 #include "test_macros.h"
19 #include "min_allocator.h"
20
21 template <class S>
22 void
test(S s,typename S::size_type pos1,typename S::size_type n1,const typename S::value_type * str,typename S::size_type n2,S expected)23 test(S s, typename S::size_type pos1, typename S::size_type n1, const typename S::value_type* str,
24 typename S::size_type n2, S expected)
25 {
26 typename S::size_type old_size = s.size();
27 typename S::const_iterator first = s.begin() + pos1;
28 typename S::const_iterator last = s.begin() + pos1 + n1;
29 typename S::size_type xlen = last - first;
30 s.replace(first, last, str, n2);
31 LIBCPP_ASSERT(s.__invariants());
32 assert(s == expected);
33 typename S::size_type rlen = n2;
34 assert(s.size() == old_size - xlen + rlen);
35 }
36
37 template <class S>
test0()38 void test0()
39 {
40 test(S(""), 0, 0, "", 0, S(""));
41 test(S(""), 0, 0, "12345", 0, S(""));
42 test(S(""), 0, 0, "12345", 1, S("1"));
43 test(S(""), 0, 0, "12345", 2, S("12"));
44 test(S(""), 0, 0, "12345", 4, S("1234"));
45 test(S(""), 0, 0, "12345", 5, S("12345"));
46 test(S(""), 0, 0, "1234567890", 0, S(""));
47 test(S(""), 0, 0, "1234567890", 1, S("1"));
48 test(S(""), 0, 0, "1234567890", 5, S("12345"));
49 test(S(""), 0, 0, "1234567890", 9, S("123456789"));
50 test(S(""), 0, 0, "1234567890", 10, S("1234567890"));
51 test(S(""), 0, 0, "12345678901234567890", 0, S(""));
52 test(S(""), 0, 0, "12345678901234567890", 1, S("1"));
53 test(S(""), 0, 0, "12345678901234567890", 10, S("1234567890"));
54 test(S(""), 0, 0, "12345678901234567890", 19, S("1234567890123456789"));
55 test(S(""), 0, 0, "12345678901234567890", 20, S("12345678901234567890"));
56 test(S("abcde"), 0, 0, "", 0, S("abcde"));
57 test(S("abcde"), 0, 0, "12345", 0, S("abcde"));
58 test(S("abcde"), 0, 0, "12345", 1, S("1abcde"));
59 test(S("abcde"), 0, 0, "12345", 2, S("12abcde"));
60 test(S("abcde"), 0, 0, "12345", 4, S("1234abcde"));
61 test(S("abcde"), 0, 0, "12345", 5, S("12345abcde"));
62 test(S("abcde"), 0, 0, "1234567890", 0, S("abcde"));
63 test(S("abcde"), 0, 0, "1234567890", 1, S("1abcde"));
64 test(S("abcde"), 0, 0, "1234567890", 5, S("12345abcde"));
65 test(S("abcde"), 0, 0, "1234567890", 9, S("123456789abcde"));
66 test(S("abcde"), 0, 0, "1234567890", 10, S("1234567890abcde"));
67 test(S("abcde"), 0, 0, "12345678901234567890", 0, S("abcde"));
68 test(S("abcde"), 0, 0, "12345678901234567890", 1, S("1abcde"));
69 test(S("abcde"), 0, 0, "12345678901234567890", 10, S("1234567890abcde"));
70 test(S("abcde"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcde"));
71 test(S("abcde"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcde"));
72 test(S("abcde"), 0, 1, "", 0, S("bcde"));
73 test(S("abcde"), 0, 1, "12345", 0, S("bcde"));
74 test(S("abcde"), 0, 1, "12345", 1, S("1bcde"));
75 test(S("abcde"), 0, 1, "12345", 2, S("12bcde"));
76 test(S("abcde"), 0, 1, "12345", 4, S("1234bcde"));
77 test(S("abcde"), 0, 1, "12345", 5, S("12345bcde"));
78 test(S("abcde"), 0, 1, "1234567890", 0, S("bcde"));
79 test(S("abcde"), 0, 1, "1234567890", 1, S("1bcde"));
80 test(S("abcde"), 0, 1, "1234567890", 5, S("12345bcde"));
81 test(S("abcde"), 0, 1, "1234567890", 9, S("123456789bcde"));
82 test(S("abcde"), 0, 1, "1234567890", 10, S("1234567890bcde"));
83 test(S("abcde"), 0, 1, "12345678901234567890", 0, S("bcde"));
84 test(S("abcde"), 0, 1, "12345678901234567890", 1, S("1bcde"));
85 test(S("abcde"), 0, 1, "12345678901234567890", 10, S("1234567890bcde"));
86 test(S("abcde"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcde"));
87 test(S("abcde"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcde"));
88 test(S("abcde"), 0, 2, "", 0, S("cde"));
89 test(S("abcde"), 0, 2, "12345", 0, S("cde"));
90 test(S("abcde"), 0, 2, "12345", 1, S("1cde"));
91 test(S("abcde"), 0, 2, "12345", 2, S("12cde"));
92 test(S("abcde"), 0, 2, "12345", 4, S("1234cde"));
93 test(S("abcde"), 0, 2, "12345", 5, S("12345cde"));
94 test(S("abcde"), 0, 2, "1234567890", 0, S("cde"));
95 test(S("abcde"), 0, 2, "1234567890", 1, S("1cde"));
96 test(S("abcde"), 0, 2, "1234567890", 5, S("12345cde"));
97 test(S("abcde"), 0, 2, "1234567890", 9, S("123456789cde"));
98 test(S("abcde"), 0, 2, "1234567890", 10, S("1234567890cde"));
99 test(S("abcde"), 0, 2, "12345678901234567890", 0, S("cde"));
100 test(S("abcde"), 0, 2, "12345678901234567890", 1, S("1cde"));
101 test(S("abcde"), 0, 2, "12345678901234567890", 10, S("1234567890cde"));
102 test(S("abcde"), 0, 2, "12345678901234567890", 19, S("1234567890123456789cde"));
103 test(S("abcde"), 0, 2, "12345678901234567890", 20, S("12345678901234567890cde"));
104 test(S("abcde"), 0, 4, "", 0, S("e"));
105 test(S("abcde"), 0, 4, "12345", 0, S("e"));
106 test(S("abcde"), 0, 4, "12345", 1, S("1e"));
107 test(S("abcde"), 0, 4, "12345", 2, S("12e"));
108 test(S("abcde"), 0, 4, "12345", 4, S("1234e"));
109 test(S("abcde"), 0, 4, "12345", 5, S("12345e"));
110 test(S("abcde"), 0, 4, "1234567890", 0, S("e"));
111 test(S("abcde"), 0, 4, "1234567890", 1, S("1e"));
112 test(S("abcde"), 0, 4, "1234567890", 5, S("12345e"));
113 test(S("abcde"), 0, 4, "1234567890", 9, S("123456789e"));
114 test(S("abcde"), 0, 4, "1234567890", 10, S("1234567890e"));
115 test(S("abcde"), 0, 4, "12345678901234567890", 0, S("e"));
116 test(S("abcde"), 0, 4, "12345678901234567890", 1, S("1e"));
117 test(S("abcde"), 0, 4, "12345678901234567890", 10, S("1234567890e"));
118 test(S("abcde"), 0, 4, "12345678901234567890", 19, S("1234567890123456789e"));
119 test(S("abcde"), 0, 4, "12345678901234567890", 20, S("12345678901234567890e"));
120 test(S("abcde"), 0, 5, "", 0, S(""));
121 test(S("abcde"), 0, 5, "12345", 0, S(""));
122 test(S("abcde"), 0, 5, "12345", 1, S("1"));
123 test(S("abcde"), 0, 5, "12345", 2, S("12"));
124 test(S("abcde"), 0, 5, "12345", 4, S("1234"));
125 test(S("abcde"), 0, 5, "12345", 5, S("12345"));
126 test(S("abcde"), 0, 5, "1234567890", 0, S(""));
127 test(S("abcde"), 0, 5, "1234567890", 1, S("1"));
128 test(S("abcde"), 0, 5, "1234567890", 5, S("12345"));
129 test(S("abcde"), 0, 5, "1234567890", 9, S("123456789"));
130 test(S("abcde"), 0, 5, "1234567890", 10, S("1234567890"));
131 test(S("abcde"), 0, 5, "12345678901234567890", 0, S(""));
132 test(S("abcde"), 0, 5, "12345678901234567890", 1, S("1"));
133 test(S("abcde"), 0, 5, "12345678901234567890", 10, S("1234567890"));
134 test(S("abcde"), 0, 5, "12345678901234567890", 19, S("1234567890123456789"));
135 test(S("abcde"), 0, 5, "12345678901234567890", 20, S("12345678901234567890"));
136 test(S("abcde"), 1, 0, "", 0, S("abcde"));
137 test(S("abcde"), 1, 0, "12345", 0, S("abcde"));
138 test(S("abcde"), 1, 0, "12345", 1, S("a1bcde"));
139 test(S("abcde"), 1, 0, "12345", 2, S("a12bcde"));
140 }
141
142 template <class S>
test1()143 void test1()
144 {
145 test(S("abcde"), 1, 0, "12345", 4, S("a1234bcde"));
146 test(S("abcde"), 1, 0, "12345", 5, S("a12345bcde"));
147 test(S("abcde"), 1, 0, "1234567890", 0, S("abcde"));
148 test(S("abcde"), 1, 0, "1234567890", 1, S("a1bcde"));
149 test(S("abcde"), 1, 0, "1234567890", 5, S("a12345bcde"));
150 test(S("abcde"), 1, 0, "1234567890", 9, S("a123456789bcde"));
151 test(S("abcde"), 1, 0, "1234567890", 10, S("a1234567890bcde"));
152 test(S("abcde"), 1, 0, "12345678901234567890", 0, S("abcde"));
153 test(S("abcde"), 1, 0, "12345678901234567890", 1, S("a1bcde"));
154 test(S("abcde"), 1, 0, "12345678901234567890", 10, S("a1234567890bcde"));
155 test(S("abcde"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcde"));
156 test(S("abcde"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcde"));
157 test(S("abcde"), 1, 1, "", 0, S("acde"));
158 test(S("abcde"), 1, 1, "12345", 0, S("acde"));
159 test(S("abcde"), 1, 1, "12345", 1, S("a1cde"));
160 test(S("abcde"), 1, 1, "12345", 2, S("a12cde"));
161 test(S("abcde"), 1, 1, "12345", 4, S("a1234cde"));
162 test(S("abcde"), 1, 1, "12345", 5, S("a12345cde"));
163 test(S("abcde"), 1, 1, "1234567890", 0, S("acde"));
164 test(S("abcde"), 1, 1, "1234567890", 1, S("a1cde"));
165 test(S("abcde"), 1, 1, "1234567890", 5, S("a12345cde"));
166 test(S("abcde"), 1, 1, "1234567890", 9, S("a123456789cde"));
167 test(S("abcde"), 1, 1, "1234567890", 10, S("a1234567890cde"));
168 test(S("abcde"), 1, 1, "12345678901234567890", 0, S("acde"));
169 test(S("abcde"), 1, 1, "12345678901234567890", 1, S("a1cde"));
170 test(S("abcde"), 1, 1, "12345678901234567890", 10, S("a1234567890cde"));
171 test(S("abcde"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cde"));
172 test(S("abcde"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cde"));
173 test(S("abcde"), 1, 2, "", 0, S("ade"));
174 test(S("abcde"), 1, 2, "12345", 0, S("ade"));
175 test(S("abcde"), 1, 2, "12345", 1, S("a1de"));
176 test(S("abcde"), 1, 2, "12345", 2, S("a12de"));
177 test(S("abcde"), 1, 2, "12345", 4, S("a1234de"));
178 test(S("abcde"), 1, 2, "12345", 5, S("a12345de"));
179 test(S("abcde"), 1, 2, "1234567890", 0, S("ade"));
180 test(S("abcde"), 1, 2, "1234567890", 1, S("a1de"));
181 test(S("abcde"), 1, 2, "1234567890", 5, S("a12345de"));
182 test(S("abcde"), 1, 2, "1234567890", 9, S("a123456789de"));
183 test(S("abcde"), 1, 2, "1234567890", 10, S("a1234567890de"));
184 test(S("abcde"), 1, 2, "12345678901234567890", 0, S("ade"));
185 test(S("abcde"), 1, 2, "12345678901234567890", 1, S("a1de"));
186 test(S("abcde"), 1, 2, "12345678901234567890", 10, S("a1234567890de"));
187 test(S("abcde"), 1, 2, "12345678901234567890", 19, S("a1234567890123456789de"));
188 test(S("abcde"), 1, 2, "12345678901234567890", 20, S("a12345678901234567890de"));
189 test(S("abcde"), 1, 3, "", 0, S("ae"));
190 test(S("abcde"), 1, 3, "12345", 0, S("ae"));
191 test(S("abcde"), 1, 3, "12345", 1, S("a1e"));
192 test(S("abcde"), 1, 3, "12345", 2, S("a12e"));
193 test(S("abcde"), 1, 3, "12345", 4, S("a1234e"));
194 test(S("abcde"), 1, 3, "12345", 5, S("a12345e"));
195 test(S("abcde"), 1, 3, "1234567890", 0, S("ae"));
196 test(S("abcde"), 1, 3, "1234567890", 1, S("a1e"));
197 test(S("abcde"), 1, 3, "1234567890", 5, S("a12345e"));
198 test(S("abcde"), 1, 3, "1234567890", 9, S("a123456789e"));
199 test(S("abcde"), 1, 3, "1234567890", 10, S("a1234567890e"));
200 test(S("abcde"), 1, 3, "12345678901234567890", 0, S("ae"));
201 test(S("abcde"), 1, 3, "12345678901234567890", 1, S("a1e"));
202 test(S("abcde"), 1, 3, "12345678901234567890", 10, S("a1234567890e"));
203 test(S("abcde"), 1, 3, "12345678901234567890", 19, S("a1234567890123456789e"));
204 test(S("abcde"), 1, 3, "12345678901234567890", 20, S("a12345678901234567890e"));
205 test(S("abcde"), 1, 4, "", 0, S("a"));
206 test(S("abcde"), 1, 4, "12345", 0, S("a"));
207 test(S("abcde"), 1, 4, "12345", 1, S("a1"));
208 test(S("abcde"), 1, 4, "12345", 2, S("a12"));
209 test(S("abcde"), 1, 4, "12345", 4, S("a1234"));
210 test(S("abcde"), 1, 4, "12345", 5, S("a12345"));
211 test(S("abcde"), 1, 4, "1234567890", 0, S("a"));
212 test(S("abcde"), 1, 4, "1234567890", 1, S("a1"));
213 test(S("abcde"), 1, 4, "1234567890", 5, S("a12345"));
214 test(S("abcde"), 1, 4, "1234567890", 9, S("a123456789"));
215 test(S("abcde"), 1, 4, "1234567890", 10, S("a1234567890"));
216 test(S("abcde"), 1, 4, "12345678901234567890", 0, S("a"));
217 test(S("abcde"), 1, 4, "12345678901234567890", 1, S("a1"));
218 test(S("abcde"), 1, 4, "12345678901234567890", 10, S("a1234567890"));
219 test(S("abcde"), 1, 4, "12345678901234567890", 19, S("a1234567890123456789"));
220 test(S("abcde"), 1, 4, "12345678901234567890", 20, S("a12345678901234567890"));
221 test(S("abcde"), 2, 0, "", 0, S("abcde"));
222 test(S("abcde"), 2, 0, "12345", 0, S("abcde"));
223 test(S("abcde"), 2, 0, "12345", 1, S("ab1cde"));
224 test(S("abcde"), 2, 0, "12345", 2, S("ab12cde"));
225 test(S("abcde"), 2, 0, "12345", 4, S("ab1234cde"));
226 test(S("abcde"), 2, 0, "12345", 5, S("ab12345cde"));
227 test(S("abcde"), 2, 0, "1234567890", 0, S("abcde"));
228 test(S("abcde"), 2, 0, "1234567890", 1, S("ab1cde"));
229 test(S("abcde"), 2, 0, "1234567890", 5, S("ab12345cde"));
230 test(S("abcde"), 2, 0, "1234567890", 9, S("ab123456789cde"));
231 test(S("abcde"), 2, 0, "1234567890", 10, S("ab1234567890cde"));
232 test(S("abcde"), 2, 0, "12345678901234567890", 0, S("abcde"));
233 test(S("abcde"), 2, 0, "12345678901234567890", 1, S("ab1cde"));
234 test(S("abcde"), 2, 0, "12345678901234567890", 10, S("ab1234567890cde"));
235 test(S("abcde"), 2, 0, "12345678901234567890", 19, S("ab1234567890123456789cde"));
236 test(S("abcde"), 2, 0, "12345678901234567890", 20, S("ab12345678901234567890cde"));
237 test(S("abcde"), 2, 1, "", 0, S("abde"));
238 test(S("abcde"), 2, 1, "12345", 0, S("abde"));
239 test(S("abcde"), 2, 1, "12345", 1, S("ab1de"));
240 test(S("abcde"), 2, 1, "12345", 2, S("ab12de"));
241 test(S("abcde"), 2, 1, "12345", 4, S("ab1234de"));
242 test(S("abcde"), 2, 1, "12345", 5, S("ab12345de"));
243 test(S("abcde"), 2, 1, "1234567890", 0, S("abde"));
244 test(S("abcde"), 2, 1, "1234567890", 1, S("ab1de"));
245 }
246
247 template <class S>
test2()248 void test2()
249 {
250 test(S("abcde"), 2, 1, "1234567890", 5, S("ab12345de"));
251 test(S("abcde"), 2, 1, "1234567890", 9, S("ab123456789de"));
252 test(S("abcde"), 2, 1, "1234567890", 10, S("ab1234567890de"));
253 test(S("abcde"), 2, 1, "12345678901234567890", 0, S("abde"));
254 test(S("abcde"), 2, 1, "12345678901234567890", 1, S("ab1de"));
255 test(S("abcde"), 2, 1, "12345678901234567890", 10, S("ab1234567890de"));
256 test(S("abcde"), 2, 1, "12345678901234567890", 19, S("ab1234567890123456789de"));
257 test(S("abcde"), 2, 1, "12345678901234567890", 20, S("ab12345678901234567890de"));
258 test(S("abcde"), 2, 2, "", 0, S("abe"));
259 test(S("abcde"), 2, 2, "12345", 0, S("abe"));
260 test(S("abcde"), 2, 2, "12345", 1, S("ab1e"));
261 test(S("abcde"), 2, 2, "12345", 2, S("ab12e"));
262 test(S("abcde"), 2, 2, "12345", 4, S("ab1234e"));
263 test(S("abcde"), 2, 2, "12345", 5, S("ab12345e"));
264 test(S("abcde"), 2, 2, "1234567890", 0, S("abe"));
265 test(S("abcde"), 2, 2, "1234567890", 1, S("ab1e"));
266 test(S("abcde"), 2, 2, "1234567890", 5, S("ab12345e"));
267 test(S("abcde"), 2, 2, "1234567890", 9, S("ab123456789e"));
268 test(S("abcde"), 2, 2, "1234567890", 10, S("ab1234567890e"));
269 test(S("abcde"), 2, 2, "12345678901234567890", 0, S("abe"));
270 test(S("abcde"), 2, 2, "12345678901234567890", 1, S("ab1e"));
271 test(S("abcde"), 2, 2, "12345678901234567890", 10, S("ab1234567890e"));
272 test(S("abcde"), 2, 2, "12345678901234567890", 19, S("ab1234567890123456789e"));
273 test(S("abcde"), 2, 2, "12345678901234567890", 20, S("ab12345678901234567890e"));
274 test(S("abcde"), 2, 3, "", 0, S("ab"));
275 test(S("abcde"), 2, 3, "12345", 0, S("ab"));
276 test(S("abcde"), 2, 3, "12345", 1, S("ab1"));
277 test(S("abcde"), 2, 3, "12345", 2, S("ab12"));
278 test(S("abcde"), 2, 3, "12345", 4, S("ab1234"));
279 test(S("abcde"), 2, 3, "12345", 5, S("ab12345"));
280 test(S("abcde"), 2, 3, "1234567890", 0, S("ab"));
281 test(S("abcde"), 2, 3, "1234567890", 1, S("ab1"));
282 test(S("abcde"), 2, 3, "1234567890", 5, S("ab12345"));
283 test(S("abcde"), 2, 3, "1234567890", 9, S("ab123456789"));
284 test(S("abcde"), 2, 3, "1234567890", 10, S("ab1234567890"));
285 test(S("abcde"), 2, 3, "12345678901234567890", 0, S("ab"));
286 test(S("abcde"), 2, 3, "12345678901234567890", 1, S("ab1"));
287 test(S("abcde"), 2, 3, "12345678901234567890", 10, S("ab1234567890"));
288 test(S("abcde"), 2, 3, "12345678901234567890", 19, S("ab1234567890123456789"));
289 test(S("abcde"), 2, 3, "12345678901234567890", 20, S("ab12345678901234567890"));
290 test(S("abcde"), 4, 0, "", 0, S("abcde"));
291 test(S("abcde"), 4, 0, "12345", 0, S("abcde"));
292 test(S("abcde"), 4, 0, "12345", 1, S("abcd1e"));
293 test(S("abcde"), 4, 0, "12345", 2, S("abcd12e"));
294 test(S("abcde"), 4, 0, "12345", 4, S("abcd1234e"));
295 test(S("abcde"), 4, 0, "12345", 5, S("abcd12345e"));
296 test(S("abcde"), 4, 0, "1234567890", 0, S("abcde"));
297 test(S("abcde"), 4, 0, "1234567890", 1, S("abcd1e"));
298 test(S("abcde"), 4, 0, "1234567890", 5, S("abcd12345e"));
299 test(S("abcde"), 4, 0, "1234567890", 9, S("abcd123456789e"));
300 test(S("abcde"), 4, 0, "1234567890", 10, S("abcd1234567890e"));
301 test(S("abcde"), 4, 0, "12345678901234567890", 0, S("abcde"));
302 test(S("abcde"), 4, 0, "12345678901234567890", 1, S("abcd1e"));
303 test(S("abcde"), 4, 0, "12345678901234567890", 10, S("abcd1234567890e"));
304 test(S("abcde"), 4, 0, "12345678901234567890", 19, S("abcd1234567890123456789e"));
305 test(S("abcde"), 4, 0, "12345678901234567890", 20, S("abcd12345678901234567890e"));
306 test(S("abcde"), 4, 1, "", 0, S("abcd"));
307 test(S("abcde"), 4, 1, "12345", 0, S("abcd"));
308 test(S("abcde"), 4, 1, "12345", 1, S("abcd1"));
309 test(S("abcde"), 4, 1, "12345", 2, S("abcd12"));
310 test(S("abcde"), 4, 1, "12345", 4, S("abcd1234"));
311 test(S("abcde"), 4, 1, "12345", 5, S("abcd12345"));
312 test(S("abcde"), 4, 1, "1234567890", 0, S("abcd"));
313 test(S("abcde"), 4, 1, "1234567890", 1, S("abcd1"));
314 test(S("abcde"), 4, 1, "1234567890", 5, S("abcd12345"));
315 test(S("abcde"), 4, 1, "1234567890", 9, S("abcd123456789"));
316 test(S("abcde"), 4, 1, "1234567890", 10, S("abcd1234567890"));
317 test(S("abcde"), 4, 1, "12345678901234567890", 0, S("abcd"));
318 test(S("abcde"), 4, 1, "12345678901234567890", 1, S("abcd1"));
319 test(S("abcde"), 4, 1, "12345678901234567890", 10, S("abcd1234567890"));
320 test(S("abcde"), 4, 1, "12345678901234567890", 19, S("abcd1234567890123456789"));
321 test(S("abcde"), 4, 1, "12345678901234567890", 20, S("abcd12345678901234567890"));
322 test(S("abcde"), 5, 0, "", 0, S("abcde"));
323 test(S("abcde"), 5, 0, "12345", 0, S("abcde"));
324 test(S("abcde"), 5, 0, "12345", 1, S("abcde1"));
325 test(S("abcde"), 5, 0, "12345", 2, S("abcde12"));
326 test(S("abcde"), 5, 0, "12345", 4, S("abcde1234"));
327 test(S("abcde"), 5, 0, "12345", 5, S("abcde12345"));
328 test(S("abcde"), 5, 0, "1234567890", 0, S("abcde"));
329 test(S("abcde"), 5, 0, "1234567890", 1, S("abcde1"));
330 test(S("abcde"), 5, 0, "1234567890", 5, S("abcde12345"));
331 test(S("abcde"), 5, 0, "1234567890", 9, S("abcde123456789"));
332 test(S("abcde"), 5, 0, "1234567890", 10, S("abcde1234567890"));
333 test(S("abcde"), 5, 0, "12345678901234567890", 0, S("abcde"));
334 test(S("abcde"), 5, 0, "12345678901234567890", 1, S("abcde1"));
335 test(S("abcde"), 5, 0, "12345678901234567890", 10, S("abcde1234567890"));
336 test(S("abcde"), 5, 0, "12345678901234567890", 19, S("abcde1234567890123456789"));
337 test(S("abcde"), 5, 0, "12345678901234567890", 20, S("abcde12345678901234567890"));
338 test(S("abcdefghij"), 0, 0, "", 0, S("abcdefghij"));
339 test(S("abcdefghij"), 0, 0, "12345", 0, S("abcdefghij"));
340 test(S("abcdefghij"), 0, 0, "12345", 1, S("1abcdefghij"));
341 test(S("abcdefghij"), 0, 0, "12345", 2, S("12abcdefghij"));
342 test(S("abcdefghij"), 0, 0, "12345", 4, S("1234abcdefghij"));
343 test(S("abcdefghij"), 0, 0, "12345", 5, S("12345abcdefghij"));
344 test(S("abcdefghij"), 0, 0, "1234567890", 0, S("abcdefghij"));
345 test(S("abcdefghij"), 0, 0, "1234567890", 1, S("1abcdefghij"));
346 test(S("abcdefghij"), 0, 0, "1234567890", 5, S("12345abcdefghij"));
347 test(S("abcdefghij"), 0, 0, "1234567890", 9, S("123456789abcdefghij"));
348 test(S("abcdefghij"), 0, 0, "1234567890", 10, S("1234567890abcdefghij"));
349 test(S("abcdefghij"), 0, 0, "12345678901234567890", 0, S("abcdefghij"));
350 }
351
352 template <class S>
test3()353 void test3()
354 {
355 test(S("abcdefghij"), 0, 0, "12345678901234567890", 1, S("1abcdefghij"));
356 test(S("abcdefghij"), 0, 0, "12345678901234567890", 10, S("1234567890abcdefghij"));
357 test(S("abcdefghij"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcdefghij"));
358 test(S("abcdefghij"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcdefghij"));
359 test(S("abcdefghij"), 0, 1, "", 0, S("bcdefghij"));
360 test(S("abcdefghij"), 0, 1, "12345", 0, S("bcdefghij"));
361 test(S("abcdefghij"), 0, 1, "12345", 1, S("1bcdefghij"));
362 test(S("abcdefghij"), 0, 1, "12345", 2, S("12bcdefghij"));
363 test(S("abcdefghij"), 0, 1, "12345", 4, S("1234bcdefghij"));
364 test(S("abcdefghij"), 0, 1, "12345", 5, S("12345bcdefghij"));
365 test(S("abcdefghij"), 0, 1, "1234567890", 0, S("bcdefghij"));
366 test(S("abcdefghij"), 0, 1, "1234567890", 1, S("1bcdefghij"));
367 test(S("abcdefghij"), 0, 1, "1234567890", 5, S("12345bcdefghij"));
368 test(S("abcdefghij"), 0, 1, "1234567890", 9, S("123456789bcdefghij"));
369 test(S("abcdefghij"), 0, 1, "1234567890", 10, S("1234567890bcdefghij"));
370 test(S("abcdefghij"), 0, 1, "12345678901234567890", 0, S("bcdefghij"));
371 test(S("abcdefghij"), 0, 1, "12345678901234567890", 1, S("1bcdefghij"));
372 test(S("abcdefghij"), 0, 1, "12345678901234567890", 10, S("1234567890bcdefghij"));
373 test(S("abcdefghij"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcdefghij"));
374 test(S("abcdefghij"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcdefghij"));
375 test(S("abcdefghij"), 0, 5, "", 0, S("fghij"));
376 test(S("abcdefghij"), 0, 5, "12345", 0, S("fghij"));
377 test(S("abcdefghij"), 0, 5, "12345", 1, S("1fghij"));
378 test(S("abcdefghij"), 0, 5, "12345", 2, S("12fghij"));
379 test(S("abcdefghij"), 0, 5, "12345", 4, S("1234fghij"));
380 test(S("abcdefghij"), 0, 5, "12345", 5, S("12345fghij"));
381 test(S("abcdefghij"), 0, 5, "1234567890", 0, S("fghij"));
382 test(S("abcdefghij"), 0, 5, "1234567890", 1, S("1fghij"));
383 test(S("abcdefghij"), 0, 5, "1234567890", 5, S("12345fghij"));
384 test(S("abcdefghij"), 0, 5, "1234567890", 9, S("123456789fghij"));
385 test(S("abcdefghij"), 0, 5, "1234567890", 10, S("1234567890fghij"));
386 test(S("abcdefghij"), 0, 5, "12345678901234567890", 0, S("fghij"));
387 test(S("abcdefghij"), 0, 5, "12345678901234567890", 1, S("1fghij"));
388 test(S("abcdefghij"), 0, 5, "12345678901234567890", 10, S("1234567890fghij"));
389 test(S("abcdefghij"), 0, 5, "12345678901234567890", 19, S("1234567890123456789fghij"));
390 test(S("abcdefghij"), 0, 5, "12345678901234567890", 20, S("12345678901234567890fghij"));
391 test(S("abcdefghij"), 0, 9, "", 0, S("j"));
392 test(S("abcdefghij"), 0, 9, "12345", 0, S("j"));
393 test(S("abcdefghij"), 0, 9, "12345", 1, S("1j"));
394 test(S("abcdefghij"), 0, 9, "12345", 2, S("12j"));
395 test(S("abcdefghij"), 0, 9, "12345", 4, S("1234j"));
396 test(S("abcdefghij"), 0, 9, "12345", 5, S("12345j"));
397 test(S("abcdefghij"), 0, 9, "1234567890", 0, S("j"));
398 test(S("abcdefghij"), 0, 9, "1234567890", 1, S("1j"));
399 test(S("abcdefghij"), 0, 9, "1234567890", 5, S("12345j"));
400 test(S("abcdefghij"), 0, 9, "1234567890", 9, S("123456789j"));
401 test(S("abcdefghij"), 0, 9, "1234567890", 10, S("1234567890j"));
402 test(S("abcdefghij"), 0, 9, "12345678901234567890", 0, S("j"));
403 test(S("abcdefghij"), 0, 9, "12345678901234567890", 1, S("1j"));
404 test(S("abcdefghij"), 0, 9, "12345678901234567890", 10, S("1234567890j"));
405 test(S("abcdefghij"), 0, 9, "12345678901234567890", 19, S("1234567890123456789j"));
406 test(S("abcdefghij"), 0, 9, "12345678901234567890", 20, S("12345678901234567890j"));
407 test(S("abcdefghij"), 0, 10, "", 0, S(""));
408 test(S("abcdefghij"), 0, 10, "12345", 0, S(""));
409 test(S("abcdefghij"), 0, 10, "12345", 1, S("1"));
410 test(S("abcdefghij"), 0, 10, "12345", 2, S("12"));
411 test(S("abcdefghij"), 0, 10, "12345", 4, S("1234"));
412 test(S("abcdefghij"), 0, 10, "12345", 5, S("12345"));
413 test(S("abcdefghij"), 0, 10, "1234567890", 0, S(""));
414 test(S("abcdefghij"), 0, 10, "1234567890", 1, S("1"));
415 test(S("abcdefghij"), 0, 10, "1234567890", 5, S("12345"));
416 test(S("abcdefghij"), 0, 10, "1234567890", 9, S("123456789"));
417 test(S("abcdefghij"), 0, 10, "1234567890", 10, S("1234567890"));
418 test(S("abcdefghij"), 0, 10, "12345678901234567890", 0, S(""));
419 test(S("abcdefghij"), 0, 10, "12345678901234567890", 1, S("1"));
420 test(S("abcdefghij"), 0, 10, "12345678901234567890", 10, S("1234567890"));
421 test(S("abcdefghij"), 0, 10, "12345678901234567890", 19, S("1234567890123456789"));
422 test(S("abcdefghij"), 0, 10, "12345678901234567890", 20, S("12345678901234567890"));
423 test(S("abcdefghij"), 1, 0, "", 0, S("abcdefghij"));
424 test(S("abcdefghij"), 1, 0, "12345", 0, S("abcdefghij"));
425 test(S("abcdefghij"), 1, 0, "12345", 1, S("a1bcdefghij"));
426 test(S("abcdefghij"), 1, 0, "12345", 2, S("a12bcdefghij"));
427 test(S("abcdefghij"), 1, 0, "12345", 4, S("a1234bcdefghij"));
428 test(S("abcdefghij"), 1, 0, "12345", 5, S("a12345bcdefghij"));
429 test(S("abcdefghij"), 1, 0, "1234567890", 0, S("abcdefghij"));
430 test(S("abcdefghij"), 1, 0, "1234567890", 1, S("a1bcdefghij"));
431 test(S("abcdefghij"), 1, 0, "1234567890", 5, S("a12345bcdefghij"));
432 test(S("abcdefghij"), 1, 0, "1234567890", 9, S("a123456789bcdefghij"));
433 test(S("abcdefghij"), 1, 0, "1234567890", 10, S("a1234567890bcdefghij"));
434 test(S("abcdefghij"), 1, 0, "12345678901234567890", 0, S("abcdefghij"));
435 test(S("abcdefghij"), 1, 0, "12345678901234567890", 1, S("a1bcdefghij"));
436 test(S("abcdefghij"), 1, 0, "12345678901234567890", 10, S("a1234567890bcdefghij"));
437 test(S("abcdefghij"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcdefghij"));
438 test(S("abcdefghij"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcdefghij"));
439 test(S("abcdefghij"), 1, 1, "", 0, S("acdefghij"));
440 test(S("abcdefghij"), 1, 1, "12345", 0, S("acdefghij"));
441 test(S("abcdefghij"), 1, 1, "12345", 1, S("a1cdefghij"));
442 test(S("abcdefghij"), 1, 1, "12345", 2, S("a12cdefghij"));
443 test(S("abcdefghij"), 1, 1, "12345", 4, S("a1234cdefghij"));
444 test(S("abcdefghij"), 1, 1, "12345", 5, S("a12345cdefghij"));
445 test(S("abcdefghij"), 1, 1, "1234567890", 0, S("acdefghij"));
446 test(S("abcdefghij"), 1, 1, "1234567890", 1, S("a1cdefghij"));
447 test(S("abcdefghij"), 1, 1, "1234567890", 5, S("a12345cdefghij"));
448 test(S("abcdefghij"), 1, 1, "1234567890", 9, S("a123456789cdefghij"));
449 test(S("abcdefghij"), 1, 1, "1234567890", 10, S("a1234567890cdefghij"));
450 test(S("abcdefghij"), 1, 1, "12345678901234567890", 0, S("acdefghij"));
451 test(S("abcdefghij"), 1, 1, "12345678901234567890", 1, S("a1cdefghij"));
452 test(S("abcdefghij"), 1, 1, "12345678901234567890", 10, S("a1234567890cdefghij"));
453 test(S("abcdefghij"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cdefghij"));
454 test(S("abcdefghij"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cdefghij"));
455 }
456
457 template <class S>
test4()458 void test4()
459 {
460 test(S("abcdefghij"), 1, 4, "", 0, S("afghij"));
461 test(S("abcdefghij"), 1, 4, "12345", 0, S("afghij"));
462 test(S("abcdefghij"), 1, 4, "12345", 1, S("a1fghij"));
463 test(S("abcdefghij"), 1, 4, "12345", 2, S("a12fghij"));
464 test(S("abcdefghij"), 1, 4, "12345", 4, S("a1234fghij"));
465 test(S("abcdefghij"), 1, 4, "12345", 5, S("a12345fghij"));
466 test(S("abcdefghij"), 1, 4, "1234567890", 0, S("afghij"));
467 test(S("abcdefghij"), 1, 4, "1234567890", 1, S("a1fghij"));
468 test(S("abcdefghij"), 1, 4, "1234567890", 5, S("a12345fghij"));
469 test(S("abcdefghij"), 1, 4, "1234567890", 9, S("a123456789fghij"));
470 test(S("abcdefghij"), 1, 4, "1234567890", 10, S("a1234567890fghij"));
471 test(S("abcdefghij"), 1, 4, "12345678901234567890", 0, S("afghij"));
472 test(S("abcdefghij"), 1, 4, "12345678901234567890", 1, S("a1fghij"));
473 test(S("abcdefghij"), 1, 4, "12345678901234567890", 10, S("a1234567890fghij"));
474 test(S("abcdefghij"), 1, 4, "12345678901234567890", 19, S("a1234567890123456789fghij"));
475 test(S("abcdefghij"), 1, 4, "12345678901234567890", 20, S("a12345678901234567890fghij"));
476 test(S("abcdefghij"), 1, 8, "", 0, S("aj"));
477 test(S("abcdefghij"), 1, 8, "12345", 0, S("aj"));
478 test(S("abcdefghij"), 1, 8, "12345", 1, S("a1j"));
479 test(S("abcdefghij"), 1, 8, "12345", 2, S("a12j"));
480 test(S("abcdefghij"), 1, 8, "12345", 4, S("a1234j"));
481 test(S("abcdefghij"), 1, 8, "12345", 5, S("a12345j"));
482 test(S("abcdefghij"), 1, 8, "1234567890", 0, S("aj"));
483 test(S("abcdefghij"), 1, 8, "1234567890", 1, S("a1j"));
484 test(S("abcdefghij"), 1, 8, "1234567890", 5, S("a12345j"));
485 test(S("abcdefghij"), 1, 8, "1234567890", 9, S("a123456789j"));
486 test(S("abcdefghij"), 1, 8, "1234567890", 10, S("a1234567890j"));
487 test(S("abcdefghij"), 1, 8, "12345678901234567890", 0, S("aj"));
488 test(S("abcdefghij"), 1, 8, "12345678901234567890", 1, S("a1j"));
489 test(S("abcdefghij"), 1, 8, "12345678901234567890", 10, S("a1234567890j"));
490 test(S("abcdefghij"), 1, 8, "12345678901234567890", 19, S("a1234567890123456789j"));
491 test(S("abcdefghij"), 1, 8, "12345678901234567890", 20, S("a12345678901234567890j"));
492 test(S("abcdefghij"), 1, 9, "", 0, S("a"));
493 test(S("abcdefghij"), 1, 9, "12345", 0, S("a"));
494 test(S("abcdefghij"), 1, 9, "12345", 1, S("a1"));
495 test(S("abcdefghij"), 1, 9, "12345", 2, S("a12"));
496 test(S("abcdefghij"), 1, 9, "12345", 4, S("a1234"));
497 test(S("abcdefghij"), 1, 9, "12345", 5, S("a12345"));
498 test(S("abcdefghij"), 1, 9, "1234567890", 0, S("a"));
499 test(S("abcdefghij"), 1, 9, "1234567890", 1, S("a1"));
500 test(S("abcdefghij"), 1, 9, "1234567890", 5, S("a12345"));
501 test(S("abcdefghij"), 1, 9, "1234567890", 9, S("a123456789"));
502 test(S("abcdefghij"), 1, 9, "1234567890", 10, S("a1234567890"));
503 test(S("abcdefghij"), 1, 9, "12345678901234567890", 0, S("a"));
504 test(S("abcdefghij"), 1, 9, "12345678901234567890", 1, S("a1"));
505 test(S("abcdefghij"), 1, 9, "12345678901234567890", 10, S("a1234567890"));
506 test(S("abcdefghij"), 1, 9, "12345678901234567890", 19, S("a1234567890123456789"));
507 test(S("abcdefghij"), 1, 9, "12345678901234567890", 20, S("a12345678901234567890"));
508 test(S("abcdefghij"), 5, 0, "", 0, S("abcdefghij"));
509 test(S("abcdefghij"), 5, 0, "12345", 0, S("abcdefghij"));
510 test(S("abcdefghij"), 5, 0, "12345", 1, S("abcde1fghij"));
511 test(S("abcdefghij"), 5, 0, "12345", 2, S("abcde12fghij"));
512 test(S("abcdefghij"), 5, 0, "12345", 4, S("abcde1234fghij"));
513 test(S("abcdefghij"), 5, 0, "12345", 5, S("abcde12345fghij"));
514 test(S("abcdefghij"), 5, 0, "1234567890", 0, S("abcdefghij"));
515 test(S("abcdefghij"), 5, 0, "1234567890", 1, S("abcde1fghij"));
516 test(S("abcdefghij"), 5, 0, "1234567890", 5, S("abcde12345fghij"));
517 test(S("abcdefghij"), 5, 0, "1234567890", 9, S("abcde123456789fghij"));
518 test(S("abcdefghij"), 5, 0, "1234567890", 10, S("abcde1234567890fghij"));
519 test(S("abcdefghij"), 5, 0, "12345678901234567890", 0, S("abcdefghij"));
520 test(S("abcdefghij"), 5, 0, "12345678901234567890", 1, S("abcde1fghij"));
521 test(S("abcdefghij"), 5, 0, "12345678901234567890", 10, S("abcde1234567890fghij"));
522 test(S("abcdefghij"), 5, 0, "12345678901234567890", 19, S("abcde1234567890123456789fghij"));
523 test(S("abcdefghij"), 5, 0, "12345678901234567890", 20, S("abcde12345678901234567890fghij"));
524 test(S("abcdefghij"), 5, 1, "", 0, S("abcdeghij"));
525 test(S("abcdefghij"), 5, 1, "12345", 0, S("abcdeghij"));
526 test(S("abcdefghij"), 5, 1, "12345", 1, S("abcde1ghij"));
527 test(S("abcdefghij"), 5, 1, "12345", 2, S("abcde12ghij"));
528 test(S("abcdefghij"), 5, 1, "12345", 4, S("abcde1234ghij"));
529 test(S("abcdefghij"), 5, 1, "12345", 5, S("abcde12345ghij"));
530 test(S("abcdefghij"), 5, 1, "1234567890", 0, S("abcdeghij"));
531 test(S("abcdefghij"), 5, 1, "1234567890", 1, S("abcde1ghij"));
532 test(S("abcdefghij"), 5, 1, "1234567890", 5, S("abcde12345ghij"));
533 test(S("abcdefghij"), 5, 1, "1234567890", 9, S("abcde123456789ghij"));
534 test(S("abcdefghij"), 5, 1, "1234567890", 10, S("abcde1234567890ghij"));
535 test(S("abcdefghij"), 5, 1, "12345678901234567890", 0, S("abcdeghij"));
536 test(S("abcdefghij"), 5, 1, "12345678901234567890", 1, S("abcde1ghij"));
537 test(S("abcdefghij"), 5, 1, "12345678901234567890", 10, S("abcde1234567890ghij"));
538 test(S("abcdefghij"), 5, 1, "12345678901234567890", 19, S("abcde1234567890123456789ghij"));
539 test(S("abcdefghij"), 5, 1, "12345678901234567890", 20, S("abcde12345678901234567890ghij"));
540 test(S("abcdefghij"), 5, 2, "", 0, S("abcdehij"));
541 test(S("abcdefghij"), 5, 2, "12345", 0, S("abcdehij"));
542 test(S("abcdefghij"), 5, 2, "12345", 1, S("abcde1hij"));
543 test(S("abcdefghij"), 5, 2, "12345", 2, S("abcde12hij"));
544 test(S("abcdefghij"), 5, 2, "12345", 4, S("abcde1234hij"));
545 test(S("abcdefghij"), 5, 2, "12345", 5, S("abcde12345hij"));
546 test(S("abcdefghij"), 5, 2, "1234567890", 0, S("abcdehij"));
547 test(S("abcdefghij"), 5, 2, "1234567890", 1, S("abcde1hij"));
548 test(S("abcdefghij"), 5, 2, "1234567890", 5, S("abcde12345hij"));
549 test(S("abcdefghij"), 5, 2, "1234567890", 9, S("abcde123456789hij"));
550 test(S("abcdefghij"), 5, 2, "1234567890", 10, S("abcde1234567890hij"));
551 test(S("abcdefghij"), 5, 2, "12345678901234567890", 0, S("abcdehij"));
552 test(S("abcdefghij"), 5, 2, "12345678901234567890", 1, S("abcde1hij"));
553 test(S("abcdefghij"), 5, 2, "12345678901234567890", 10, S("abcde1234567890hij"));
554 test(S("abcdefghij"), 5, 2, "12345678901234567890", 19, S("abcde1234567890123456789hij"));
555 test(S("abcdefghij"), 5, 2, "12345678901234567890", 20, S("abcde12345678901234567890hij"));
556 test(S("abcdefghij"), 5, 4, "", 0, S("abcdej"));
557 test(S("abcdefghij"), 5, 4, "12345", 0, S("abcdej"));
558 test(S("abcdefghij"), 5, 4, "12345", 1, S("abcde1j"));
559 test(S("abcdefghij"), 5, 4, "12345", 2, S("abcde12j"));
560 }
561
562 template <class S>
test5()563 void test5()
564 {
565 test(S("abcdefghij"), 5, 4, "12345", 4, S("abcde1234j"));
566 test(S("abcdefghij"), 5, 4, "12345", 5, S("abcde12345j"));
567 test(S("abcdefghij"), 5, 4, "1234567890", 0, S("abcdej"));
568 test(S("abcdefghij"), 5, 4, "1234567890", 1, S("abcde1j"));
569 test(S("abcdefghij"), 5, 4, "1234567890", 5, S("abcde12345j"));
570 test(S("abcdefghij"), 5, 4, "1234567890", 9, S("abcde123456789j"));
571 test(S("abcdefghij"), 5, 4, "1234567890", 10, S("abcde1234567890j"));
572 test(S("abcdefghij"), 5, 4, "12345678901234567890", 0, S("abcdej"));
573 test(S("abcdefghij"), 5, 4, "12345678901234567890", 1, S("abcde1j"));
574 test(S("abcdefghij"), 5, 4, "12345678901234567890", 10, S("abcde1234567890j"));
575 test(S("abcdefghij"), 5, 4, "12345678901234567890", 19, S("abcde1234567890123456789j"));
576 test(S("abcdefghij"), 5, 4, "12345678901234567890", 20, S("abcde12345678901234567890j"));
577 test(S("abcdefghij"), 5, 5, "", 0, S("abcde"));
578 test(S("abcdefghij"), 5, 5, "12345", 0, S("abcde"));
579 test(S("abcdefghij"), 5, 5, "12345", 1, S("abcde1"));
580 test(S("abcdefghij"), 5, 5, "12345", 2, S("abcde12"));
581 test(S("abcdefghij"), 5, 5, "12345", 4, S("abcde1234"));
582 test(S("abcdefghij"), 5, 5, "12345", 5, S("abcde12345"));
583 test(S("abcdefghij"), 5, 5, "1234567890", 0, S("abcde"));
584 test(S("abcdefghij"), 5, 5, "1234567890", 1, S("abcde1"));
585 test(S("abcdefghij"), 5, 5, "1234567890", 5, S("abcde12345"));
586 test(S("abcdefghij"), 5, 5, "1234567890", 9, S("abcde123456789"));
587 test(S("abcdefghij"), 5, 5, "1234567890", 10, S("abcde1234567890"));
588 test(S("abcdefghij"), 5, 5, "12345678901234567890", 0, S("abcde"));
589 test(S("abcdefghij"), 5, 5, "12345678901234567890", 1, S("abcde1"));
590 test(S("abcdefghij"), 5, 5, "12345678901234567890", 10, S("abcde1234567890"));
591 test(S("abcdefghij"), 5, 5, "12345678901234567890", 19, S("abcde1234567890123456789"));
592 test(S("abcdefghij"), 5, 5, "12345678901234567890", 20, S("abcde12345678901234567890"));
593 test(S("abcdefghij"), 9, 0, "", 0, S("abcdefghij"));
594 test(S("abcdefghij"), 9, 0, "12345", 0, S("abcdefghij"));
595 test(S("abcdefghij"), 9, 0, "12345", 1, S("abcdefghi1j"));
596 test(S("abcdefghij"), 9, 0, "12345", 2, S("abcdefghi12j"));
597 test(S("abcdefghij"), 9, 0, "12345", 4, S("abcdefghi1234j"));
598 test(S("abcdefghij"), 9, 0, "12345", 5, S("abcdefghi12345j"));
599 test(S("abcdefghij"), 9, 0, "1234567890", 0, S("abcdefghij"));
600 test(S("abcdefghij"), 9, 0, "1234567890", 1, S("abcdefghi1j"));
601 test(S("abcdefghij"), 9, 0, "1234567890", 5, S("abcdefghi12345j"));
602 test(S("abcdefghij"), 9, 0, "1234567890", 9, S("abcdefghi123456789j"));
603 test(S("abcdefghij"), 9, 0, "1234567890", 10, S("abcdefghi1234567890j"));
604 test(S("abcdefghij"), 9, 0, "12345678901234567890", 0, S("abcdefghij"));
605 test(S("abcdefghij"), 9, 0, "12345678901234567890", 1, S("abcdefghi1j"));
606 test(S("abcdefghij"), 9, 0, "12345678901234567890", 10, S("abcdefghi1234567890j"));
607 test(S("abcdefghij"), 9, 0, "12345678901234567890", 19, S("abcdefghi1234567890123456789j"));
608 test(S("abcdefghij"), 9, 0, "12345678901234567890", 20, S("abcdefghi12345678901234567890j"));
609 test(S("abcdefghij"), 9, 1, "", 0, S("abcdefghi"));
610 test(S("abcdefghij"), 9, 1, "12345", 0, S("abcdefghi"));
611 test(S("abcdefghij"), 9, 1, "12345", 1, S("abcdefghi1"));
612 test(S("abcdefghij"), 9, 1, "12345", 2, S("abcdefghi12"));
613 test(S("abcdefghij"), 9, 1, "12345", 4, S("abcdefghi1234"));
614 test(S("abcdefghij"), 9, 1, "12345", 5, S("abcdefghi12345"));
615 test(S("abcdefghij"), 9, 1, "1234567890", 0, S("abcdefghi"));
616 test(S("abcdefghij"), 9, 1, "1234567890", 1, S("abcdefghi1"));
617 test(S("abcdefghij"), 9, 1, "1234567890", 5, S("abcdefghi12345"));
618 test(S("abcdefghij"), 9, 1, "1234567890", 9, S("abcdefghi123456789"));
619 test(S("abcdefghij"), 9, 1, "1234567890", 10, S("abcdefghi1234567890"));
620 test(S("abcdefghij"), 9, 1, "12345678901234567890", 0, S("abcdefghi"));
621 test(S("abcdefghij"), 9, 1, "12345678901234567890", 1, S("abcdefghi1"));
622 test(S("abcdefghij"), 9, 1, "12345678901234567890", 10, S("abcdefghi1234567890"));
623 test(S("abcdefghij"), 9, 1, "12345678901234567890", 19, S("abcdefghi1234567890123456789"));
624 test(S("abcdefghij"), 9, 1, "12345678901234567890", 20, S("abcdefghi12345678901234567890"));
625 test(S("abcdefghij"), 10, 0, "", 0, S("abcdefghij"));
626 test(S("abcdefghij"), 10, 0, "12345", 0, S("abcdefghij"));
627 test(S("abcdefghij"), 10, 0, "12345", 1, S("abcdefghij1"));
628 test(S("abcdefghij"), 10, 0, "12345", 2, S("abcdefghij12"));
629 test(S("abcdefghij"), 10, 0, "12345", 4, S("abcdefghij1234"));
630 test(S("abcdefghij"), 10, 0, "12345", 5, S("abcdefghij12345"));
631 test(S("abcdefghij"), 10, 0, "1234567890", 0, S("abcdefghij"));
632 test(S("abcdefghij"), 10, 0, "1234567890", 1, S("abcdefghij1"));
633 test(S("abcdefghij"), 10, 0, "1234567890", 5, S("abcdefghij12345"));
634 test(S("abcdefghij"), 10, 0, "1234567890", 9, S("abcdefghij123456789"));
635 test(S("abcdefghij"), 10, 0, "1234567890", 10, S("abcdefghij1234567890"));
636 test(S("abcdefghij"), 10, 0, "12345678901234567890", 0, S("abcdefghij"));
637 test(S("abcdefghij"), 10, 0, "12345678901234567890", 1, S("abcdefghij1"));
638 test(S("abcdefghij"), 10, 0, "12345678901234567890", 10, S("abcdefghij1234567890"));
639 test(S("abcdefghij"), 10, 0, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
640 test(S("abcdefghij"), 10, 0, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
641 test(S("abcdefghijklmnopqrst"), 0, 0, "", 0, S("abcdefghijklmnopqrst"));
642 test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 0, S("abcdefghijklmnopqrst"));
643 test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 1, S("1abcdefghijklmnopqrst"));
644 test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 2, S("12abcdefghijklmnopqrst"));
645 test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 4, S("1234abcdefghijklmnopqrst"));
646 test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 5, S("12345abcdefghijklmnopqrst"));
647 test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
648 test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 1, S("1abcdefghijklmnopqrst"));
649 test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 5, S("12345abcdefghijklmnopqrst"));
650 test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 9, S("123456789abcdefghijklmnopqrst"));
651 test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 10, S("1234567890abcdefghijklmnopqrst"));
652 test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
653 test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 1, S("1abcdefghijklmnopqrst"));
654 test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 10, S("1234567890abcdefghijklmnopqrst"));
655 test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcdefghijklmnopqrst"));
656 test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcdefghijklmnopqrst"));
657 test(S("abcdefghijklmnopqrst"), 0, 1, "", 0, S("bcdefghijklmnopqrst"));
658 test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 0, S("bcdefghijklmnopqrst"));
659 test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 1, S("1bcdefghijklmnopqrst"));
660 test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 2, S("12bcdefghijklmnopqrst"));
661 test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 4, S("1234bcdefghijklmnopqrst"));
662 test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 5, S("12345bcdefghijklmnopqrst"));
663 test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 0, S("bcdefghijklmnopqrst"));
664 test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 1, S("1bcdefghijklmnopqrst"));
665 }
666
667 template <class S>
test6()668 void test6()
669 {
670 test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 5, S("12345bcdefghijklmnopqrst"));
671 test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 9, S("123456789bcdefghijklmnopqrst"));
672 test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 10, S("1234567890bcdefghijklmnopqrst"));
673 test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 0, S("bcdefghijklmnopqrst"));
674 test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 1, S("1bcdefghijklmnopqrst"));
675 test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 10, S("1234567890bcdefghijklmnopqrst"));
676 test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcdefghijklmnopqrst"));
677 test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcdefghijklmnopqrst"));
678 test(S("abcdefghijklmnopqrst"), 0, 10, "", 0, S("klmnopqrst"));
679 test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 0, S("klmnopqrst"));
680 test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 1, S("1klmnopqrst"));
681 test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 2, S("12klmnopqrst"));
682 test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 4, S("1234klmnopqrst"));
683 test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 5, S("12345klmnopqrst"));
684 test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 0, S("klmnopqrst"));
685 test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 1, S("1klmnopqrst"));
686 test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 5, S("12345klmnopqrst"));
687 test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 9, S("123456789klmnopqrst"));
688 test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 10, S("1234567890klmnopqrst"));
689 test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 0, S("klmnopqrst"));
690 test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 1, S("1klmnopqrst"));
691 test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 10, S("1234567890klmnopqrst"));
692 test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 19, S("1234567890123456789klmnopqrst"));
693 test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 20, S("12345678901234567890klmnopqrst"));
694 test(S("abcdefghijklmnopqrst"), 0, 19, "", 0, S("t"));
695 test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 0, S("t"));
696 test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 1, S("1t"));
697 test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 2, S("12t"));
698 test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 4, S("1234t"));
699 test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 5, S("12345t"));
700 test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 0, S("t"));
701 test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 1, S("1t"));
702 test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 5, S("12345t"));
703 test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 9, S("123456789t"));
704 test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 10, S("1234567890t"));
705 test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 0, S("t"));
706 test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 1, S("1t"));
707 test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 10, S("1234567890t"));
708 test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 19, S("1234567890123456789t"));
709 test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 20, S("12345678901234567890t"));
710 test(S("abcdefghijklmnopqrst"), 0, 20, "", 0, S(""));
711 test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 0, S(""));
712 test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 1, S("1"));
713 test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 2, S("12"));
714 test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 4, S("1234"));
715 test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 5, S("12345"));
716 test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 0, S(""));
717 test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 1, S("1"));
718 test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 5, S("12345"));
719 test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 9, S("123456789"));
720 test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 10, S("1234567890"));
721 test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 0, S(""));
722 test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 1, S("1"));
723 test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 10, S("1234567890"));
724 test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 19, S("1234567890123456789"));
725 test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 20, S("12345678901234567890"));
726 test(S("abcdefghijklmnopqrst"), 1, 0, "", 0, S("abcdefghijklmnopqrst"));
727 test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 0, S("abcdefghijklmnopqrst"));
728 test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 1, S("a1bcdefghijklmnopqrst"));
729 test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 2, S("a12bcdefghijklmnopqrst"));
730 test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 4, S("a1234bcdefghijklmnopqrst"));
731 test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 5, S("a12345bcdefghijklmnopqrst"));
732 test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
733 test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 1, S("a1bcdefghijklmnopqrst"));
734 test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 5, S("a12345bcdefghijklmnopqrst"));
735 test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 9, S("a123456789bcdefghijklmnopqrst"));
736 test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
737 test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
738 test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 1, S("a1bcdefghijklmnopqrst"));
739 test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
740 test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcdefghijklmnopqrst"));
741 test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcdefghijklmnopqrst"));
742 test(S("abcdefghijklmnopqrst"), 1, 1, "", 0, S("acdefghijklmnopqrst"));
743 test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 0, S("acdefghijklmnopqrst"));
744 test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 1, S("a1cdefghijklmnopqrst"));
745 test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 2, S("a12cdefghijklmnopqrst"));
746 test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 4, S("a1234cdefghijklmnopqrst"));
747 test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 5, S("a12345cdefghijklmnopqrst"));
748 test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 0, S("acdefghijklmnopqrst"));
749 test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 1, S("a1cdefghijklmnopqrst"));
750 test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 5, S("a12345cdefghijklmnopqrst"));
751 test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 9, S("a123456789cdefghijklmnopqrst"));
752 test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 10, S("a1234567890cdefghijklmnopqrst"));
753 test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 0, S("acdefghijklmnopqrst"));
754 test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 1, S("a1cdefghijklmnopqrst"));
755 test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 10, S("a1234567890cdefghijklmnopqrst"));
756 test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cdefghijklmnopqrst"));
757 test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cdefghijklmnopqrst"));
758 test(S("abcdefghijklmnopqrst"), 1, 9, "", 0, S("aklmnopqrst"));
759 test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 0, S("aklmnopqrst"));
760 test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 1, S("a1klmnopqrst"));
761 test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 2, S("a12klmnopqrst"));
762 test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 4, S("a1234klmnopqrst"));
763 test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 5, S("a12345klmnopqrst"));
764 test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 0, S("aklmnopqrst"));
765 test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 1, S("a1klmnopqrst"));
766 test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 5, S("a12345klmnopqrst"));
767 test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 9, S("a123456789klmnopqrst"));
768 test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 10, S("a1234567890klmnopqrst"));
769 test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 0, S("aklmnopqrst"));
770 }
771
772 template <class S>
test7()773 void test7()
774 {
775 test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 1, S("a1klmnopqrst"));
776 test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 10, S("a1234567890klmnopqrst"));
777 test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 19, S("a1234567890123456789klmnopqrst"));
778 test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 20, S("a12345678901234567890klmnopqrst"));
779 test(S("abcdefghijklmnopqrst"), 1, 18, "", 0, S("at"));
780 test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 0, S("at"));
781 test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 1, S("a1t"));
782 test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 2, S("a12t"));
783 test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 4, S("a1234t"));
784 test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 5, S("a12345t"));
785 test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 0, S("at"));
786 test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 1, S("a1t"));
787 test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 5, S("a12345t"));
788 test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 9, S("a123456789t"));
789 test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 10, S("a1234567890t"));
790 test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 0, S("at"));
791 test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 1, S("a1t"));
792 test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 10, S("a1234567890t"));
793 test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 19, S("a1234567890123456789t"));
794 test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 20, S("a12345678901234567890t"));
795 test(S("abcdefghijklmnopqrst"), 1, 19, "", 0, S("a"));
796 test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 0, S("a"));
797 test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 1, S("a1"));
798 test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 2, S("a12"));
799 test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 4, S("a1234"));
800 test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 5, S("a12345"));
801 test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 0, S("a"));
802 test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 1, S("a1"));
803 test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 5, S("a12345"));
804 test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 9, S("a123456789"));
805 test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 10, S("a1234567890"));
806 test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 0, S("a"));
807 test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 1, S("a1"));
808 test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 10, S("a1234567890"));
809 test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 19, S("a1234567890123456789"));
810 test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 20, S("a12345678901234567890"));
811 test(S("abcdefghijklmnopqrst"), 10, 0, "", 0, S("abcdefghijklmnopqrst"));
812 test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 0, S("abcdefghijklmnopqrst"));
813 test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 1, S("abcdefghij1klmnopqrst"));
814 test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 2, S("abcdefghij12klmnopqrst"));
815 test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 4, S("abcdefghij1234klmnopqrst"));
816 test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 5, S("abcdefghij12345klmnopqrst"));
817 test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
818 test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 1, S("abcdefghij1klmnopqrst"));
819 test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 5, S("abcdefghij12345klmnopqrst"));
820 test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 9, S("abcdefghij123456789klmnopqrst"));
821 test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 10, S("abcdefghij1234567890klmnopqrst"));
822 test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
823 test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 1, S("abcdefghij1klmnopqrst"));
824 test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 10, S("abcdefghij1234567890klmnopqrst"));
825 test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 19, S("abcdefghij1234567890123456789klmnopqrst"));
826 test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 20, S("abcdefghij12345678901234567890klmnopqrst"));
827 test(S("abcdefghijklmnopqrst"), 10, 1, "", 0, S("abcdefghijlmnopqrst"));
828 test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 0, S("abcdefghijlmnopqrst"));
829 test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 1, S("abcdefghij1lmnopqrst"));
830 test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 2, S("abcdefghij12lmnopqrst"));
831 test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 4, S("abcdefghij1234lmnopqrst"));
832 test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 5, S("abcdefghij12345lmnopqrst"));
833 test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 0, S("abcdefghijlmnopqrst"));
834 test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 1, S("abcdefghij1lmnopqrst"));
835 test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 5, S("abcdefghij12345lmnopqrst"));
836 test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 9, S("abcdefghij123456789lmnopqrst"));
837 test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 10, S("abcdefghij1234567890lmnopqrst"));
838 test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 0, S("abcdefghijlmnopqrst"));
839 test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 1, S("abcdefghij1lmnopqrst"));
840 test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 10, S("abcdefghij1234567890lmnopqrst"));
841 test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 19, S("abcdefghij1234567890123456789lmnopqrst"));
842 test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 20, S("abcdefghij12345678901234567890lmnopqrst"));
843 test(S("abcdefghijklmnopqrst"), 10, 5, "", 0, S("abcdefghijpqrst"));
844 test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 0, S("abcdefghijpqrst"));
845 test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 1, S("abcdefghij1pqrst"));
846 test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 2, S("abcdefghij12pqrst"));
847 test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 4, S("abcdefghij1234pqrst"));
848 test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 5, S("abcdefghij12345pqrst"));
849 test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 0, S("abcdefghijpqrst"));
850 test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 1, S("abcdefghij1pqrst"));
851 test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 5, S("abcdefghij12345pqrst"));
852 test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 9, S("abcdefghij123456789pqrst"));
853 test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 10, S("abcdefghij1234567890pqrst"));
854 test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 0, S("abcdefghijpqrst"));
855 test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 1, S("abcdefghij1pqrst"));
856 test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 10, S("abcdefghij1234567890pqrst"));
857 test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 19, S("abcdefghij1234567890123456789pqrst"));
858 test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 20, S("abcdefghij12345678901234567890pqrst"));
859 test(S("abcdefghijklmnopqrst"), 10, 9, "", 0, S("abcdefghijt"));
860 test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 0, S("abcdefghijt"));
861 test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 1, S("abcdefghij1t"));
862 test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 2, S("abcdefghij12t"));
863 test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 4, S("abcdefghij1234t"));
864 test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 5, S("abcdefghij12345t"));
865 test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 0, S("abcdefghijt"));
866 test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 1, S("abcdefghij1t"));
867 test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 5, S("abcdefghij12345t"));
868 test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 9, S("abcdefghij123456789t"));
869 test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 10, S("abcdefghij1234567890t"));
870 test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 0, S("abcdefghijt"));
871 test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 1, S("abcdefghij1t"));
872 test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 10, S("abcdefghij1234567890t"));
873 test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 19, S("abcdefghij1234567890123456789t"));
874 test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 20, S("abcdefghij12345678901234567890t"));
875 }
876
877 template <class S>
test8()878 void test8()
879 {
880 test(S("abcdefghijklmnopqrst"), 10, 10, "", 0, S("abcdefghij"));
881 test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 0, S("abcdefghij"));
882 test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 1, S("abcdefghij1"));
883 test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 2, S("abcdefghij12"));
884 test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 4, S("abcdefghij1234"));
885 test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 5, S("abcdefghij12345"));
886 test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 0, S("abcdefghij"));
887 test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 1, S("abcdefghij1"));
888 test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 5, S("abcdefghij12345"));
889 test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 9, S("abcdefghij123456789"));
890 test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 10, S("abcdefghij1234567890"));
891 test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 0, S("abcdefghij"));
892 test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 1, S("abcdefghij1"));
893 test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 10, S("abcdefghij1234567890"));
894 test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
895 test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
896 test(S("abcdefghijklmnopqrst"), 19, 0, "", 0, S("abcdefghijklmnopqrst"));
897 test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 0, S("abcdefghijklmnopqrst"));
898 test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 1, S("abcdefghijklmnopqrs1t"));
899 test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 2, S("abcdefghijklmnopqrs12t"));
900 test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 4, S("abcdefghijklmnopqrs1234t"));
901 test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 5, S("abcdefghijklmnopqrs12345t"));
902 test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
903 test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 1, S("abcdefghijklmnopqrs1t"));
904 test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 5, S("abcdefghijklmnopqrs12345t"));
905 test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 9, S("abcdefghijklmnopqrs123456789t"));
906 test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
907 test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
908 test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 1, S("abcdefghijklmnopqrs1t"));
909 test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
910 test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789t"));
911 test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890t"));
912 test(S("abcdefghijklmnopqrst"), 19, 1, "", 0, S("abcdefghijklmnopqrs"));
913 test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 0, S("abcdefghijklmnopqrs"));
914 test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 1, S("abcdefghijklmnopqrs1"));
915 test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 2, S("abcdefghijklmnopqrs12"));
916 test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 4, S("abcdefghijklmnopqrs1234"));
917 test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 5, S("abcdefghijklmnopqrs12345"));
918 test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 0, S("abcdefghijklmnopqrs"));
919 test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 1, S("abcdefghijklmnopqrs1"));
920 test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 5, S("abcdefghijklmnopqrs12345"));
921 test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 9, S("abcdefghijklmnopqrs123456789"));
922 test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 10, S("abcdefghijklmnopqrs1234567890"));
923 test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 0, S("abcdefghijklmnopqrs"));
924 test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 1, S("abcdefghijklmnopqrs1"));
925 test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890"));
926 test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789"));
927 test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890"));
928 test(S("abcdefghijklmnopqrst"), 20, 0, "", 0, S("abcdefghijklmnopqrst"));
929 test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 0, S("abcdefghijklmnopqrst"));
930 test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 1, S("abcdefghijklmnopqrst1"));
931 test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 2, S("abcdefghijklmnopqrst12"));
932 test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 4, S("abcdefghijklmnopqrst1234"));
933 test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 5, S("abcdefghijklmnopqrst12345"));
934 test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
935 test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 1, S("abcdefghijklmnopqrst1"));
936 test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 5, S("abcdefghijklmnopqrst12345"));
937 test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 9, S("abcdefghijklmnopqrst123456789"));
938 test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 10, S("abcdefghijklmnopqrst1234567890"));
939 test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
940 test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 1, S("abcdefghijklmnopqrst1"));
941 test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 10, S("abcdefghijklmnopqrst1234567890"));
942 test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 19, S("abcdefghijklmnopqrst1234567890123456789"));
943 test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"));
944 }
945
main(int,char **)946 int main(int, char**)
947 {
948 {
949 typedef std::string S;
950 test0<S>();
951 test1<S>();
952 test2<S>();
953 test3<S>();
954 test4<S>();
955 test5<S>();
956 test6<S>();
957 test7<S>();
958 test8<S>();
959 }
960 #if TEST_STD_VER >= 11
961 {
962 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
963 test0<S>();
964 test1<S>();
965 test2<S>();
966 test3<S>();
967 test4<S>();
968 test5<S>();
969 test6<S>();
970 test7<S>();
971 test8<S>();
972 }
973 #endif
974
975 { // test replacing into self
976 typedef std::string S;
977 S s_short = "123/";
978 S s_long = "Lorem ipsum dolor sit amet, consectetur/";
979
980 s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
981 assert(s_short == "123/123/");
982 s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
983 assert(s_short == "123/123/123/123/");
984 s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
985 assert(s_short == "123/123/123/123/123/123/123/123/");
986
987 s_long.replace(s_long.begin(), s_long.begin(), s_long.data(), s_long.size());
988 assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
989 }
990
991 return 0;
992 }
993