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