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, const charT* s);
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,const typename S::value_type * str,S expected)24 test(S s, typename S::size_type pos, typename S::size_type n1,
25      const typename S::value_type* str, S expected)
26 {
27     const typename S::size_type old_size = s.size();
28     S s0 = s;
29     if (pos <= old_size)
30     {
31         s.replace(pos, n1, str);
32         LIBCPP_ASSERT(s.__invariants());
33         assert(s == expected);
34         typename S::size_type xlen = std::min(n1, old_size - pos);
35         typename S::size_type rlen = S::traits_type::length(str);
36         assert(s.size() == old_size - xlen + rlen);
37     }
38 #ifndef TEST_HAS_NO_EXCEPTIONS
39     else
40     {
41         try
42         {
43             s.replace(pos, n1, str);
44             assert(false);
45         }
46         catch (std::out_of_range&)
47         {
48             assert(pos > old_size);
49             assert(s == s0);
50         }
51     }
52 #endif
53 }
54 
55 template <class S>
test0()56 void test0()
57 {
58     test(S(""), 0, 0, "", S(""));
59     test(S(""), 0, 0, "12345", S("12345"));
60     test(S(""), 0, 0, "1234567890", S("1234567890"));
61     test(S(""), 0, 0, "12345678901234567890", S("12345678901234567890"));
62     test(S(""), 0, 1, "", S(""));
63     test(S(""), 0, 1, "12345", S("12345"));
64     test(S(""), 0, 1, "1234567890", S("1234567890"));
65     test(S(""), 0, 1, "12345678901234567890", S("12345678901234567890"));
66     test(S(""), 1, 0, "", S("can't happen"));
67     test(S(""), 1, 0, "12345", S("can't happen"));
68     test(S(""), 1, 0, "1234567890", S("can't happen"));
69     test(S(""), 1, 0, "12345678901234567890", S("can't happen"));
70     test(S("abcde"), 0, 0, "", S("abcde"));
71     test(S("abcde"), 0, 0, "12345", S("12345abcde"));
72     test(S("abcde"), 0, 0, "1234567890", S("1234567890abcde"));
73     test(S("abcde"), 0, 0, "12345678901234567890", S("12345678901234567890abcde"));
74     test(S("abcde"), 0, 1, "", S("bcde"));
75     test(S("abcde"), 0, 1, "12345", S("12345bcde"));
76     test(S("abcde"), 0, 1, "1234567890", S("1234567890bcde"));
77     test(S("abcde"), 0, 1, "12345678901234567890", S("12345678901234567890bcde"));
78     test(S("abcde"), 0, 2, "", S("cde"));
79     test(S("abcde"), 0, 2, "12345", S("12345cde"));
80     test(S("abcde"), 0, 2, "1234567890", S("1234567890cde"));
81     test(S("abcde"), 0, 2, "12345678901234567890", S("12345678901234567890cde"));
82     test(S("abcde"), 0, 4, "", S("e"));
83     test(S("abcde"), 0, 4, "12345", S("12345e"));
84     test(S("abcde"), 0, 4, "1234567890", S("1234567890e"));
85     test(S("abcde"), 0, 4, "12345678901234567890", S("12345678901234567890e"));
86     test(S("abcde"), 0, 5, "", S(""));
87     test(S("abcde"), 0, 5, "12345", S("12345"));
88     test(S("abcde"), 0, 5, "1234567890", S("1234567890"));
89     test(S("abcde"), 0, 5, "12345678901234567890", S("12345678901234567890"));
90     test(S("abcde"), 0, 6, "", S(""));
91     test(S("abcde"), 0, 6, "12345", S("12345"));
92     test(S("abcde"), 0, 6, "1234567890", S("1234567890"));
93     test(S("abcde"), 0, 6, "12345678901234567890", S("12345678901234567890"));
94     test(S("abcde"), 1, 0, "", S("abcde"));
95     test(S("abcde"), 1, 0, "12345", S("a12345bcde"));
96     test(S("abcde"), 1, 0, "1234567890", S("a1234567890bcde"));
97     test(S("abcde"), 1, 0, "12345678901234567890", S("a12345678901234567890bcde"));
98     test(S("abcde"), 1, 1, "", S("acde"));
99     test(S("abcde"), 1, 1, "12345", S("a12345cde"));
100     test(S("abcde"), 1, 1, "1234567890", S("a1234567890cde"));
101     test(S("abcde"), 1, 1, "12345678901234567890", S("a12345678901234567890cde"));
102     test(S("abcde"), 1, 2, "", S("ade"));
103     test(S("abcde"), 1, 2, "12345", S("a12345de"));
104     test(S("abcde"), 1, 2, "1234567890", S("a1234567890de"));
105     test(S("abcde"), 1, 2, "12345678901234567890", S("a12345678901234567890de"));
106     test(S("abcde"), 1, 3, "", S("ae"));
107     test(S("abcde"), 1, 3, "12345", S("a12345e"));
108     test(S("abcde"), 1, 3, "1234567890", S("a1234567890e"));
109     test(S("abcde"), 1, 3, "12345678901234567890", S("a12345678901234567890e"));
110     test(S("abcde"), 1, 4, "", S("a"));
111     test(S("abcde"), 1, 4, "12345", S("a12345"));
112     test(S("abcde"), 1, 4, "1234567890", S("a1234567890"));
113     test(S("abcde"), 1, 4, "12345678901234567890", S("a12345678901234567890"));
114     test(S("abcde"), 1, 5, "", S("a"));
115     test(S("abcde"), 1, 5, "12345", S("a12345"));
116     test(S("abcde"), 1, 5, "1234567890", S("a1234567890"));
117     test(S("abcde"), 1, 5, "12345678901234567890", S("a12345678901234567890"));
118     test(S("abcde"), 2, 0, "", S("abcde"));
119     test(S("abcde"), 2, 0, "12345", S("ab12345cde"));
120     test(S("abcde"), 2, 0, "1234567890", S("ab1234567890cde"));
121     test(S("abcde"), 2, 0, "12345678901234567890", S("ab12345678901234567890cde"));
122     test(S("abcde"), 2, 1, "", S("abde"));
123     test(S("abcde"), 2, 1, "12345", S("ab12345de"));
124     test(S("abcde"), 2, 1, "1234567890", S("ab1234567890de"));
125     test(S("abcde"), 2, 1, "12345678901234567890", S("ab12345678901234567890de"));
126     test(S("abcde"), 2, 2, "", S("abe"));
127     test(S("abcde"), 2, 2, "12345", S("ab12345e"));
128     test(S("abcde"), 2, 2, "1234567890", S("ab1234567890e"));
129     test(S("abcde"), 2, 2, "12345678901234567890", S("ab12345678901234567890e"));
130     test(S("abcde"), 2, 3, "", S("ab"));
131     test(S("abcde"), 2, 3, "12345", S("ab12345"));
132     test(S("abcde"), 2, 3, "1234567890", S("ab1234567890"));
133     test(S("abcde"), 2, 3, "12345678901234567890", S("ab12345678901234567890"));
134     test(S("abcde"), 2, 4, "", S("ab"));
135     test(S("abcde"), 2, 4, "12345", S("ab12345"));
136     test(S("abcde"), 2, 4, "1234567890", S("ab1234567890"));
137     test(S("abcde"), 2, 4, "12345678901234567890", S("ab12345678901234567890"));
138     test(S("abcde"), 4, 0, "", S("abcde"));
139     test(S("abcde"), 4, 0, "12345", S("abcd12345e"));
140     test(S("abcde"), 4, 0, "1234567890", S("abcd1234567890e"));
141     test(S("abcde"), 4, 0, "12345678901234567890", S("abcd12345678901234567890e"));
142     test(S("abcde"), 4, 1, "", S("abcd"));
143     test(S("abcde"), 4, 1, "12345", S("abcd12345"));
144     test(S("abcde"), 4, 1, "1234567890", S("abcd1234567890"));
145     test(S("abcde"), 4, 1, "12345678901234567890", S("abcd12345678901234567890"));
146     test(S("abcde"), 4, 2, "", S("abcd"));
147     test(S("abcde"), 4, 2, "12345", S("abcd12345"));
148     test(S("abcde"), 4, 2, "1234567890", S("abcd1234567890"));
149     test(S("abcde"), 4, 2, "12345678901234567890", S("abcd12345678901234567890"));
150     test(S("abcde"), 5, 0, "", S("abcde"));
151     test(S("abcde"), 5, 0, "12345", S("abcde12345"));
152     test(S("abcde"), 5, 0, "1234567890", S("abcde1234567890"));
153     test(S("abcde"), 5, 0, "12345678901234567890", S("abcde12345678901234567890"));
154     test(S("abcde"), 5, 1, "", S("abcde"));
155     test(S("abcde"), 5, 1, "12345", S("abcde12345"));
156     test(S("abcde"), 5, 1, "1234567890", S("abcde1234567890"));
157     test(S("abcde"), 5, 1, "12345678901234567890", S("abcde12345678901234567890"));
158 }
159 
160 template <class S>
test1()161 void test1()
162 {
163     test(S("abcde"), 6, 0, "", S("can't happen"));
164     test(S("abcde"), 6, 0, "12345", S("can't happen"));
165     test(S("abcde"), 6, 0, "1234567890", S("can't happen"));
166     test(S("abcde"), 6, 0, "12345678901234567890", S("can't happen"));
167     test(S("abcdefghij"), 0, 0, "", S("abcdefghij"));
168     test(S("abcdefghij"), 0, 0, "12345", S("12345abcdefghij"));
169     test(S("abcdefghij"), 0, 0, "1234567890", S("1234567890abcdefghij"));
170     test(S("abcdefghij"), 0, 0, "12345678901234567890", S("12345678901234567890abcdefghij"));
171     test(S("abcdefghij"), 0, 1, "", S("bcdefghij"));
172     test(S("abcdefghij"), 0, 1, "12345", S("12345bcdefghij"));
173     test(S("abcdefghij"), 0, 1, "1234567890", S("1234567890bcdefghij"));
174     test(S("abcdefghij"), 0, 1, "12345678901234567890", S("12345678901234567890bcdefghij"));
175     test(S("abcdefghij"), 0, 5, "", S("fghij"));
176     test(S("abcdefghij"), 0, 5, "12345", S("12345fghij"));
177     test(S("abcdefghij"), 0, 5, "1234567890", S("1234567890fghij"));
178     test(S("abcdefghij"), 0, 5, "12345678901234567890", S("12345678901234567890fghij"));
179     test(S("abcdefghij"), 0, 9, "", S("j"));
180     test(S("abcdefghij"), 0, 9, "12345", S("12345j"));
181     test(S("abcdefghij"), 0, 9, "1234567890", S("1234567890j"));
182     test(S("abcdefghij"), 0, 9, "12345678901234567890", S("12345678901234567890j"));
183     test(S("abcdefghij"), 0, 10, "", S(""));
184     test(S("abcdefghij"), 0, 10, "12345", S("12345"));
185     test(S("abcdefghij"), 0, 10, "1234567890", S("1234567890"));
186     test(S("abcdefghij"), 0, 10, "12345678901234567890", S("12345678901234567890"));
187     test(S("abcdefghij"), 0, 11, "", S(""));
188     test(S("abcdefghij"), 0, 11, "12345", S("12345"));
189     test(S("abcdefghij"), 0, 11, "1234567890", S("1234567890"));
190     test(S("abcdefghij"), 0, 11, "12345678901234567890", S("12345678901234567890"));
191     test(S("abcdefghij"), 1, 0, "", S("abcdefghij"));
192     test(S("abcdefghij"), 1, 0, "12345", S("a12345bcdefghij"));
193     test(S("abcdefghij"), 1, 0, "1234567890", S("a1234567890bcdefghij"));
194     test(S("abcdefghij"), 1, 0, "12345678901234567890", S("a12345678901234567890bcdefghij"));
195     test(S("abcdefghij"), 1, 1, "", S("acdefghij"));
196     test(S("abcdefghij"), 1, 1, "12345", S("a12345cdefghij"));
197     test(S("abcdefghij"), 1, 1, "1234567890", S("a1234567890cdefghij"));
198     test(S("abcdefghij"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghij"));
199     test(S("abcdefghij"), 1, 4, "", S("afghij"));
200     test(S("abcdefghij"), 1, 4, "12345", S("a12345fghij"));
201     test(S("abcdefghij"), 1, 4, "1234567890", S("a1234567890fghij"));
202     test(S("abcdefghij"), 1, 4, "12345678901234567890", S("a12345678901234567890fghij"));
203     test(S("abcdefghij"), 1, 8, "", S("aj"));
204     test(S("abcdefghij"), 1, 8, "12345", S("a12345j"));
205     test(S("abcdefghij"), 1, 8, "1234567890", S("a1234567890j"));
206     test(S("abcdefghij"), 1, 8, "12345678901234567890", S("a12345678901234567890j"));
207     test(S("abcdefghij"), 1, 9, "", S("a"));
208     test(S("abcdefghij"), 1, 9, "12345", S("a12345"));
209     test(S("abcdefghij"), 1, 9, "1234567890", S("a1234567890"));
210     test(S("abcdefghij"), 1, 9, "12345678901234567890", S("a12345678901234567890"));
211     test(S("abcdefghij"), 1, 10, "", S("a"));
212     test(S("abcdefghij"), 1, 10, "12345", S("a12345"));
213     test(S("abcdefghij"), 1, 10, "1234567890", S("a1234567890"));
214     test(S("abcdefghij"), 1, 10, "12345678901234567890", S("a12345678901234567890"));
215     test(S("abcdefghij"), 5, 0, "", S("abcdefghij"));
216     test(S("abcdefghij"), 5, 0, "12345", S("abcde12345fghij"));
217     test(S("abcdefghij"), 5, 0, "1234567890", S("abcde1234567890fghij"));
218     test(S("abcdefghij"), 5, 0, "12345678901234567890", S("abcde12345678901234567890fghij"));
219     test(S("abcdefghij"), 5, 1, "", S("abcdeghij"));
220     test(S("abcdefghij"), 5, 1, "12345", S("abcde12345ghij"));
221     test(S("abcdefghij"), 5, 1, "1234567890", S("abcde1234567890ghij"));
222     test(S("abcdefghij"), 5, 1, "12345678901234567890", S("abcde12345678901234567890ghij"));
223     test(S("abcdefghij"), 5, 2, "", S("abcdehij"));
224     test(S("abcdefghij"), 5, 2, "12345", S("abcde12345hij"));
225     test(S("abcdefghij"), 5, 2, "1234567890", S("abcde1234567890hij"));
226     test(S("abcdefghij"), 5, 2, "12345678901234567890", S("abcde12345678901234567890hij"));
227     test(S("abcdefghij"), 5, 4, "", S("abcdej"));
228     test(S("abcdefghij"), 5, 4, "12345", S("abcde12345j"));
229     test(S("abcdefghij"), 5, 4, "1234567890", S("abcde1234567890j"));
230     test(S("abcdefghij"), 5, 4, "12345678901234567890", S("abcde12345678901234567890j"));
231     test(S("abcdefghij"), 5, 5, "", S("abcde"));
232     test(S("abcdefghij"), 5, 5, "12345", S("abcde12345"));
233     test(S("abcdefghij"), 5, 5, "1234567890", S("abcde1234567890"));
234     test(S("abcdefghij"), 5, 5, "12345678901234567890", S("abcde12345678901234567890"));
235     test(S("abcdefghij"), 5, 6, "", S("abcde"));
236     test(S("abcdefghij"), 5, 6, "12345", S("abcde12345"));
237     test(S("abcdefghij"), 5, 6, "1234567890", S("abcde1234567890"));
238     test(S("abcdefghij"), 5, 6, "12345678901234567890", S("abcde12345678901234567890"));
239     test(S("abcdefghij"), 9, 0, "", S("abcdefghij"));
240     test(S("abcdefghij"), 9, 0, "12345", S("abcdefghi12345j"));
241     test(S("abcdefghij"), 9, 0, "1234567890", S("abcdefghi1234567890j"));
242     test(S("abcdefghij"), 9, 0, "12345678901234567890", S("abcdefghi12345678901234567890j"));
243     test(S("abcdefghij"), 9, 1, "", S("abcdefghi"));
244     test(S("abcdefghij"), 9, 1, "12345", S("abcdefghi12345"));
245     test(S("abcdefghij"), 9, 1, "1234567890", S("abcdefghi1234567890"));
246     test(S("abcdefghij"), 9, 1, "12345678901234567890", S("abcdefghi12345678901234567890"));
247     test(S("abcdefghij"), 9, 2, "", S("abcdefghi"));
248     test(S("abcdefghij"), 9, 2, "12345", S("abcdefghi12345"));
249     test(S("abcdefghij"), 9, 2, "1234567890", S("abcdefghi1234567890"));
250     test(S("abcdefghij"), 9, 2, "12345678901234567890", S("abcdefghi12345678901234567890"));
251     test(S("abcdefghij"), 10, 0, "", S("abcdefghij"));
252     test(S("abcdefghij"), 10, 0, "12345", S("abcdefghij12345"));
253     test(S("abcdefghij"), 10, 0, "1234567890", S("abcdefghij1234567890"));
254     test(S("abcdefghij"), 10, 0, "12345678901234567890", S("abcdefghij12345678901234567890"));
255     test(S("abcdefghij"), 10, 1, "", S("abcdefghij"));
256     test(S("abcdefghij"), 10, 1, "12345", S("abcdefghij12345"));
257     test(S("abcdefghij"), 10, 1, "1234567890", S("abcdefghij1234567890"));
258     test(S("abcdefghij"), 10, 1, "12345678901234567890", S("abcdefghij12345678901234567890"));
259     test(S("abcdefghij"), 11, 0, "", S("can't happen"));
260     test(S("abcdefghij"), 11, 0, "12345", S("can't happen"));
261     test(S("abcdefghij"), 11, 0, "1234567890", S("can't happen"));
262     test(S("abcdefghij"), 11, 0, "12345678901234567890", S("can't happen"));
263 }
264 
265 template <class S>
test2()266 void test2()
267 {
268     test(S("abcdefghijklmnopqrst"), 0, 0, "", S("abcdefghijklmnopqrst"));
269     test(S("abcdefghijklmnopqrst"), 0, 0, "12345", S("12345abcdefghijklmnopqrst"));
270     test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", S("1234567890abcdefghijklmnopqrst"));
271     test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst"));
272     test(S("abcdefghijklmnopqrst"), 0, 1, "", S("bcdefghijklmnopqrst"));
273     test(S("abcdefghijklmnopqrst"), 0, 1, "12345", S("12345bcdefghijklmnopqrst"));
274     test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", S("1234567890bcdefghijklmnopqrst"));
275     test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", S("12345678901234567890bcdefghijklmnopqrst"));
276     test(S("abcdefghijklmnopqrst"), 0, 10, "", S("klmnopqrst"));
277     test(S("abcdefghijklmnopqrst"), 0, 10, "12345", S("12345klmnopqrst"));
278     test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", S("1234567890klmnopqrst"));
279     test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", S("12345678901234567890klmnopqrst"));
280     test(S("abcdefghijklmnopqrst"), 0, 19, "", S("t"));
281     test(S("abcdefghijklmnopqrst"), 0, 19, "12345", S("12345t"));
282     test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", S("1234567890t"));
283     test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", S("12345678901234567890t"));
284     test(S("abcdefghijklmnopqrst"), 0, 20, "", S(""));
285     test(S("abcdefghijklmnopqrst"), 0, 20, "12345", S("12345"));
286     test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", S("1234567890"));
287     test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", S("12345678901234567890"));
288     test(S("abcdefghijklmnopqrst"), 0, 21, "", S(""));
289     test(S("abcdefghijklmnopqrst"), 0, 21, "12345", S("12345"));
290     test(S("abcdefghijklmnopqrst"), 0, 21, "1234567890", S("1234567890"));
291     test(S("abcdefghijklmnopqrst"), 0, 21, "12345678901234567890", S("12345678901234567890"));
292     test(S("abcdefghijklmnopqrst"), 1, 0, "", S("abcdefghijklmnopqrst"));
293     test(S("abcdefghijklmnopqrst"), 1, 0, "12345", S("a12345bcdefghijklmnopqrst"));
294     test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", S("a1234567890bcdefghijklmnopqrst"));
295     test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst"));
296     test(S("abcdefghijklmnopqrst"), 1, 1, "", S("acdefghijklmnopqrst"));
297     test(S("abcdefghijklmnopqrst"), 1, 1, "12345", S("a12345cdefghijklmnopqrst"));
298     test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", S("a1234567890cdefghijklmnopqrst"));
299     test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghijklmnopqrst"));
300     test(S("abcdefghijklmnopqrst"), 1, 9, "", S("aklmnopqrst"));
301     test(S("abcdefghijklmnopqrst"), 1, 9, "12345", S("a12345klmnopqrst"));
302     test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", S("a1234567890klmnopqrst"));
303     test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", S("a12345678901234567890klmnopqrst"));
304     test(S("abcdefghijklmnopqrst"), 1, 18, "", S("at"));
305     test(S("abcdefghijklmnopqrst"), 1, 18, "12345", S("a12345t"));
306     test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", S("a1234567890t"));
307     test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", S("a12345678901234567890t"));
308     test(S("abcdefghijklmnopqrst"), 1, 19, "", S("a"));
309     test(S("abcdefghijklmnopqrst"), 1, 19, "12345", S("a12345"));
310     test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", S("a1234567890"));
311     test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", S("a12345678901234567890"));
312     test(S("abcdefghijklmnopqrst"), 1, 20, "", S("a"));
313     test(S("abcdefghijklmnopqrst"), 1, 20, "12345", S("a12345"));
314     test(S("abcdefghijklmnopqrst"), 1, 20, "1234567890", S("a1234567890"));
315     test(S("abcdefghijklmnopqrst"), 1, 20, "12345678901234567890", S("a12345678901234567890"));
316     test(S("abcdefghijklmnopqrst"), 10, 0, "", S("abcdefghijklmnopqrst"));
317     test(S("abcdefghijklmnopqrst"), 10, 0, "12345", S("abcdefghij12345klmnopqrst"));
318     test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", S("abcdefghij1234567890klmnopqrst"));
319     test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst"));
320     test(S("abcdefghijklmnopqrst"), 10, 1, "", S("abcdefghijlmnopqrst"));
321     test(S("abcdefghijklmnopqrst"), 10, 1, "12345", S("abcdefghij12345lmnopqrst"));
322     test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", S("abcdefghij1234567890lmnopqrst"));
323     test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", S("abcdefghij12345678901234567890lmnopqrst"));
324     test(S("abcdefghijklmnopqrst"), 10, 5, "", S("abcdefghijpqrst"));
325     test(S("abcdefghijklmnopqrst"), 10, 5, "12345", S("abcdefghij12345pqrst"));
326     test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", S("abcdefghij1234567890pqrst"));
327     test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", S("abcdefghij12345678901234567890pqrst"));
328     test(S("abcdefghijklmnopqrst"), 10, 9, "", S("abcdefghijt"));
329     test(S("abcdefghijklmnopqrst"), 10, 9, "12345", S("abcdefghij12345t"));
330     test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", S("abcdefghij1234567890t"));
331     test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", S("abcdefghij12345678901234567890t"));
332     test(S("abcdefghijklmnopqrst"), 10, 10, "", S("abcdefghij"));
333     test(S("abcdefghijklmnopqrst"), 10, 10, "12345", S("abcdefghij12345"));
334     test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", S("abcdefghij1234567890"));
335     test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", S("abcdefghij12345678901234567890"));
336     test(S("abcdefghijklmnopqrst"), 10, 11, "", S("abcdefghij"));
337     test(S("abcdefghijklmnopqrst"), 10, 11, "12345", S("abcdefghij12345"));
338     test(S("abcdefghijklmnopqrst"), 10, 11, "1234567890", S("abcdefghij1234567890"));
339     test(S("abcdefghijklmnopqrst"), 10, 11, "12345678901234567890", S("abcdefghij12345678901234567890"));
340     test(S("abcdefghijklmnopqrst"), 19, 0, "", S("abcdefghijklmnopqrst"));
341     test(S("abcdefghijklmnopqrst"), 19, 0, "12345", S("abcdefghijklmnopqrs12345t"));
342     test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", S("abcdefghijklmnopqrs1234567890t"));
343     test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t"));
344     test(S("abcdefghijklmnopqrst"), 19, 1, "", S("abcdefghijklmnopqrs"));
345     test(S("abcdefghijklmnopqrst"), 19, 1, "12345", S("abcdefghijklmnopqrs12345"));
346     test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", S("abcdefghijklmnopqrs1234567890"));
347     test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890"));
348     test(S("abcdefghijklmnopqrst"), 19, 2, "", S("abcdefghijklmnopqrs"));
349     test(S("abcdefghijklmnopqrst"), 19, 2, "12345", S("abcdefghijklmnopqrs12345"));
350     test(S("abcdefghijklmnopqrst"), 19, 2, "1234567890", S("abcdefghijklmnopqrs1234567890"));
351     test(S("abcdefghijklmnopqrst"), 19, 2, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890"));
352     test(S("abcdefghijklmnopqrst"), 20, 0, "", S("abcdefghijklmnopqrst"));
353     test(S("abcdefghijklmnopqrst"), 20, 0, "12345", S("abcdefghijklmnopqrst12345"));
354     test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", S("abcdefghijklmnopqrst1234567890"));
355     test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
356     test(S("abcdefghijklmnopqrst"), 20, 1, "", S("abcdefghijklmnopqrst"));
357     test(S("abcdefghijklmnopqrst"), 20, 1, "12345", S("abcdefghijklmnopqrst12345"));
358     test(S("abcdefghijklmnopqrst"), 20, 1, "1234567890", S("abcdefghijklmnopqrst1234567890"));
359     test(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
360     test(S("abcdefghijklmnopqrst"), 21, 0, "", S("can't happen"));
361     test(S("abcdefghijklmnopqrst"), 21, 0, "12345", S("can't happen"));
362     test(S("abcdefghijklmnopqrst"), 21, 0, "1234567890", S("can't happen"));
363     test(S("abcdefghijklmnopqrst"), 21, 0, "12345678901234567890", S("can't happen"));
364 }
365 
main(int,char **)366 int main(int, char**)
367 {
368     {
369     typedef std::string S;
370     test0<S>();
371     test1<S>();
372     test2<S>();
373     }
374 #if TEST_STD_VER >= 11
375     {
376     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
377     test0<S>();
378     test1<S>();
379     test2<S>();
380     }
381 #endif
382 
383   return 0;
384 }
385