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