| 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 | // int compare(size_type pos, size_type n1, const charT *s) const; // constexpr since C++20 |
| 12 | |
| 13 | #include <string> |
| 14 | #include <stdexcept> |
| 15 | #include <cassert> |
| 16 | |
| 17 | #include "min_allocator.h" |
| 18 | |
| 19 | #include "test_macros.h" |
| 20 | |
| 21 | TEST_CONSTEXPR_CXX20 int sign(int x) { |
| 22 | if (x == 0) |
| 23 | return 0; |
| 24 | if (x < 0) |
| 25 | return -1; |
| 26 | return 1; |
| 27 | } |
| 28 | |
| 29 | template <class S> |
| 30 | TEST_CONSTEXPR_CXX20 void |
| 31 | test(const S& s, typename S::size_type pos1, typename S::size_type n1, const typename S::value_type* str, int x) { |
| 32 | if (pos1 <= s.size()) |
| 33 | assert(sign(s.compare(pos1, n1, str)) == sign(x)); |
| 34 | #ifndef TEST_HAS_NO_EXCEPTIONS |
| 35 | else if (!TEST_IS_CONSTANT_EVALUATED) { |
| 36 | try { |
| 37 | TEST_IGNORE_NODISCARD s.compare(pos1, n1, str); |
| 38 | assert(false); |
| 39 | } catch (std::out_of_range&) { |
| 40 | assert(pos1 > s.size()); |
| 41 | } |
| 42 | } |
| 43 | #endif |
| 44 | } |
| 45 | |
| 46 | template <class S> |
| 47 | TEST_CONSTEXPR_CXX20 void test0() { |
| 48 | test(S("" ), 0, 0, "" , 0); |
| 49 | test(S("" ), 0, 0, "abcde" , -5); |
| 50 | test(S("" ), 0, 0, "abcdefghij" , -10); |
| 51 | test(S("" ), 0, 0, "abcdefghijklmnopqrst" , -20); |
| 52 | test(S("" ), 0, 1, "" , 0); |
| 53 | test(S("" ), 0, 1, "abcde" , -5); |
| 54 | test(S("" ), 0, 1, "abcdefghij" , -10); |
| 55 | test(S("" ), 0, 1, "abcdefghijklmnopqrst" , -20); |
| 56 | test(S("" ), 1, 0, "" , 0); |
| 57 | test(S("" ), 1, 0, "abcde" , 0); |
| 58 | test(S("" ), 1, 0, "abcdefghij" , 0); |
| 59 | test(S("" ), 1, 0, "abcdefghijklmnopqrst" , 0); |
| 60 | test(S("abcde" ), 0, 0, "" , 0); |
| 61 | test(S("abcde" ), 0, 0, "abcde" , -5); |
| 62 | test(S("abcde" ), 0, 0, "abcdefghij" , -10); |
| 63 | test(S("abcde" ), 0, 0, "abcdefghijklmnopqrst" , -20); |
| 64 | test(S("abcde" ), 0, 1, "" , 1); |
| 65 | test(S("abcde" ), 0, 1, "abcde" , -4); |
| 66 | test(S("abcde" ), 0, 1, "abcdefghij" , -9); |
| 67 | test(S("abcde" ), 0, 1, "abcdefghijklmnopqrst" , -19); |
| 68 | test(S("abcde" ), 0, 2, "" , 2); |
| 69 | test(S("abcde" ), 0, 2, "abcde" , -3); |
| 70 | test(S("abcde" ), 0, 2, "abcdefghij" , -8); |
| 71 | test(S("abcde" ), 0, 2, "abcdefghijklmnopqrst" , -18); |
| 72 | test(S("abcde" ), 0, 4, "" , 4); |
| 73 | test(S("abcde" ), 0, 4, "abcde" , -1); |
| 74 | test(S("abcde" ), 0, 4, "abcdefghij" , -6); |
| 75 | test(S("abcde" ), 0, 4, "abcdefghijklmnopqrst" , -16); |
| 76 | test(S("abcde" ), 0, 5, "" , 5); |
| 77 | test(S("abcde" ), 0, 5, "abcde" , 0); |
| 78 | test(S("abcde" ), 0, 5, "abcdefghij" , -5); |
| 79 | test(S("abcde" ), 0, 5, "abcdefghijklmnopqrst" , -15); |
| 80 | test(S("abcde" ), 0, 6, "" , 5); |
| 81 | test(S("abcde" ), 0, 6, "abcde" , 0); |
| 82 | test(S("abcde" ), 0, 6, "abcdefghij" , -5); |
| 83 | test(S("abcde" ), 0, 6, "abcdefghijklmnopqrst" , -15); |
| 84 | test(S("abcde" ), 1, 0, "" , 0); |
| 85 | test(S("abcde" ), 1, 0, "abcde" , -5); |
| 86 | test(S("abcde" ), 1, 0, "abcdefghij" , -10); |
| 87 | test(S("abcde" ), 1, 0, "abcdefghijklmnopqrst" , -20); |
| 88 | test(S("abcde" ), 1, 1, "" , 1); |
| 89 | test(S("abcde" ), 1, 1, "abcde" , 1); |
| 90 | test(S("abcde" ), 1, 1, "abcdefghij" , 1); |
| 91 | test(S("abcde" ), 1, 1, "abcdefghijklmnopqrst" , 1); |
| 92 | test(S("abcde" ), 1, 2, "" , 2); |
| 93 | test(S("abcde" ), 1, 2, "abcde" , 1); |
| 94 | test(S("abcde" ), 1, 2, "abcdefghij" , 1); |
| 95 | test(S("abcde" ), 1, 2, "abcdefghijklmnopqrst" , 1); |
| 96 | test(S("abcde" ), 1, 3, "" , 3); |
| 97 | test(S("abcde" ), 1, 3, "abcde" , 1); |
| 98 | test(S("abcde" ), 1, 3, "abcdefghij" , 1); |
| 99 | test(S("abcde" ), 1, 3, "abcdefghijklmnopqrst" , 1); |
| 100 | test(S("abcde" ), 1, 4, "" , 4); |
| 101 | test(S("abcde" ), 1, 4, "abcde" , 1); |
| 102 | test(S("abcde" ), 1, 4, "abcdefghij" , 1); |
| 103 | test(S("abcde" ), 1, 4, "abcdefghijklmnopqrst" , 1); |
| 104 | test(S("abcde" ), 1, 5, "" , 4); |
| 105 | test(S("abcde" ), 1, 5, "abcde" , 1); |
| 106 | test(S("abcde" ), 1, 5, "abcdefghij" , 1); |
| 107 | test(S("abcde" ), 1, 5, "abcdefghijklmnopqrst" , 1); |
| 108 | test(S("abcde" ), 2, 0, "" , 0); |
| 109 | test(S("abcde" ), 2, 0, "abcde" , -5); |
| 110 | test(S("abcde" ), 2, 0, "abcdefghij" , -10); |
| 111 | test(S("abcde" ), 2, 0, "abcdefghijklmnopqrst" , -20); |
| 112 | test(S("abcde" ), 2, 1, "" , 1); |
| 113 | test(S("abcde" ), 2, 1, "abcde" , 2); |
| 114 | test(S("abcde" ), 2, 1, "abcdefghij" , 2); |
| 115 | test(S("abcde" ), 2, 1, "abcdefghijklmnopqrst" , 2); |
| 116 | test(S("abcde" ), 2, 2, "" , 2); |
| 117 | test(S("abcde" ), 2, 2, "abcde" , 2); |
| 118 | test(S("abcde" ), 2, 2, "abcdefghij" , 2); |
| 119 | test(S("abcde" ), 2, 2, "abcdefghijklmnopqrst" , 2); |
| 120 | test(S("abcde" ), 2, 3, "" , 3); |
| 121 | test(S("abcde" ), 2, 3, "abcde" , 2); |
| 122 | test(S("abcde" ), 2, 3, "abcdefghij" , 2); |
| 123 | test(S("abcde" ), 2, 3, "abcdefghijklmnopqrst" , 2); |
| 124 | test(S("abcde" ), 2, 4, "" , 3); |
| 125 | test(S("abcde" ), 2, 4, "abcde" , 2); |
| 126 | test(S("abcde" ), 2, 4, "abcdefghij" , 2); |
| 127 | test(S("abcde" ), 2, 4, "abcdefghijklmnopqrst" , 2); |
| 128 | test(S("abcde" ), 4, 0, "" , 0); |
| 129 | test(S("abcde" ), 4, 0, "abcde" , -5); |
| 130 | test(S("abcde" ), 4, 0, "abcdefghij" , -10); |
| 131 | test(S("abcde" ), 4, 0, "abcdefghijklmnopqrst" , -20); |
| 132 | test(S("abcde" ), 4, 1, "" , 1); |
| 133 | test(S("abcde" ), 4, 1, "abcde" , 4); |
| 134 | test(S("abcde" ), 4, 1, "abcdefghij" , 4); |
| 135 | test(S("abcde" ), 4, 1, "abcdefghijklmnopqrst" , 4); |
| 136 | test(S("abcde" ), 4, 2, "" , 1); |
| 137 | test(S("abcde" ), 4, 2, "abcde" , 4); |
| 138 | test(S("abcde" ), 4, 2, "abcdefghij" , 4); |
| 139 | test(S("abcde" ), 4, 2, "abcdefghijklmnopqrst" , 4); |
| 140 | test(S("abcde" ), 5, 0, "" , 0); |
| 141 | test(S("abcde" ), 5, 0, "abcde" , -5); |
| 142 | test(S("abcde" ), 5, 0, "abcdefghij" , -10); |
| 143 | test(S("abcde" ), 5, 0, "abcdefghijklmnopqrst" , -20); |
| 144 | test(S("abcde" ), 5, 1, "" , 0); |
| 145 | test(S("abcde" ), 5, 1, "abcde" , -5); |
| 146 | test(S("abcde" ), 5, 1, "abcdefghij" , -10); |
| 147 | test(S("abcde" ), 5, 1, "abcdefghijklmnopqrst" , -20); |
| 148 | } |
| 149 | |
| 150 | template <class S> |
| 151 | TEST_CONSTEXPR_CXX20 void test1() { |
| 152 | test(S("abcde" ), 6, 0, "" , 0); |
| 153 | test(S("abcde" ), 6, 0, "abcde" , 0); |
| 154 | test(S("abcde" ), 6, 0, "abcdefghij" , 0); |
| 155 | test(S("abcde" ), 6, 0, "abcdefghijklmnopqrst" , 0); |
| 156 | test(S("abcdefghij" ), 0, 0, "" , 0); |
| 157 | test(S("abcdefghij" ), 0, 0, "abcde" , -5); |
| 158 | test(S("abcdefghij" ), 0, 0, "abcdefghij" , -10); |
| 159 | test(S("abcdefghij" ), 0, 0, "abcdefghijklmnopqrst" , -20); |
| 160 | test(S("abcdefghij" ), 0, 1, "" , 1); |
| 161 | test(S("abcdefghij" ), 0, 1, "abcde" , -4); |
| 162 | test(S("abcdefghij" ), 0, 1, "abcdefghij" , -9); |
| 163 | test(S("abcdefghij" ), 0, 1, "abcdefghijklmnopqrst" , -19); |
| 164 | test(S("abcdefghij" ), 0, 5, "" , 5); |
| 165 | test(S("abcdefghij" ), 0, 5, "abcde" , 0); |
| 166 | test(S("abcdefghij" ), 0, 5, "abcdefghij" , -5); |
| 167 | test(S("abcdefghij" ), 0, 5, "abcdefghijklmnopqrst" , -15); |
| 168 | test(S("abcdefghij" ), 0, 9, "" , 9); |
| 169 | test(S("abcdefghij" ), 0, 9, "abcde" , 4); |
| 170 | test(S("abcdefghij" ), 0, 9, "abcdefghij" , -1); |
| 171 | test(S("abcdefghij" ), 0, 9, "abcdefghijklmnopqrst" , -11); |
| 172 | test(S("abcdefghij" ), 0, 10, "" , 10); |
| 173 | test(S("abcdefghij" ), 0, 10, "abcde" , 5); |
| 174 | test(S("abcdefghij" ), 0, 10, "abcdefghij" , 0); |
| 175 | test(S("abcdefghij" ), 0, 10, "abcdefghijklmnopqrst" , -10); |
| 176 | test(S("abcdefghij" ), 0, 11, "" , 10); |
| 177 | test(S("abcdefghij" ), 0, 11, "abcde" , 5); |
| 178 | test(S("abcdefghij" ), 0, 11, "abcdefghij" , 0); |
| 179 | test(S("abcdefghij" ), 0, 11, "abcdefghijklmnopqrst" , -10); |
| 180 | test(S("abcdefghij" ), 1, 0, "" , 0); |
| 181 | test(S("abcdefghij" ), 1, 0, "abcde" , -5); |
| 182 | test(S("abcdefghij" ), 1, 0, "abcdefghij" , -10); |
| 183 | test(S("abcdefghij" ), 1, 0, "abcdefghijklmnopqrst" , -20); |
| 184 | test(S("abcdefghij" ), 1, 1, "" , 1); |
| 185 | test(S("abcdefghij" ), 1, 1, "abcde" , 1); |
| 186 | test(S("abcdefghij" ), 1, 1, "abcdefghij" , 1); |
| 187 | test(S("abcdefghij" ), 1, 1, "abcdefghijklmnopqrst" , 1); |
| 188 | test(S("abcdefghij" ), 1, 4, "" , 4); |
| 189 | test(S("abcdefghij" ), 1, 4, "abcde" , 1); |
| 190 | test(S("abcdefghij" ), 1, 4, "abcdefghij" , 1); |
| 191 | test(S("abcdefghij" ), 1, 4, "abcdefghijklmnopqrst" , 1); |
| 192 | test(S("abcdefghij" ), 1, 8, "" , 8); |
| 193 | test(S("abcdefghij" ), 1, 8, "abcde" , 1); |
| 194 | test(S("abcdefghij" ), 1, 8, "abcdefghij" , 1); |
| 195 | test(S("abcdefghij" ), 1, 8, "abcdefghijklmnopqrst" , 1); |
| 196 | test(S("abcdefghij" ), 1, 9, "" , 9); |
| 197 | test(S("abcdefghij" ), 1, 9, "abcde" , 1); |
| 198 | test(S("abcdefghij" ), 1, 9, "abcdefghij" , 1); |
| 199 | test(S("abcdefghij" ), 1, 9, "abcdefghijklmnopqrst" , 1); |
| 200 | test(S("abcdefghij" ), 1, 10, "" , 9); |
| 201 | test(S("abcdefghij" ), 1, 10, "abcde" , 1); |
| 202 | test(S("abcdefghij" ), 1, 10, "abcdefghij" , 1); |
| 203 | test(S("abcdefghij" ), 1, 10, "abcdefghijklmnopqrst" , 1); |
| 204 | test(S("abcdefghij" ), 5, 0, "" , 0); |
| 205 | test(S("abcdefghij" ), 5, 0, "abcde" , -5); |
| 206 | test(S("abcdefghij" ), 5, 0, "abcdefghij" , -10); |
| 207 | test(S("abcdefghij" ), 5, 0, "abcdefghijklmnopqrst" , -20); |
| 208 | test(S("abcdefghij" ), 5, 1, "" , 1); |
| 209 | test(S("abcdefghij" ), 5, 1, "abcde" , 5); |
| 210 | test(S("abcdefghij" ), 5, 1, "abcdefghij" , 5); |
| 211 | test(S("abcdefghij" ), 5, 1, "abcdefghijklmnopqrst" , 5); |
| 212 | test(S("abcdefghij" ), 5, 2, "" , 2); |
| 213 | test(S("abcdefghij" ), 5, 2, "abcde" , 5); |
| 214 | test(S("abcdefghij" ), 5, 2, "abcdefghij" , 5); |
| 215 | test(S("abcdefghij" ), 5, 2, "abcdefghijklmnopqrst" , 5); |
| 216 | test(S("abcdefghij" ), 5, 4, "" , 4); |
| 217 | test(S("abcdefghij" ), 5, 4, "abcde" , 5); |
| 218 | test(S("abcdefghij" ), 5, 4, "abcdefghij" , 5); |
| 219 | test(S("abcdefghij" ), 5, 4, "abcdefghijklmnopqrst" , 5); |
| 220 | test(S("abcdefghij" ), 5, 5, "" , 5); |
| 221 | test(S("abcdefghij" ), 5, 5, "abcde" , 5); |
| 222 | test(S("abcdefghij" ), 5, 5, "abcdefghij" , 5); |
| 223 | test(S("abcdefghij" ), 5, 5, "abcdefghijklmnopqrst" , 5); |
| 224 | test(S("abcdefghij" ), 5, 6, "" , 5); |
| 225 | test(S("abcdefghij" ), 5, 6, "abcde" , 5); |
| 226 | test(S("abcdefghij" ), 5, 6, "abcdefghij" , 5); |
| 227 | test(S("abcdefghij" ), 5, 6, "abcdefghijklmnopqrst" , 5); |
| 228 | test(S("abcdefghij" ), 9, 0, "" , 0); |
| 229 | test(S("abcdefghij" ), 9, 0, "abcde" , -5); |
| 230 | test(S("abcdefghij" ), 9, 0, "abcdefghij" , -10); |
| 231 | test(S("abcdefghij" ), 9, 0, "abcdefghijklmnopqrst" , -20); |
| 232 | test(S("abcdefghij" ), 9, 1, "" , 1); |
| 233 | test(S("abcdefghij" ), 9, 1, "abcde" , 9); |
| 234 | test(S("abcdefghij" ), 9, 1, "abcdefghij" , 9); |
| 235 | test(S("abcdefghij" ), 9, 1, "abcdefghijklmnopqrst" , 9); |
| 236 | test(S("abcdefghij" ), 9, 2, "" , 1); |
| 237 | test(S("abcdefghij" ), 9, 2, "abcde" , 9); |
| 238 | test(S("abcdefghij" ), 9, 2, "abcdefghij" , 9); |
| 239 | test(S("abcdefghij" ), 9, 2, "abcdefghijklmnopqrst" , 9); |
| 240 | test(S("abcdefghij" ), 10, 0, "" , 0); |
| 241 | test(S("abcdefghij" ), 10, 0, "abcde" , -5); |
| 242 | test(S("abcdefghij" ), 10, 0, "abcdefghij" , -10); |
| 243 | test(S("abcdefghij" ), 10, 0, "abcdefghijklmnopqrst" , -20); |
| 244 | test(S("abcdefghij" ), 10, 1, "" , 0); |
| 245 | test(S("abcdefghij" ), 10, 1, "abcde" , -5); |
| 246 | test(S("abcdefghij" ), 10, 1, "abcdefghij" , -10); |
| 247 | test(S("abcdefghij" ), 10, 1, "abcdefghijklmnopqrst" , -20); |
| 248 | test(S("abcdefghij" ), 11, 0, "" , 0); |
| 249 | test(S("abcdefghij" ), 11, 0, "abcde" , 0); |
| 250 | test(S("abcdefghij" ), 11, 0, "abcdefghij" , 0); |
| 251 | test(S("abcdefghij" ), 11, 0, "abcdefghijklmnopqrst" , 0); |
| 252 | } |
| 253 | |
| 254 | template <class S> |
| 255 | TEST_CONSTEXPR_CXX20 void test2() { |
| 256 | test(S("abcdefghijklmnopqrst" ), 0, 0, "" , 0); |
| 257 | test(S("abcdefghijklmnopqrst" ), 0, 0, "abcde" , -5); |
| 258 | test(S("abcdefghijklmnopqrst" ), 0, 0, "abcdefghij" , -10); |
| 259 | test(S("abcdefghijklmnopqrst" ), 0, 0, "abcdefghijklmnopqrst" , -20); |
| 260 | test(S("abcdefghijklmnopqrst" ), 0, 1, "" , 1); |
| 261 | test(S("abcdefghijklmnopqrst" ), 0, 1, "abcde" , -4); |
| 262 | test(S("abcdefghijklmnopqrst" ), 0, 1, "abcdefghij" , -9); |
| 263 | test(S("abcdefghijklmnopqrst" ), 0, 1, "abcdefghijklmnopqrst" , -19); |
| 264 | test(S("abcdefghijklmnopqrst" ), 0, 10, "" , 10); |
| 265 | test(S("abcdefghijklmnopqrst" ), 0, 10, "abcde" , 5); |
| 266 | test(S("abcdefghijklmnopqrst" ), 0, 10, "abcdefghij" , 0); |
| 267 | test(S("abcdefghijklmnopqrst" ), 0, 10, "abcdefghijklmnopqrst" , -10); |
| 268 | test(S("abcdefghijklmnopqrst" ), 0, 19, "" , 19); |
| 269 | test(S("abcdefghijklmnopqrst" ), 0, 19, "abcde" , 14); |
| 270 | test(S("abcdefghijklmnopqrst" ), 0, 19, "abcdefghij" , 9); |
| 271 | test(S("abcdefghijklmnopqrst" ), 0, 19, "abcdefghijklmnopqrst" , -1); |
| 272 | test(S("abcdefghijklmnopqrst" ), 0, 20, "" , 20); |
| 273 | test(S("abcdefghijklmnopqrst" ), 0, 20, "abcde" , 15); |
| 274 | test(S("abcdefghijklmnopqrst" ), 0, 20, "abcdefghij" , 10); |
| 275 | test(S("abcdefghijklmnopqrst" ), 0, 20, "abcdefghijklmnopqrst" , 0); |
| 276 | test(S("abcdefghijklmnopqrst" ), 0, 21, "" , 20); |
| 277 | test(S("abcdefghijklmnopqrst" ), 0, 21, "abcde" , 15); |
| 278 | test(S("abcdefghijklmnopqrst" ), 0, 21, "abcdefghij" , 10); |
| 279 | test(S("abcdefghijklmnopqrst" ), 0, 21, "abcdefghijklmnopqrst" , 0); |
| 280 | test(S("abcdefghijklmnopqrst" ), 1, 0, "" , 0); |
| 281 | test(S("abcdefghijklmnopqrst" ), 1, 0, "abcde" , -5); |
| 282 | test(S("abcdefghijklmnopqrst" ), 1, 0, "abcdefghij" , -10); |
| 283 | test(S("abcdefghijklmnopqrst" ), 1, 0, "abcdefghijklmnopqrst" , -20); |
| 284 | test(S("abcdefghijklmnopqrst" ), 1, 1, "" , 1); |
| 285 | test(S("abcdefghijklmnopqrst" ), 1, 1, "abcde" , 1); |
| 286 | test(S("abcdefghijklmnopqrst" ), 1, 1, "abcdefghij" , 1); |
| 287 | test(S("abcdefghijklmnopqrst" ), 1, 1, "abcdefghijklmnopqrst" , 1); |
| 288 | test(S("abcdefghijklmnopqrst" ), 1, 9, "" , 9); |
| 289 | test(S("abcdefghijklmnopqrst" ), 1, 9, "abcde" , 1); |
| 290 | test(S("abcdefghijklmnopqrst" ), 1, 9, "abcdefghij" , 1); |
| 291 | test(S("abcdefghijklmnopqrst" ), 1, 9, "abcdefghijklmnopqrst" , 1); |
| 292 | test(S("abcdefghijklmnopqrst" ), 1, 18, "" , 18); |
| 293 | test(S("abcdefghijklmnopqrst" ), 1, 18, "abcde" , 1); |
| 294 | test(S("abcdefghijklmnopqrst" ), 1, 18, "abcdefghij" , 1); |
| 295 | test(S("abcdefghijklmnopqrst" ), 1, 18, "abcdefghijklmnopqrst" , 1); |
| 296 | test(S("abcdefghijklmnopqrst" ), 1, 19, "" , 19); |
| 297 | test(S("abcdefghijklmnopqrst" ), 1, 19, "abcde" , 1); |
| 298 | test(S("abcdefghijklmnopqrst" ), 1, 19, "abcdefghij" , 1); |
| 299 | test(S("abcdefghijklmnopqrst" ), 1, 19, "abcdefghijklmnopqrst" , 1); |
| 300 | test(S("abcdefghijklmnopqrst" ), 1, 20, "" , 19); |
| 301 | test(S("abcdefghijklmnopqrst" ), 1, 20, "abcde" , 1); |
| 302 | test(S("abcdefghijklmnopqrst" ), 1, 20, "abcdefghij" , 1); |
| 303 | test(S("abcdefghijklmnopqrst" ), 1, 20, "abcdefghijklmnopqrst" , 1); |
| 304 | test(S("abcdefghijklmnopqrst" ), 10, 0, "" , 0); |
| 305 | test(S("abcdefghijklmnopqrst" ), 10, 0, "abcde" , -5); |
| 306 | test(S("abcdefghijklmnopqrst" ), 10, 0, "abcdefghij" , -10); |
| 307 | test(S("abcdefghijklmnopqrst" ), 10, 0, "abcdefghijklmnopqrst" , -20); |
| 308 | test(S("abcdefghijklmnopqrst" ), 10, 1, "" , 1); |
| 309 | test(S("abcdefghijklmnopqrst" ), 10, 1, "abcde" , 10); |
| 310 | test(S("abcdefghijklmnopqrst" ), 10, 1, "abcdefghij" , 10); |
| 311 | test(S("abcdefghijklmnopqrst" ), 10, 1, "abcdefghijklmnopqrst" , 10); |
| 312 | test(S("abcdefghijklmnopqrst" ), 10, 5, "" , 5); |
| 313 | test(S("abcdefghijklmnopqrst" ), 10, 5, "abcde" , 10); |
| 314 | test(S("abcdefghijklmnopqrst" ), 10, 5, "abcdefghij" , 10); |
| 315 | test(S("abcdefghijklmnopqrst" ), 10, 5, "abcdefghijklmnopqrst" , 10); |
| 316 | test(S("abcdefghijklmnopqrst" ), 10, 9, "" , 9); |
| 317 | test(S("abcdefghijklmnopqrst" ), 10, 9, "abcde" , 10); |
| 318 | test(S("abcdefghijklmnopqrst" ), 10, 9, "abcdefghij" , 10); |
| 319 | test(S("abcdefghijklmnopqrst" ), 10, 9, "abcdefghijklmnopqrst" , 10); |
| 320 | test(S("abcdefghijklmnopqrst" ), 10, 10, "" , 10); |
| 321 | test(S("abcdefghijklmnopqrst" ), 10, 10, "abcde" , 10); |
| 322 | test(S("abcdefghijklmnopqrst" ), 10, 10, "abcdefghij" , 10); |
| 323 | test(S("abcdefghijklmnopqrst" ), 10, 10, "abcdefghijklmnopqrst" , 10); |
| 324 | test(S("abcdefghijklmnopqrst" ), 10, 11, "" , 10); |
| 325 | test(S("abcdefghijklmnopqrst" ), 10, 11, "abcde" , 10); |
| 326 | test(S("abcdefghijklmnopqrst" ), 10, 11, "abcdefghij" , 10); |
| 327 | test(S("abcdefghijklmnopqrst" ), 10, 11, "abcdefghijklmnopqrst" , 10); |
| 328 | test(S("abcdefghijklmnopqrst" ), 19, 0, "" , 0); |
| 329 | test(S("abcdefghijklmnopqrst" ), 19, 0, "abcde" , -5); |
| 330 | test(S("abcdefghijklmnopqrst" ), 19, 0, "abcdefghij" , -10); |
| 331 | test(S("abcdefghijklmnopqrst" ), 19, 0, "abcdefghijklmnopqrst" , -20); |
| 332 | test(S("abcdefghijklmnopqrst" ), 19, 1, "" , 1); |
| 333 | test(S("abcdefghijklmnopqrst" ), 19, 1, "abcde" , 19); |
| 334 | test(S("abcdefghijklmnopqrst" ), 19, 1, "abcdefghij" , 19); |
| 335 | test(S("abcdefghijklmnopqrst" ), 19, 1, "abcdefghijklmnopqrst" , 19); |
| 336 | test(S("abcdefghijklmnopqrst" ), 19, 2, "" , 1); |
| 337 | test(S("abcdefghijklmnopqrst" ), 19, 2, "abcde" , 19); |
| 338 | test(S("abcdefghijklmnopqrst" ), 19, 2, "abcdefghij" , 19); |
| 339 | test(S("abcdefghijklmnopqrst" ), 19, 2, "abcdefghijklmnopqrst" , 19); |
| 340 | test(S("abcdefghijklmnopqrst" ), 20, 0, "" , 0); |
| 341 | test(S("abcdefghijklmnopqrst" ), 20, 0, "abcde" , -5); |
| 342 | test(S("abcdefghijklmnopqrst" ), 20, 0, "abcdefghij" , -10); |
| 343 | test(S("abcdefghijklmnopqrst" ), 20, 0, "abcdefghijklmnopqrst" , -20); |
| 344 | test(S("abcdefghijklmnopqrst" ), 20, 1, "" , 0); |
| 345 | test(S("abcdefghijklmnopqrst" ), 20, 1, "abcde" , -5); |
| 346 | test(S("abcdefghijklmnopqrst" ), 20, 1, "abcdefghij" , -10); |
| 347 | test(S("abcdefghijklmnopqrst" ), 20, 1, "abcdefghijklmnopqrst" , -20); |
| 348 | test(S("abcdefghijklmnopqrst" ), 21, 0, "" , 0); |
| 349 | test(S("abcdefghijklmnopqrst" ), 21, 0, "abcde" , 0); |
| 350 | test(S("abcdefghijklmnopqrst" ), 21, 0, "abcdefghij" , 0); |
| 351 | test(S("abcdefghijklmnopqrst" ), 21, 0, "abcdefghijklmnopqrst" , 0); |
| 352 | } |
| 353 | |
| 354 | template <class S> |
| 355 | TEST_CONSTEXPR_CXX20 void test_string() { |
| 356 | test0<S>(); |
| 357 | test1<S>(); |
| 358 | test2<S>(); |
| 359 | } |
| 360 | |
| 361 | TEST_CONSTEXPR_CXX20 bool test() { |
| 362 | test_string<std::string>(); |
| 363 | #if TEST_STD_VER >= 11 |
| 364 | test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); |
| 365 | #endif |
| 366 | |
| 367 | return true; |
| 368 | } |
| 369 | |
| 370 | int main(int, char**) { |
| 371 | test(); |
| 372 | #if TEST_STD_VER > 17 |
| 373 | static_assert(test()); |
| 374 | #endif |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |