[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / string.view / string.view.ops / compare.pointer_size.pass.cpp
bloba3b7b6cc0b09afdb914e642536bce39a01b853fa
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 //===----------------------------------------------------------------------===//
9 // <string_view>
11 // constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
13 #include <string_view>
14 #include <cassert>
15 #include <stdexcept>
17 #include "test_macros.h"
18 #include "constexpr_char_traits.h"
20 int sign ( int x ) { return x > 0 ? 1 : ( x < 0 ? -1 : 0 ); }
22 template<typename CharT>
23 void test1 ( std::basic_string_view<CharT> sv1,
24 size_t pos1, size_t n1, const CharT *s, int expected ) {
25 #ifdef TEST_HAS_NO_EXCEPTIONS
26 if (pos1 <= sv1.size())
27 assert(sign(sv1.compare(pos1, n1, s)) == sign(expected));
28 #else
29 try {
30 assert(sign(sv1.compare(pos1, n1, s)) == sign(expected));
31 assert(pos1 <= sv1.size());
33 catch (const std::out_of_range&) {
34 assert(pos1 > sv1.size());
36 #endif
39 template<typename CharT>
40 void
41 test( const CharT *s1, size_t pos1, size_t n1, const CharT *s2, int expected)
43 typedef std::basic_string_view<CharT> string_view_t;
44 string_view_t sv1 ( s1 );
45 test1 ( sv1, pos1, n1, s2, expected );
48 void test0()
50 test("", 0, 0, "", 0);
51 test("", 0, 0, "abcde", -5);
52 test("", 0, 0, "abcdefghij", -10);
53 test("", 0, 0, "abcdefghijklmnopqrst", -20);
54 test("", 0, 1, "", 0);
55 test("", 0, 1, "abcde", -5);
56 test("", 0, 1, "abcdefghij", -10);
57 test("", 0, 1, "abcdefghijklmnopqrst", -20);
58 test("", 1, 0, "", 0);
59 test("", 1, 0, "abcde", 0);
60 test("", 1, 0, "abcdefghij", 0);
61 test("", 1, 0, "abcdefghijklmnopqrst", 0);
62 test("abcde", 0, 0, "", 0);
63 test("abcde", 0, 0, "abcde", -5);
64 test("abcde", 0, 0, "abcdefghij", -10);
65 test("abcde", 0, 0, "abcdefghijklmnopqrst", -20);
66 test("abcde", 0, 1, "", 1);
67 test("abcde", 0, 1, "abcde", -4);
68 test("abcde", 0, 1, "abcdefghij", -9);
69 test("abcde", 0, 1, "abcdefghijklmnopqrst", -19);
70 test("abcde", 0, 2, "", 2);
71 test("abcde", 0, 2, "abcde", -3);
72 test("abcde", 0, 2, "abcdefghij", -8);
73 test("abcde", 0, 2, "abcdefghijklmnopqrst", -18);
74 test("abcde", 0, 4, "", 4);
75 test("abcde", 0, 4, "abcde", -1);
76 test("abcde", 0, 4, "abcdefghij", -6);
77 test("abcde", 0, 4, "abcdefghijklmnopqrst", -16);
78 test("abcde", 0, 5, "", 5);
79 test("abcde", 0, 5, "abcde", 0);
80 test("abcde", 0, 5, "abcdefghij", -5);
81 test("abcde", 0, 5, "abcdefghijklmnopqrst", -15);
82 test("abcde", 0, 6, "", 5);
83 test("abcde", 0, 6, "abcde", 0);
84 test("abcde", 0, 6, "abcdefghij", -5);
85 test("abcde", 0, 6, "abcdefghijklmnopqrst", -15);
86 test("abcde", 1, 0, "", 0);
87 test("abcde", 1, 0, "abcde", -5);
88 test("abcde", 1, 0, "abcdefghij", -10);
89 test("abcde", 1, 0, "abcdefghijklmnopqrst", -20);
90 test("abcde", 1, 1, "", 1);
91 test("abcde", 1, 1, "abcde", 1);
92 test("abcde", 1, 1, "abcdefghij", 1);
93 test("abcde", 1, 1, "abcdefghijklmnopqrst", 1);
94 test("abcde", 1, 2, "", 2);
95 test("abcde", 1, 2, "abcde", 1);
96 test("abcde", 1, 2, "abcdefghij", 1);
97 test("abcde", 1, 2, "abcdefghijklmnopqrst", 1);
98 test("abcde", 1, 3, "", 3);
99 test("abcde", 1, 3, "abcde", 1);
100 test("abcde", 1, 3, "abcdefghij", 1);
101 test("abcde", 1, 3, "abcdefghijklmnopqrst", 1);
102 test("abcde", 1, 4, "", 4);
103 test("abcde", 1, 4, "abcde", 1);
104 test("abcde", 1, 4, "abcdefghij", 1);
105 test("abcde", 1, 4, "abcdefghijklmnopqrst", 1);
106 test("abcde", 1, 5, "", 4);
107 test("abcde", 1, 5, "abcde", 1);
108 test("abcde", 1, 5, "abcdefghij", 1);
109 test("abcde", 1, 5, "abcdefghijklmnopqrst", 1);
110 test("abcde", 2, 0, "", 0);
111 test("abcde", 2, 0, "abcde", -5);
112 test("abcde", 2, 0, "abcdefghij", -10);
113 test("abcde", 2, 0, "abcdefghijklmnopqrst", -20);
114 test("abcde", 2, 1, "", 1);
115 test("abcde", 2, 1, "abcde", 2);
116 test("abcde", 2, 1, "abcdefghij", 2);
117 test("abcde", 2, 1, "abcdefghijklmnopqrst", 2);
118 test("abcde", 2, 2, "", 2);
119 test("abcde", 2, 2, "abcde", 2);
120 test("abcde", 2, 2, "abcdefghij", 2);
121 test("abcde", 2, 2, "abcdefghijklmnopqrst", 2);
122 test("abcde", 2, 3, "", 3);
123 test("abcde", 2, 3, "abcde", 2);
124 test("abcde", 2, 3, "abcdefghij", 2);
125 test("abcde", 2, 3, "abcdefghijklmnopqrst", 2);
126 test("abcde", 2, 4, "", 3);
127 test("abcde", 2, 4, "abcde", 2);
128 test("abcde", 2, 4, "abcdefghij", 2);
129 test("abcde", 2, 4, "abcdefghijklmnopqrst", 2);
130 test("abcde", 4, 0, "", 0);
131 test("abcde", 4, 0, "abcde", -5);
132 test("abcde", 4, 0, "abcdefghij", -10);
133 test("abcde", 4, 0, "abcdefghijklmnopqrst", -20);
134 test("abcde", 4, 1, "", 1);
135 test("abcde", 4, 1, "abcde", 4);
136 test("abcde", 4, 1, "abcdefghij", 4);
137 test("abcde", 4, 1, "abcdefghijklmnopqrst", 4);
138 test("abcde", 4, 2, "", 1);
139 test("abcde", 4, 2, "abcde", 4);
140 test("abcde", 4, 2, "abcdefghij", 4);
141 test("abcde", 4, 2, "abcdefghijklmnopqrst", 4);
142 test("abcde", 5, 0, "", 0);
143 test("abcde", 5, 0, "abcde", -5);
144 test("abcde", 5, 0, "abcdefghij", -10);
145 test("abcde", 5, 0, "abcdefghijklmnopqrst", -20);
146 test("abcde", 5, 1, "", 0);
147 test("abcde", 5, 1, "abcde", -5);
148 test("abcde", 5, 1, "abcdefghij", -10);
149 test("abcde", 5, 1, "abcdefghijklmnopqrst", -20);
152 void test1()
154 test("abcde", 6, 0, "", 0);
155 test("abcde", 6, 0, "abcde", 0);
156 test("abcde", 6, 0, "abcdefghij", 0);
157 test("abcde", 6, 0, "abcdefghijklmnopqrst", 0);
158 test("abcdefghij", 0, 0, "", 0);
159 test("abcdefghij", 0, 0, "abcde", -5);
160 test("abcdefghij", 0, 0, "abcdefghij", -10);
161 test("abcdefghij", 0, 0, "abcdefghijklmnopqrst", -20);
162 test("abcdefghij", 0, 1, "", 1);
163 test("abcdefghij", 0, 1, "abcde", -4);
164 test("abcdefghij", 0, 1, "abcdefghij", -9);
165 test("abcdefghij", 0, 1, "abcdefghijklmnopqrst", -19);
166 test("abcdefghij", 0, 5, "", 5);
167 test("abcdefghij", 0, 5, "abcde", 0);
168 test("abcdefghij", 0, 5, "abcdefghij", -5);
169 test("abcdefghij", 0, 5, "abcdefghijklmnopqrst", -15);
170 test("abcdefghij", 0, 9, "", 9);
171 test("abcdefghij", 0, 9, "abcde", 4);
172 test("abcdefghij", 0, 9, "abcdefghij", -1);
173 test("abcdefghij", 0, 9, "abcdefghijklmnopqrst", -11);
174 test("abcdefghij", 0, 10, "", 10);
175 test("abcdefghij", 0, 10, "abcde", 5);
176 test("abcdefghij", 0, 10, "abcdefghij", 0);
177 test("abcdefghij", 0, 10, "abcdefghijklmnopqrst", -10);
178 test("abcdefghij", 0, 11, "", 10);
179 test("abcdefghij", 0, 11, "abcde", 5);
180 test("abcdefghij", 0, 11, "abcdefghij", 0);
181 test("abcdefghij", 0, 11, "abcdefghijklmnopqrst", -10);
182 test("abcdefghij", 1, 0, "", 0);
183 test("abcdefghij", 1, 0, "abcde", -5);
184 test("abcdefghij", 1, 0, "abcdefghij", -10);
185 test("abcdefghij", 1, 0, "abcdefghijklmnopqrst", -20);
186 test("abcdefghij", 1, 1, "", 1);
187 test("abcdefghij", 1, 1, "abcde", 1);
188 test("abcdefghij", 1, 1, "abcdefghij", 1);
189 test("abcdefghij", 1, 1, "abcdefghijklmnopqrst", 1);
190 test("abcdefghij", 1, 4, "", 4);
191 test("abcdefghij", 1, 4, "abcde", 1);
192 test("abcdefghij", 1, 4, "abcdefghij", 1);
193 test("abcdefghij", 1, 4, "abcdefghijklmnopqrst", 1);
194 test("abcdefghij", 1, 8, "", 8);
195 test("abcdefghij", 1, 8, "abcde", 1);
196 test("abcdefghij", 1, 8, "abcdefghij", 1);
197 test("abcdefghij", 1, 8, "abcdefghijklmnopqrst", 1);
198 test("abcdefghij", 1, 9, "", 9);
199 test("abcdefghij", 1, 9, "abcde", 1);
200 test("abcdefghij", 1, 9, "abcdefghij", 1);
201 test("abcdefghij", 1, 9, "abcdefghijklmnopqrst", 1);
202 test("abcdefghij", 1, 10, "", 9);
203 test("abcdefghij", 1, 10, "abcde", 1);
204 test("abcdefghij", 1, 10, "abcdefghij", 1);
205 test("abcdefghij", 1, 10, "abcdefghijklmnopqrst", 1);
206 test("abcdefghij", 5, 0, "", 0);
207 test("abcdefghij", 5, 0, "abcde", -5);
208 test("abcdefghij", 5, 0, "abcdefghij", -10);
209 test("abcdefghij", 5, 0, "abcdefghijklmnopqrst", -20);
210 test("abcdefghij", 5, 1, "", 1);
211 test("abcdefghij", 5, 1, "abcde", 5);
212 test("abcdefghij", 5, 1, "abcdefghij", 5);
213 test("abcdefghij", 5, 1, "abcdefghijklmnopqrst", 5);
214 test("abcdefghij", 5, 2, "", 2);
215 test("abcdefghij", 5, 2, "abcde", 5);
216 test("abcdefghij", 5, 2, "abcdefghij", 5);
217 test("abcdefghij", 5, 2, "abcdefghijklmnopqrst", 5);
218 test("abcdefghij", 5, 4, "", 4);
219 test("abcdefghij", 5, 4, "abcde", 5);
220 test("abcdefghij", 5, 4, "abcdefghij", 5);
221 test("abcdefghij", 5, 4, "abcdefghijklmnopqrst", 5);
222 test("abcdefghij", 5, 5, "", 5);
223 test("abcdefghij", 5, 5, "abcde", 5);
224 test("abcdefghij", 5, 5, "abcdefghij", 5);
225 test("abcdefghij", 5, 5, "abcdefghijklmnopqrst", 5);
226 test("abcdefghij", 5, 6, "", 5);
227 test("abcdefghij", 5, 6, "abcde", 5);
228 test("abcdefghij", 5, 6, "abcdefghij", 5);
229 test("abcdefghij", 5, 6, "abcdefghijklmnopqrst", 5);
230 test("abcdefghij", 9, 0, "", 0);
231 test("abcdefghij", 9, 0, "abcde", -5);
232 test("abcdefghij", 9, 0, "abcdefghij", -10);
233 test("abcdefghij", 9, 0, "abcdefghijklmnopqrst", -20);
234 test("abcdefghij", 9, 1, "", 1);
235 test("abcdefghij", 9, 1, "abcde", 9);
236 test("abcdefghij", 9, 1, "abcdefghij", 9);
237 test("abcdefghij", 9, 1, "abcdefghijklmnopqrst", 9);
238 test("abcdefghij", 9, 2, "", 1);
239 test("abcdefghij", 9, 2, "abcde", 9);
240 test("abcdefghij", 9, 2, "abcdefghij", 9);
241 test("abcdefghij", 9, 2, "abcdefghijklmnopqrst", 9);
242 test("abcdefghij", 10, 0, "", 0);
243 test("abcdefghij", 10, 0, "abcde", -5);
244 test("abcdefghij", 10, 0, "abcdefghij", -10);
245 test("abcdefghij", 10, 0, "abcdefghijklmnopqrst", -20);
246 test("abcdefghij", 10, 1, "", 0);
247 test("abcdefghij", 10, 1, "abcde", -5);
248 test("abcdefghij", 10, 1, "abcdefghij", -10);
249 test("abcdefghij", 10, 1, "abcdefghijklmnopqrst", -20);
250 test("abcdefghij", 11, 0, "", 0);
251 test("abcdefghij", 11, 0, "abcde", 0);
252 test("abcdefghij", 11, 0, "abcdefghij", 0);
253 test("abcdefghij", 11, 0, "abcdefghijklmnopqrst", 0);
256 void test2()
258 test("abcdefghijklmnopqrst", 0, 0, "", 0);
259 test("abcdefghijklmnopqrst", 0, 0, "abcde", -5);
260 test("abcdefghijklmnopqrst", 0, 0, "abcdefghij", -10);
261 test("abcdefghijklmnopqrst", 0, 0, "abcdefghijklmnopqrst", -20);
262 test("abcdefghijklmnopqrst", 0, 1, "", 1);
263 test("abcdefghijklmnopqrst", 0, 1, "abcde", -4);
264 test("abcdefghijklmnopqrst", 0, 1, "abcdefghij", -9);
265 test("abcdefghijklmnopqrst", 0, 1, "abcdefghijklmnopqrst", -19);
266 test("abcdefghijklmnopqrst", 0, 10, "", 10);
267 test("abcdefghijklmnopqrst", 0, 10, "abcde", 5);
268 test("abcdefghijklmnopqrst", 0, 10, "abcdefghij", 0);
269 test("abcdefghijklmnopqrst", 0, 10, "abcdefghijklmnopqrst", -10);
270 test("abcdefghijklmnopqrst", 0, 19, "", 19);
271 test("abcdefghijklmnopqrst", 0, 19, "abcde", 14);
272 test("abcdefghijklmnopqrst", 0, 19, "abcdefghij", 9);
273 test("abcdefghijklmnopqrst", 0, 19, "abcdefghijklmnopqrst", -1);
274 test("abcdefghijklmnopqrst", 0, 20, "", 20);
275 test("abcdefghijklmnopqrst", 0, 20, "abcde", 15);
276 test("abcdefghijklmnopqrst", 0, 20, "abcdefghij", 10);
277 test("abcdefghijklmnopqrst", 0, 20, "abcdefghijklmnopqrst", 0);
278 test("abcdefghijklmnopqrst", 0, 21, "", 20);
279 test("abcdefghijklmnopqrst", 0, 21, "abcde", 15);
280 test("abcdefghijklmnopqrst", 0, 21, "abcdefghij", 10);
281 test("abcdefghijklmnopqrst", 0, 21, "abcdefghijklmnopqrst", 0);
282 test("abcdefghijklmnopqrst", 1, 0, "", 0);
283 test("abcdefghijklmnopqrst", 1, 0, "abcde", -5);
284 test("abcdefghijklmnopqrst", 1, 0, "abcdefghij", -10);
285 test("abcdefghijklmnopqrst", 1, 0, "abcdefghijklmnopqrst", -20);
286 test("abcdefghijklmnopqrst", 1, 1, "", 1);
287 test("abcdefghijklmnopqrst", 1, 1, "abcde", 1);
288 test("abcdefghijklmnopqrst", 1, 1, "abcdefghij", 1);
289 test("abcdefghijklmnopqrst", 1, 1, "abcdefghijklmnopqrst", 1);
290 test("abcdefghijklmnopqrst", 1, 9, "", 9);
291 test("abcdefghijklmnopqrst", 1, 9, "abcde", 1);
292 test("abcdefghijklmnopqrst", 1, 9, "abcdefghij", 1);
293 test("abcdefghijklmnopqrst", 1, 9, "abcdefghijklmnopqrst", 1);
294 test("abcdefghijklmnopqrst", 1, 18, "", 18);
295 test("abcdefghijklmnopqrst", 1, 18, "abcde", 1);
296 test("abcdefghijklmnopqrst", 1, 18, "abcdefghij", 1);
297 test("abcdefghijklmnopqrst", 1, 18, "abcdefghijklmnopqrst", 1);
298 test("abcdefghijklmnopqrst", 1, 19, "", 19);
299 test("abcdefghijklmnopqrst", 1, 19, "abcde", 1);
300 test("abcdefghijklmnopqrst", 1, 19, "abcdefghij", 1);
301 test("abcdefghijklmnopqrst", 1, 19, "abcdefghijklmnopqrst", 1);
302 test("abcdefghijklmnopqrst", 1, 20, "", 19);
303 test("abcdefghijklmnopqrst", 1, 20, "abcde", 1);
304 test("abcdefghijklmnopqrst", 1, 20, "abcdefghij", 1);
305 test("abcdefghijklmnopqrst", 1, 20, "abcdefghijklmnopqrst", 1);
306 test("abcdefghijklmnopqrst", 10, 0, "", 0);
307 test("abcdefghijklmnopqrst", 10, 0, "abcde", -5);
308 test("abcdefghijklmnopqrst", 10, 0, "abcdefghij", -10);
309 test("abcdefghijklmnopqrst", 10, 0, "abcdefghijklmnopqrst", -20);
310 test("abcdefghijklmnopqrst", 10, 1, "", 1);
311 test("abcdefghijklmnopqrst", 10, 1, "abcde", 10);
312 test("abcdefghijklmnopqrst", 10, 1, "abcdefghij", 10);
313 test("abcdefghijklmnopqrst", 10, 1, "abcdefghijklmnopqrst", 10);
314 test("abcdefghijklmnopqrst", 10, 5, "", 5);
315 test("abcdefghijklmnopqrst", 10, 5, "abcde", 10);
316 test("abcdefghijklmnopqrst", 10, 5, "abcdefghij", 10);
317 test("abcdefghijklmnopqrst", 10, 5, "abcdefghijklmnopqrst", 10);
318 test("abcdefghijklmnopqrst", 10, 9, "", 9);
319 test("abcdefghijklmnopqrst", 10, 9, "abcde", 10);
320 test("abcdefghijklmnopqrst", 10, 9, "abcdefghij", 10);
321 test("abcdefghijklmnopqrst", 10, 9, "abcdefghijklmnopqrst", 10);
322 test("abcdefghijklmnopqrst", 10, 10, "", 10);
323 test("abcdefghijklmnopqrst", 10, 10, "abcde", 10);
324 test("abcdefghijklmnopqrst", 10, 10, "abcdefghij", 10);
325 test("abcdefghijklmnopqrst", 10, 10, "abcdefghijklmnopqrst", 10);
326 test("abcdefghijklmnopqrst", 10, 11, "", 10);
327 test("abcdefghijklmnopqrst", 10, 11, "abcde", 10);
328 test("abcdefghijklmnopqrst", 10, 11, "abcdefghij", 10);
329 test("abcdefghijklmnopqrst", 10, 11, "abcdefghijklmnopqrst", 10);
330 test("abcdefghijklmnopqrst", 19, 0, "", 0);
331 test("abcdefghijklmnopqrst", 19, 0, "abcde", -5);
332 test("abcdefghijklmnopqrst", 19, 0, "abcdefghij", -10);
333 test("abcdefghijklmnopqrst", 19, 0, "abcdefghijklmnopqrst", -20);
334 test("abcdefghijklmnopqrst", 19, 1, "", 1);
335 test("abcdefghijklmnopqrst", 19, 1, "abcde", 19);
336 test("abcdefghijklmnopqrst", 19, 1, "abcdefghij", 19);
337 test("abcdefghijklmnopqrst", 19, 1, "abcdefghijklmnopqrst", 19);
338 test("abcdefghijklmnopqrst", 19, 2, "", 1);
339 test("abcdefghijklmnopqrst", 19, 2, "abcde", 19);
340 test("abcdefghijklmnopqrst", 19, 2, "abcdefghij", 19);
341 test("abcdefghijklmnopqrst", 19, 2, "abcdefghijklmnopqrst", 19);
342 test("abcdefghijklmnopqrst", 20, 0, "", 0);
343 test("abcdefghijklmnopqrst", 20, 0, "abcde", -5);
344 test("abcdefghijklmnopqrst", 20, 0, "abcdefghij", -10);
345 test("abcdefghijklmnopqrst", 20, 0, "abcdefghijklmnopqrst", -20);
346 test("abcdefghijklmnopqrst", 20, 1, "", 0);
347 test("abcdefghijklmnopqrst", 20, 1, "abcde", -5);
348 test("abcdefghijklmnopqrst", 20, 1, "abcdefghij", -10);
349 test("abcdefghijklmnopqrst", 20, 1, "abcdefghijklmnopqrst", -20);
350 test("abcdefghijklmnopqrst", 21, 0, "", 0);
351 test("abcdefghijklmnopqrst", 21, 0, "abcde", 0);
352 test("abcdefghijklmnopqrst", 21, 0, "abcdefghij", 0);
353 test("abcdefghijklmnopqrst", 21, 0, "abcdefghijklmnopqrst", 0);
357 int main(int, char**)
359 test0();
360 test1();
361 test2();
364 test("", 0, 0, "", 0);
365 test("", 0, 0, "abcde", -5);
366 test("", 0, 0, "abcdefghij", -10);
367 test("", 0, 0, "abcdefghijklmnopqrst", -20);
368 test("abcde", 0, 2, "", 5);
369 test("abcde", 0, 6,"abcde", 0);
370 test("abcde", 0, 6, "abcdefghij", -5);
371 test("abcde", 0, 6, "abcdefghijklmnopqrst", -15);
372 test("abcdefghij", 3, 3, "", 10);
373 test("abcdefghij", 3, 3,"abcde", 5);
374 test("abcdefghij", 3, 3, "def", 0);
375 test("abcdefghij", 0, 4, "abcdefghijklmnopqrst", -10);
376 test("abcdefghijklmnopqrst", 5, 5, "", 20);
377 test("abcdefghijklmnopqrst", 0, 8, "abcde", 15);
378 test("abcdefghijklmnopqrst", 0, 12, "abcdefghij", 10);
379 test("abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), "abcdefghijklmnopqrst", 0);
383 test(L"", 0, 0, L"", 0);
384 test(L"", 0, 0, L"abcde", -5);
385 test(L"", 0, 0, L"abcdefghij", -10);
386 test(L"", 0, 0, L"abcdefghijklmnopqrst", -20);
387 test(L"abcde", 0, 2, L"", 5);
388 test(L"abcde", 0, 6, L"abcde", 0);
389 test(L"abcde", 0, 6, L"abcdefghij", -5);
390 test(L"abcde", 0, 6, L"abcdefghijklmnopqrst", -15);
391 test(L"abcdefghij", 3, 3, L"", 10);
392 test(L"abcdefghij", 3, 3, L"abcde", 5);
393 test(L"abcdefghij", 3, 3, L"def", 0);
394 test(L"abcdefghij", 0, 4, L"abcdefghijklmnopqrst", -10);
395 test(L"abcdefghijklmnopqrst", 5, 5, L"", 20);
396 test(L"abcdefghijklmnopqrst", 0, 8, L"abcde", 15);
397 test(L"abcdefghijklmnopqrst", 0, 12, L"abcdefghij", 10);
398 test(L"abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), L"abcdefghijklmnopqrst", 0);
401 #if TEST_STD_VER >= 11
403 test(U"", 0, 0, U"", 0);
404 test(U"", 0, 0, U"abcde", -5);
405 test(U"", 0, 0, U"abcdefghij", -10);
406 test(U"", 0, 0, U"abcdefghijklmnopqrst", -20);
407 test(U"abcde", 0, 2, U"", 5);
408 test(U"abcde", 0, 6, U"abcde", 0);
409 test(U"abcde", 0, 6, U"abcdefghij", -5);
410 test(U"abcde", 0, 6, U"abcdefghijklmnopqrst", -15);
411 test(U"abcdefghij", 3, 3, U"", 10);
412 test(U"abcdefghij", 3, 3, U"abcde", 5);
413 test(U"abcdefghij", 3, 3, U"def", 0);
414 test(U"abcdefghij", 0, 4, U"abcdefghijklmnopqrst", -10);
415 test(U"abcdefghijklmnopqrst", 5, 5, U"", 20);
416 test(U"abcdefghijklmnopqrst", 0, 8, U"abcde", 15);
417 test(U"abcdefghijklmnopqrst", 0, 12, U"abcdefghij", 10);
418 test(U"abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), U"abcdefghijklmnopqrst", 0);
422 test(u"", 0, 0, u"", 0);
423 test(u"", 0, 0, u"abcde", -5);
424 test(u"", 0, 0, u"abcdefghij", -10);
425 test(u"", 0, 0, u"abcdefghijklmnopqrst", -20);
426 test(u"abcde", 0, 2, u"", 5);
427 test(u"abcde", 0, 6, u"abcde", 0);
428 test(u"abcde", 0, 6, u"abcdefghij", -5);
429 test(u"abcde", 0, 6, u"abcdefghijklmnopqrst", -15);
430 test(u"abcdefghij", 3, 3, u"", 10);
431 test(u"abcdefghij", 3, 3, u"abcde", 5);
432 test(u"abcdefghij", 3, 3, u"def", 0);
433 test(u"abcdefghij", 0, 4, u"abcdefghijklmnopqrst", -10);
434 test(u"abcdefghijklmnopqrst", 5, 5, u"", 20);
435 test(u"abcdefghijklmnopqrst", 0, 8, u"abcde", 15);
436 test(u"abcdefghijklmnopqrst", 0, 12, u"abcdefghij", 10);
437 test(u"abcdefghijklmnopqrst", 0, static_cast<size_t>(-1), u"abcdefghijklmnopqrst", 0);
439 #endif
441 #if TEST_STD_VER > 11
443 typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
444 constexpr SV sv1;
445 constexpr SV sv2 { "abcde", 5 };
446 static_assert ( sv1.compare(0, 0, "") == 0, "" );
447 static_assert ( sv1.compare(0, 0, "abcde") < 0, "" );
448 static_assert ( sv2.compare(0, 2, "") > 0, "" );
449 static_assert ( sv2.compare(0, 6, "abcde") == 0, "" );
451 #endif
453 return 0;