| 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 | // insert(size_type pos, const charT* s, size_type n); // constexpr since C++20 |
| 13 | |
| 14 | #include <string> |
| 15 | #include <stdexcept> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "min_allocator.h" |
| 20 | #include "asan_testing.h" |
| 21 | |
| 22 | template <class S> |
| 23 | TEST_CONSTEXPR_CXX20 void |
| 24 | test(S s, typename S::size_type pos, const typename S::value_type* str, typename S::size_type n, S expected) { |
| 25 | const typename S::size_type old_size = s.size(); |
| 26 | S s0 = s; |
| 27 | if (pos <= old_size) { |
| 28 | s.insert(pos, str, n); |
| 29 | LIBCPP_ASSERT(s.__invariants()); |
| 30 | assert(s == expected); |
| 31 | LIBCPP_ASSERT(is_string_asan_correct(s)); |
| 32 | } |
| 33 | #ifndef TEST_HAS_NO_EXCEPTIONS |
| 34 | else if (!TEST_IS_CONSTANT_EVALUATED) { |
| 35 | try { |
| 36 | s.insert(pos, str, n); |
| 37 | assert(false); |
| 38 | } catch (std::out_of_range&) { |
| 39 | assert(pos > old_size); |
| 40 | assert(s == s0); |
| 41 | } |
| 42 | } |
| 43 | #endif |
| 44 | } |
| 45 | |
| 46 | template <class S> |
| 47 | TEST_CONSTEXPR_CXX20 bool test() { |
| 48 | { |
| 49 | test(S("" ), 0, "" , 0, S("" )); |
| 50 | test(S("" ), 0, "12345" , 0, S("" )); |
| 51 | test(S("" ), 0, "12345" , 1, S("1" )); |
| 52 | test(S("" ), 0, "12345" , 2, S("12" )); |
| 53 | test(S("" ), 0, "12345" , 4, S("1234" )); |
| 54 | test(S("" ), 0, "12345" , 5, S("12345" )); |
| 55 | test(S("" ), 0, "1234567890" , 0, S("" )); |
| 56 | test(S("" ), 0, "1234567890" , 1, S("1" )); |
| 57 | test(S("" ), 0, "1234567890" , 5, S("12345" )); |
| 58 | test(S("" ), 0, "1234567890" , 9, S("123456789" )); |
| 59 | test(S("" ), 0, "1234567890" , 10, S("1234567890" )); |
| 60 | test(S("" ), 0, "12345678901234567890" , 0, S("" )); |
| 61 | test(S("" ), 0, "12345678901234567890" , 1, S("1" )); |
| 62 | test(S("" ), 0, "12345678901234567890" , 10, S("1234567890" )); |
| 63 | test(S("" ), 0, "12345678901234567890" , 19, S("1234567890123456789" )); |
| 64 | test(S("" ), 0, "12345678901234567890" , 20, S("12345678901234567890" )); |
| 65 | test(S("" ), 1, "" , 0, S("can't happen" )); |
| 66 | test(S("" ), 1, "12345" , 0, S("can't happen" )); |
| 67 | test(S("" ), 1, "12345" , 1, S("can't happen" )); |
| 68 | test(S("" ), 1, "12345" , 2, S("can't happen" )); |
| 69 | test(S("" ), 1, "12345" , 4, S("can't happen" )); |
| 70 | test(S("" ), 1, "12345" , 5, S("can't happen" )); |
| 71 | test(S("" ), 1, "1234567890" , 0, S("can't happen" )); |
| 72 | test(S("" ), 1, "1234567890" , 1, S("can't happen" )); |
| 73 | test(S("" ), 1, "1234567890" , 5, S("can't happen" )); |
| 74 | test(S("" ), 1, "1234567890" , 9, S("can't happen" )); |
| 75 | test(S("" ), 1, "1234567890" , 10, S("can't happen" )); |
| 76 | test(S("" ), 1, "12345678901234567890" , 0, S("can't happen" )); |
| 77 | test(S("" ), 1, "12345678901234567890" , 1, S("can't happen" )); |
| 78 | test(S("" ), 1, "12345678901234567890" , 10, S("can't happen" )); |
| 79 | test(S("" ), 1, "12345678901234567890" , 19, S("can't happen" )); |
| 80 | test(S("" ), 1, "12345678901234567890" , 20, S("can't happen" )); |
| 81 | test(S("abcde" ), 0, "" , 0, S("abcde" )); |
| 82 | test(S("abcde" ), 0, "12345" , 0, S("abcde" )); |
| 83 | test(S("abcde" ), 0, "12345" , 1, S("1abcde" )); |
| 84 | test(S("abcde" ), 0, "12345" , 2, S("12abcde" )); |
| 85 | test(S("abcde" ), 0, "12345" , 4, S("1234abcde" )); |
| 86 | test(S("abcde" ), 0, "12345" , 5, S("12345abcde" )); |
| 87 | test(S("abcde" ), 0, "1234567890" , 0, S("abcde" )); |
| 88 | test(S("abcde" ), 0, "1234567890" , 1, S("1abcde" )); |
| 89 | test(S("abcde" ), 0, "1234567890" , 5, S("12345abcde" )); |
| 90 | test(S("abcde" ), 0, "1234567890" , 9, S("123456789abcde" )); |
| 91 | test(S("abcde" ), 0, "1234567890" , 10, S("1234567890abcde" )); |
| 92 | test(S("abcde" ), 0, "12345678901234567890" , 0, S("abcde" )); |
| 93 | test(S("abcde" ), 0, "12345678901234567890" , 1, S("1abcde" )); |
| 94 | test(S("abcde" ), 0, "12345678901234567890" , 10, S("1234567890abcde" )); |
| 95 | test(S("abcde" ), 0, "12345678901234567890" , 19, S("1234567890123456789abcde" )); |
| 96 | test(S("abcde" ), 0, "12345678901234567890" , 20, S("12345678901234567890abcde" )); |
| 97 | test(S("abcde" ), 1, "" , 0, S("abcde" )); |
| 98 | test(S("abcde" ), 1, "12345" , 0, S("abcde" )); |
| 99 | test(S("abcde" ), 1, "12345" , 1, S("a1bcde" )); |
| 100 | test(S("abcde" ), 1, "12345" , 2, S("a12bcde" )); |
| 101 | test(S("abcde" ), 1, "12345" , 4, S("a1234bcde" )); |
| 102 | test(S("abcde" ), 1, "12345" , 5, S("a12345bcde" )); |
| 103 | test(S("abcde" ), 1, "1234567890" , 0, S("abcde" )); |
| 104 | test(S("abcde" ), 1, "1234567890" , 1, S("a1bcde" )); |
| 105 | test(S("abcde" ), 1, "1234567890" , 5, S("a12345bcde" )); |
| 106 | test(S("abcde" ), 1, "1234567890" , 9, S("a123456789bcde" )); |
| 107 | test(S("abcde" ), 1, "1234567890" , 10, S("a1234567890bcde" )); |
| 108 | test(S("abcde" ), 1, "12345678901234567890" , 0, S("abcde" )); |
| 109 | test(S("abcde" ), 1, "12345678901234567890" , 1, S("a1bcde" )); |
| 110 | test(S("abcde" ), 1, "12345678901234567890" , 10, S("a1234567890bcde" )); |
| 111 | test(S("abcde" ), 1, "12345678901234567890" , 19, S("a1234567890123456789bcde" )); |
| 112 | test(S("abcde" ), 1, "12345678901234567890" , 20, S("a12345678901234567890bcde" )); |
| 113 | test(S("abcde" ), 2, "" , 0, S("abcde" )); |
| 114 | test(S("abcde" ), 2, "12345" , 0, S("abcde" )); |
| 115 | test(S("abcde" ), 2, "12345" , 1, S("ab1cde" )); |
| 116 | test(S("abcde" ), 2, "12345" , 2, S("ab12cde" )); |
| 117 | test(S("abcde" ), 2, "12345" , 4, S("ab1234cde" )); |
| 118 | test(S("abcde" ), 2, "12345" , 5, S("ab12345cde" )); |
| 119 | test(S("abcde" ), 2, "1234567890" , 0, S("abcde" )); |
| 120 | test(S("abcde" ), 2, "1234567890" , 1, S("ab1cde" )); |
| 121 | test(S("abcde" ), 2, "1234567890" , 5, S("ab12345cde" )); |
| 122 | test(S("abcde" ), 2, "1234567890" , 9, S("ab123456789cde" )); |
| 123 | test(S("abcde" ), 2, "1234567890" , 10, S("ab1234567890cde" )); |
| 124 | test(S("abcde" ), 2, "12345678901234567890" , 0, S("abcde" )); |
| 125 | test(S("abcde" ), 2, "12345678901234567890" , 1, S("ab1cde" )); |
| 126 | test(S("abcde" ), 2, "12345678901234567890" , 10, S("ab1234567890cde" )); |
| 127 | test(S("abcde" ), 2, "12345678901234567890" , 19, S("ab1234567890123456789cde" )); |
| 128 | test(S("abcde" ), 2, "12345678901234567890" , 20, S("ab12345678901234567890cde" )); |
| 129 | test(S("abcde" ), 4, "" , 0, S("abcde" )); |
| 130 | test(S("abcde" ), 4, "12345" , 0, S("abcde" )); |
| 131 | test(S("abcde" ), 4, "12345" , 1, S("abcd1e" )); |
| 132 | test(S("abcde" ), 4, "12345" , 2, S("abcd12e" )); |
| 133 | test(S("abcde" ), 4, "12345" , 4, S("abcd1234e" )); |
| 134 | test(S("abcde" ), 4, "12345" , 5, S("abcd12345e" )); |
| 135 | test(S("abcde" ), 4, "1234567890" , 0, S("abcde" )); |
| 136 | test(S("abcde" ), 4, "1234567890" , 1, S("abcd1e" )); |
| 137 | test(S("abcde" ), 4, "1234567890" , 5, S("abcd12345e" )); |
| 138 | test(S("abcde" ), 4, "1234567890" , 9, S("abcd123456789e" )); |
| 139 | test(S("abcde" ), 4, "1234567890" , 10, S("abcd1234567890e" )); |
| 140 | test(S("abcde" ), 4, "12345678901234567890" , 0, S("abcde" )); |
| 141 | test(S("abcde" ), 4, "12345678901234567890" , 1, S("abcd1e" )); |
| 142 | test(S("abcde" ), 4, "12345678901234567890" , 10, S("abcd1234567890e" )); |
| 143 | test(S("abcde" ), 4, "12345678901234567890" , 19, S("abcd1234567890123456789e" )); |
| 144 | test(S("abcde" ), 4, "12345678901234567890" , 20, S("abcd12345678901234567890e" )); |
| 145 | test(S("abcde" ), 5, "" , 0, S("abcde" )); |
| 146 | test(S("abcde" ), 5, "12345" , 0, S("abcde" )); |
| 147 | test(S("abcde" ), 5, "12345" , 1, S("abcde1" )); |
| 148 | test(S("abcde" ), 5, "12345" , 2, S("abcde12" )); |
| 149 | test(S("abcde" ), 5, "12345" , 4, S("abcde1234" )); |
| 150 | test(S("abcde" ), 5, "12345" , 5, S("abcde12345" )); |
| 151 | test(S("abcde" ), 5, "1234567890" , 0, S("abcde" )); |
| 152 | test(S("abcde" ), 5, "1234567890" , 1, S("abcde1" )); |
| 153 | test(S("abcde" ), 5, "1234567890" , 5, S("abcde12345" )); |
| 154 | test(S("abcde" ), 5, "1234567890" , 9, S("abcde123456789" )); |
| 155 | test(S("abcde" ), 5, "1234567890" , 10, S("abcde1234567890" )); |
| 156 | test(S("abcde" ), 5, "12345678901234567890" , 0, S("abcde" )); |
| 157 | test(S("abcde" ), 5, "12345678901234567890" , 1, S("abcde1" )); |
| 158 | test(S("abcde" ), 5, "12345678901234567890" , 10, S("abcde1234567890" )); |
| 159 | test(S("abcde" ), 5, "12345678901234567890" , 19, S("abcde1234567890123456789" )); |
| 160 | test(S("abcde" ), 5, "12345678901234567890" , 20, S("abcde12345678901234567890" )); |
| 161 | test(S("abcde" ), 6, "" , 0, S("can't happen" )); |
| 162 | test(S("abcde" ), 6, "12345" , 0, S("can't happen" )); |
| 163 | test(S("abcde" ), 6, "12345" , 1, S("can't happen" )); |
| 164 | test(S("abcde" ), 6, "12345" , 2, S("can't happen" )); |
| 165 | test(S("abcde" ), 6, "12345" , 4, S("can't happen" )); |
| 166 | test(S("abcde" ), 6, "12345" , 5, S("can't happen" )); |
| 167 | test(S("abcde" ), 6, "1234567890" , 0, S("can't happen" )); |
| 168 | test(S("abcde" ), 6, "1234567890" , 1, S("can't happen" )); |
| 169 | test(S("abcde" ), 6, "1234567890" , 5, S("can't happen" )); |
| 170 | test(S("abcde" ), 6, "1234567890" , 9, S("can't happen" )); |
| 171 | test(S("abcde" ), 6, "1234567890" , 10, S("can't happen" )); |
| 172 | test(S("abcde" ), 6, "12345678901234567890" , 0, S("can't happen" )); |
| 173 | test(S("abcde" ), 6, "12345678901234567890" , 1, S("can't happen" )); |
| 174 | test(S("abcde" ), 6, "12345678901234567890" , 10, S("can't happen" )); |
| 175 | test(S("abcde" ), 6, "12345678901234567890" , 19, S("can't happen" )); |
| 176 | test(S("abcde" ), 6, "12345678901234567890" , 20, S("can't happen" )); |
| 177 | test(S("abcdefghij" ), 0, "" , 0, S("abcdefghij" )); |
| 178 | test(S("abcdefghij" ), 0, "12345" , 0, S("abcdefghij" )); |
| 179 | test(S("abcdefghij" ), 0, "12345" , 1, S("1abcdefghij" )); |
| 180 | test(S("abcdefghij" ), 0, "12345" , 2, S("12abcdefghij" )); |
| 181 | test(S("abcdefghij" ), 0, "12345" , 4, S("1234abcdefghij" )); |
| 182 | test(S("abcdefghij" ), 0, "12345" , 5, S("12345abcdefghij" )); |
| 183 | test(S("abcdefghij" ), 0, "1234567890" , 0, S("abcdefghij" )); |
| 184 | test(S("abcdefghij" ), 0, "1234567890" , 1, S("1abcdefghij" )); |
| 185 | test(S("abcdefghij" ), 0, "1234567890" , 5, S("12345abcdefghij" )); |
| 186 | test(S("abcdefghij" ), 0, "1234567890" , 9, S("123456789abcdefghij" )); |
| 187 | test(S("abcdefghij" ), 0, "1234567890" , 10, S("1234567890abcdefghij" )); |
| 188 | test(S("abcdefghij" ), 0, "12345678901234567890" , 0, S("abcdefghij" )); |
| 189 | test(S("abcdefghij" ), 0, "12345678901234567890" , 1, S("1abcdefghij" )); |
| 190 | test(S("abcdefghij" ), 0, "12345678901234567890" , 10, S("1234567890abcdefghij" )); |
| 191 | test(S("abcdefghij" ), 0, "12345678901234567890" , 19, S("1234567890123456789abcdefghij" )); |
| 192 | test(S("abcdefghij" ), 0, "12345678901234567890" , 20, S("12345678901234567890abcdefghij" )); |
| 193 | test(S("abcdefghij" ), 1, "" , 0, S("abcdefghij" )); |
| 194 | test(S("abcdefghij" ), 1, "12345" , 0, S("abcdefghij" )); |
| 195 | test(S("abcdefghij" ), 1, "12345" , 1, S("a1bcdefghij" )); |
| 196 | test(S("abcdefghij" ), 1, "12345" , 2, S("a12bcdefghij" )); |
| 197 | test(S("abcdefghij" ), 1, "12345" , 4, S("a1234bcdefghij" )); |
| 198 | test(S("abcdefghij" ), 1, "12345" , 5, S("a12345bcdefghij" )); |
| 199 | test(S("abcdefghij" ), 1, "1234567890" , 0, S("abcdefghij" )); |
| 200 | test(S("abcdefghij" ), 1, "1234567890" , 1, S("a1bcdefghij" )); |
| 201 | test(S("abcdefghij" ), 1, "1234567890" , 5, S("a12345bcdefghij" )); |
| 202 | test(S("abcdefghij" ), 1, "1234567890" , 9, S("a123456789bcdefghij" )); |
| 203 | test(S("abcdefghij" ), 1, "1234567890" , 10, S("a1234567890bcdefghij" )); |
| 204 | test(S("abcdefghij" ), 1, "12345678901234567890" , 0, S("abcdefghij" )); |
| 205 | test(S("abcdefghij" ), 1, "12345678901234567890" , 1, S("a1bcdefghij" )); |
| 206 | test(S("abcdefghij" ), 1, "12345678901234567890" , 10, S("a1234567890bcdefghij" )); |
| 207 | test(S("abcdefghij" ), 1, "12345678901234567890" , 19, S("a1234567890123456789bcdefghij" )); |
| 208 | test(S("abcdefghij" ), 1, "12345678901234567890" , 20, S("a12345678901234567890bcdefghij" )); |
| 209 | test(S("abcdefghij" ), 5, "" , 0, S("abcdefghij" )); |
| 210 | test(S("abcdefghij" ), 5, "12345" , 0, S("abcdefghij" )); |
| 211 | test(S("abcdefghij" ), 5, "12345" , 1, S("abcde1fghij" )); |
| 212 | test(S("abcdefghij" ), 5, "12345" , 2, S("abcde12fghij" )); |
| 213 | test(S("abcdefghij" ), 5, "12345" , 4, S("abcde1234fghij" )); |
| 214 | test(S("abcdefghij" ), 5, "12345" , 5, S("abcde12345fghij" )); |
| 215 | test(S("abcdefghij" ), 5, "1234567890" , 0, S("abcdefghij" )); |
| 216 | test(S("abcdefghij" ), 5, "1234567890" , 1, S("abcde1fghij" )); |
| 217 | test(S("abcdefghij" ), 5, "1234567890" , 5, S("abcde12345fghij" )); |
| 218 | test(S("abcdefghij" ), 5, "1234567890" , 9, S("abcde123456789fghij" )); |
| 219 | test(S("abcdefghij" ), 5, "1234567890" , 10, S("abcde1234567890fghij" )); |
| 220 | test(S("abcdefghij" ), 5, "12345678901234567890" , 0, S("abcdefghij" )); |
| 221 | test(S("abcdefghij" ), 5, "12345678901234567890" , 1, S("abcde1fghij" )); |
| 222 | test(S("abcdefghij" ), 5, "12345678901234567890" , 10, S("abcde1234567890fghij" )); |
| 223 | test(S("abcdefghij" ), 5, "12345678901234567890" , 19, S("abcde1234567890123456789fghij" )); |
| 224 | test(S("abcdefghij" ), 5, "12345678901234567890" , 20, S("abcde12345678901234567890fghij" )); |
| 225 | test(S("abcdefghij" ), 9, "" , 0, S("abcdefghij" )); |
| 226 | test(S("abcdefghij" ), 9, "12345" , 0, S("abcdefghij" )); |
| 227 | test(S("abcdefghij" ), 9, "12345" , 1, S("abcdefghi1j" )); |
| 228 | test(S("abcdefghij" ), 9, "12345" , 2, S("abcdefghi12j" )); |
| 229 | test(S("abcdefghij" ), 9, "12345" , 4, S("abcdefghi1234j" )); |
| 230 | test(S("abcdefghij" ), 9, "12345" , 5, S("abcdefghi12345j" )); |
| 231 | test(S("abcdefghij" ), 9, "1234567890" , 0, S("abcdefghij" )); |
| 232 | test(S("abcdefghij" ), 9, "1234567890" , 1, S("abcdefghi1j" )); |
| 233 | test(S("abcdefghij" ), 9, "1234567890" , 5, S("abcdefghi12345j" )); |
| 234 | test(S("abcdefghij" ), 9, "1234567890" , 9, S("abcdefghi123456789j" )); |
| 235 | test(S("abcdefghij" ), 9, "1234567890" , 10, S("abcdefghi1234567890j" )); |
| 236 | test(S("abcdefghij" ), 9, "12345678901234567890" , 0, S("abcdefghij" )); |
| 237 | test(S("abcdefghij" ), 9, "12345678901234567890" , 1, S("abcdefghi1j" )); |
| 238 | test(S("abcdefghij" ), 9, "12345678901234567890" , 10, S("abcdefghi1234567890j" )); |
| 239 | test(S("abcdefghij" ), 9, "12345678901234567890" , 19, S("abcdefghi1234567890123456789j" )); |
| 240 | test(S("abcdefghij" ), 9, "12345678901234567890" , 20, S("abcdefghi12345678901234567890j" )); |
| 241 | test(S("abcdefghij" ), 10, "" , 0, S("abcdefghij" )); |
| 242 | test(S("abcdefghij" ), 10, "12345" , 0, S("abcdefghij" )); |
| 243 | test(S("abcdefghij" ), 10, "12345" , 1, S("abcdefghij1" )); |
| 244 | test(S("abcdefghij" ), 10, "12345" , 2, S("abcdefghij12" )); |
| 245 | test(S("abcdefghij" ), 10, "12345" , 4, S("abcdefghij1234" )); |
| 246 | test(S("abcdefghij" ), 10, "12345" , 5, S("abcdefghij12345" )); |
| 247 | test(S("abcdefghij" ), 10, "1234567890" , 0, S("abcdefghij" )); |
| 248 | test(S("abcdefghij" ), 10, "1234567890" , 1, S("abcdefghij1" )); |
| 249 | test(S("abcdefghij" ), 10, "1234567890" , 5, S("abcdefghij12345" )); |
| 250 | test(S("abcdefghij" ), 10, "1234567890" , 9, S("abcdefghij123456789" )); |
| 251 | test(S("abcdefghij" ), 10, "1234567890" , 10, S("abcdefghij1234567890" )); |
| 252 | test(S("abcdefghij" ), 10, "12345678901234567890" , 0, S("abcdefghij" )); |
| 253 | test(S("abcdefghij" ), 10, "12345678901234567890" , 1, S("abcdefghij1" )); |
| 254 | test(S("abcdefghij" ), 10, "12345678901234567890" , 10, S("abcdefghij1234567890" )); |
| 255 | test(S("abcdefghij" ), 10, "12345678901234567890" , 19, S("abcdefghij1234567890123456789" )); |
| 256 | test(S("abcdefghij" ), 10, "12345678901234567890" , 20, S("abcdefghij12345678901234567890" )); |
| 257 | test(S("abcdefghij" ), 11, "" , 0, S("can't happen" )); |
| 258 | test(S("abcdefghij" ), 11, "12345" , 0, S("can't happen" )); |
| 259 | test(S("abcdefghij" ), 11, "12345" , 1, S("can't happen" )); |
| 260 | test(S("abcdefghij" ), 11, "12345" , 2, S("can't happen" )); |
| 261 | test(S("abcdefghij" ), 11, "12345" , 4, S("can't happen" )); |
| 262 | test(S("abcdefghij" ), 11, "12345" , 5, S("can't happen" )); |
| 263 | test(S("abcdefghij" ), 11, "1234567890" , 0, S("can't happen" )); |
| 264 | test(S("abcdefghij" ), 11, "1234567890" , 1, S("can't happen" )); |
| 265 | test(S("abcdefghij" ), 11, "1234567890" , 5, S("can't happen" )); |
| 266 | test(S("abcdefghij" ), 11, "1234567890" , 9, S("can't happen" )); |
| 267 | test(S("abcdefghij" ), 11, "1234567890" , 10, S("can't happen" )); |
| 268 | test(S("abcdefghij" ), 11, "12345678901234567890" , 0, S("can't happen" )); |
| 269 | test(S("abcdefghij" ), 11, "12345678901234567890" , 1, S("can't happen" )); |
| 270 | test(S("abcdefghij" ), 11, "12345678901234567890" , 10, S("can't happen" )); |
| 271 | test(S("abcdefghij" ), 11, "12345678901234567890" , 19, S("can't happen" )); |
| 272 | test(S("abcdefghij" ), 11, "12345678901234567890" , 20, S("can't happen" )); |
| 273 | test(S("abcdefghijklmnopqrst" ), 0, "" , 0, S("abcdefghijklmnopqrst" )); |
| 274 | test(S("abcdefghijklmnopqrst" ), 0, "12345" , 0, S("abcdefghijklmnopqrst" )); |
| 275 | test(S("abcdefghijklmnopqrst" ), 0, "12345" , 1, S("1abcdefghijklmnopqrst" )); |
| 276 | test(S("abcdefghijklmnopqrst" ), 0, "12345" , 2, S("12abcdefghijklmnopqrst" )); |
| 277 | test(S("abcdefghijklmnopqrst" ), 0, "12345" , 4, S("1234abcdefghijklmnopqrst" )); |
| 278 | test(S("abcdefghijklmnopqrst" ), 0, "12345" , 5, S("12345abcdefghijklmnopqrst" )); |
| 279 | test(S("abcdefghijklmnopqrst" ), 0, "1234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 280 | test(S("abcdefghijklmnopqrst" ), 0, "1234567890" , 1, S("1abcdefghijklmnopqrst" )); |
| 281 | test(S("abcdefghijklmnopqrst" ), 0, "1234567890" , 5, S("12345abcdefghijklmnopqrst" )); |
| 282 | test(S("abcdefghijklmnopqrst" ), 0, "1234567890" , 9, S("123456789abcdefghijklmnopqrst" )); |
| 283 | test(S("abcdefghijklmnopqrst" ), 0, "1234567890" , 10, S("1234567890abcdefghijklmnopqrst" )); |
| 284 | test(S("abcdefghijklmnopqrst" ), 0, "12345678901234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 285 | test(S("abcdefghijklmnopqrst" ), 0, "12345678901234567890" , 1, S("1abcdefghijklmnopqrst" )); |
| 286 | test(S("abcdefghijklmnopqrst" ), 0, "12345678901234567890" , 10, S("1234567890abcdefghijklmnopqrst" )); |
| 287 | test(S("abcdefghijklmnopqrst" ), 0, "12345678901234567890" , 19, S("1234567890123456789abcdefghijklmnopqrst" )); |
| 288 | test(S("abcdefghijklmnopqrst" ), 0, "12345678901234567890" , 20, S("12345678901234567890abcdefghijklmnopqrst" )); |
| 289 | test(S("abcdefghijklmnopqrst" ), 1, "" , 0, S("abcdefghijklmnopqrst" )); |
| 290 | test(S("abcdefghijklmnopqrst" ), 1, "12345" , 0, S("abcdefghijklmnopqrst" )); |
| 291 | test(S("abcdefghijklmnopqrst" ), 1, "12345" , 1, S("a1bcdefghijklmnopqrst" )); |
| 292 | test(S("abcdefghijklmnopqrst" ), 1, "12345" , 2, S("a12bcdefghijklmnopqrst" )); |
| 293 | test(S("abcdefghijklmnopqrst" ), 1, "12345" , 4, S("a1234bcdefghijklmnopqrst" )); |
| 294 | test(S("abcdefghijklmnopqrst" ), 1, "12345" , 5, S("a12345bcdefghijklmnopqrst" )); |
| 295 | test(S("abcdefghijklmnopqrst" ), 1, "1234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 296 | test(S("abcdefghijklmnopqrst" ), 1, "1234567890" , 1, S("a1bcdefghijklmnopqrst" )); |
| 297 | test(S("abcdefghijklmnopqrst" ), 1, "1234567890" , 5, S("a12345bcdefghijklmnopqrst" )); |
| 298 | test(S("abcdefghijklmnopqrst" ), 1, "1234567890" , 9, S("a123456789bcdefghijklmnopqrst" )); |
| 299 | test(S("abcdefghijklmnopqrst" ), 1, "1234567890" , 10, S("a1234567890bcdefghijklmnopqrst" )); |
| 300 | test(S("abcdefghijklmnopqrst" ), 1, "12345678901234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 301 | test(S("abcdefghijklmnopqrst" ), 1, "12345678901234567890" , 1, S("a1bcdefghijklmnopqrst" )); |
| 302 | test(S("abcdefghijklmnopqrst" ), 1, "12345678901234567890" , 10, S("a1234567890bcdefghijklmnopqrst" )); |
| 303 | test(S("abcdefghijklmnopqrst" ), 1, "12345678901234567890" , 19, S("a1234567890123456789bcdefghijklmnopqrst" )); |
| 304 | test(S("abcdefghijklmnopqrst" ), 1, "12345678901234567890" , 20, S("a12345678901234567890bcdefghijklmnopqrst" )); |
| 305 | test(S("abcdefghijklmnopqrst" ), 10, "" , 0, S("abcdefghijklmnopqrst" )); |
| 306 | test(S("abcdefghijklmnopqrst" ), 10, "12345" , 0, S("abcdefghijklmnopqrst" )); |
| 307 | test(S("abcdefghijklmnopqrst" ), 10, "12345" , 1, S("abcdefghij1klmnopqrst" )); |
| 308 | test(S("abcdefghijklmnopqrst" ), 10, "12345" , 2, S("abcdefghij12klmnopqrst" )); |
| 309 | test(S("abcdefghijklmnopqrst" ), 10, "12345" , 4, S("abcdefghij1234klmnopqrst" )); |
| 310 | test(S("abcdefghijklmnopqrst" ), 10, "12345" , 5, S("abcdefghij12345klmnopqrst" )); |
| 311 | test(S("abcdefghijklmnopqrst" ), 10, "1234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 312 | test(S("abcdefghijklmnopqrst" ), 10, "1234567890" , 1, S("abcdefghij1klmnopqrst" )); |
| 313 | test(S("abcdefghijklmnopqrst" ), 10, "1234567890" , 5, S("abcdefghij12345klmnopqrst" )); |
| 314 | test(S("abcdefghijklmnopqrst" ), 10, "1234567890" , 9, S("abcdefghij123456789klmnopqrst" )); |
| 315 | test(S("abcdefghijklmnopqrst" ), 10, "1234567890" , 10, S("abcdefghij1234567890klmnopqrst" )); |
| 316 | test(S("abcdefghijklmnopqrst" ), 10, "12345678901234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 317 | test(S("abcdefghijklmnopqrst" ), 10, "12345678901234567890" , 1, S("abcdefghij1klmnopqrst" )); |
| 318 | test(S("abcdefghijklmnopqrst" ), 10, "12345678901234567890" , 10, S("abcdefghij1234567890klmnopqrst" )); |
| 319 | test(S("abcdefghijklmnopqrst" ), 10, "12345678901234567890" , 19, S("abcdefghij1234567890123456789klmnopqrst" )); |
| 320 | test(S("abcdefghijklmnopqrst" ), 10, "12345678901234567890" , 20, S("abcdefghij12345678901234567890klmnopqrst" )); |
| 321 | test(S("abcdefghijklmnopqrst" ), 19, "" , 0, S("abcdefghijklmnopqrst" )); |
| 322 | test(S("abcdefghijklmnopqrst" ), 19, "12345" , 0, S("abcdefghijklmnopqrst" )); |
| 323 | test(S("abcdefghijklmnopqrst" ), 19, "12345" , 1, S("abcdefghijklmnopqrs1t" )); |
| 324 | test(S("abcdefghijklmnopqrst" ), 19, "12345" , 2, S("abcdefghijklmnopqrs12t" )); |
| 325 | test(S("abcdefghijklmnopqrst" ), 19, "12345" , 4, S("abcdefghijklmnopqrs1234t" )); |
| 326 | test(S("abcdefghijklmnopqrst" ), 19, "12345" , 5, S("abcdefghijklmnopqrs12345t" )); |
| 327 | test(S("abcdefghijklmnopqrst" ), 19, "1234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 328 | test(S("abcdefghijklmnopqrst" ), 19, "1234567890" , 1, S("abcdefghijklmnopqrs1t" )); |
| 329 | test(S("abcdefghijklmnopqrst" ), 19, "1234567890" , 5, S("abcdefghijklmnopqrs12345t" )); |
| 330 | test(S("abcdefghijklmnopqrst" ), 19, "1234567890" , 9, S("abcdefghijklmnopqrs123456789t" )); |
| 331 | test(S("abcdefghijklmnopqrst" ), 19, "1234567890" , 10, S("abcdefghijklmnopqrs1234567890t" )); |
| 332 | test(S("abcdefghijklmnopqrst" ), 19, "12345678901234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 333 | test(S("abcdefghijklmnopqrst" ), 19, "12345678901234567890" , 1, S("abcdefghijklmnopqrs1t" )); |
| 334 | test(S("abcdefghijklmnopqrst" ), 19, "12345678901234567890" , 10, S("abcdefghijklmnopqrs1234567890t" )); |
| 335 | test(S("abcdefghijklmnopqrst" ), 19, "12345678901234567890" , 19, S("abcdefghijklmnopqrs1234567890123456789t" )); |
| 336 | test(S("abcdefghijklmnopqrst" ), 19, "12345678901234567890" , 20, S("abcdefghijklmnopqrs12345678901234567890t" )); |
| 337 | test(S("abcdefghijklmnopqrst" ), 20, "" , 0, S("abcdefghijklmnopqrst" )); |
| 338 | test(S("abcdefghijklmnopqrst" ), 20, "12345" , 0, S("abcdefghijklmnopqrst" )); |
| 339 | test(S("abcdefghijklmnopqrst" ), 20, "12345" , 1, S("abcdefghijklmnopqrst1" )); |
| 340 | test(S("abcdefghijklmnopqrst" ), 20, "12345" , 2, S("abcdefghijklmnopqrst12" )); |
| 341 | test(S("abcdefghijklmnopqrst" ), 20, "12345" , 4, S("abcdefghijklmnopqrst1234" )); |
| 342 | test(S("abcdefghijklmnopqrst" ), 20, "12345" , 5, S("abcdefghijklmnopqrst12345" )); |
| 343 | test(S("abcdefghijklmnopqrst" ), 20, "1234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 344 | test(S("abcdefghijklmnopqrst" ), 20, "1234567890" , 1, S("abcdefghijklmnopqrst1" )); |
| 345 | test(S("abcdefghijklmnopqrst" ), 20, "1234567890" , 5, S("abcdefghijklmnopqrst12345" )); |
| 346 | test(S("abcdefghijklmnopqrst" ), 20, "1234567890" , 9, S("abcdefghijklmnopqrst123456789" )); |
| 347 | test(S("abcdefghijklmnopqrst" ), 20, "1234567890" , 10, S("abcdefghijklmnopqrst1234567890" )); |
| 348 | test(S("abcdefghijklmnopqrst" ), 20, "12345678901234567890" , 0, S("abcdefghijklmnopqrst" )); |
| 349 | test(S("abcdefghijklmnopqrst" ), 20, "12345678901234567890" , 1, S("abcdefghijklmnopqrst1" )); |
| 350 | test(S("abcdefghijklmnopqrst" ), 20, "12345678901234567890" , 10, S("abcdefghijklmnopqrst1234567890" )); |
| 351 | test(S("abcdefghijklmnopqrst" ), 20, "12345678901234567890" , 19, S("abcdefghijklmnopqrst1234567890123456789" )); |
| 352 | test(S("abcdefghijklmnopqrst" ), 20, "12345678901234567890" , 20, S("abcdefghijklmnopqrst12345678901234567890" )); |
| 353 | test(S("abcdefghijklmnopqrst" ), 21, "" , 0, S("can't happen" )); |
| 354 | test(S("abcdefghijklmnopqrst" ), 21, "12345" , 0, S("can't happen" )); |
| 355 | test(S("abcdefghijklmnopqrst" ), 21, "12345" , 1, S("can't happen" )); |
| 356 | test(S("abcdefghijklmnopqrst" ), 21, "12345" , 2, S("can't happen" )); |
| 357 | test(S("abcdefghijklmnopqrst" ), 21, "12345" , 4, S("can't happen" )); |
| 358 | test(S("abcdefghijklmnopqrst" ), 21, "12345" , 5, S("can't happen" )); |
| 359 | test(S("abcdefghijklmnopqrst" ), 21, "1234567890" , 0, S("can't happen" )); |
| 360 | test(S("abcdefghijklmnopqrst" ), 21, "1234567890" , 1, S("can't happen" )); |
| 361 | test(S("abcdefghijklmnopqrst" ), 21, "1234567890" , 5, S("can't happen" )); |
| 362 | test(S("abcdefghijklmnopqrst" ), 21, "1234567890" , 9, S("can't happen" )); |
| 363 | test(S("abcdefghijklmnopqrst" ), 21, "1234567890" , 10, S("can't happen" )); |
| 364 | test(S("abcdefghijklmnopqrst" ), 21, "12345678901234567890" , 0, S("can't happen" )); |
| 365 | test(S("abcdefghijklmnopqrst" ), 21, "12345678901234567890" , 1, S("can't happen" )); |
| 366 | test(S("abcdefghijklmnopqrst" ), 21, "12345678901234567890" , 10, S("can't happen" )); |
| 367 | test(S("abcdefghijklmnopqrst" ), 21, "12345678901234567890" , 19, S("can't happen" )); |
| 368 | test(S("abcdefghijklmnopqrst" ), 21, "12345678901234567890" , 20, S("can't happen" )); |
| 369 | } |
| 370 | |
| 371 | { // test inserting into self |
| 372 | S s_short = "123/" ; |
| 373 | S s_long = "Lorem ipsum dolor sit amet, consectetur/" ; |
| 374 | |
| 375 | s_short.insert(0, s_short.data(), s_short.size()); |
| 376 | assert(s_short == "123/123/" ); |
| 377 | s_short.insert(0, s_short.data(), s_short.size()); |
| 378 | assert(s_short == "123/123/123/123/" ); |
| 379 | s_short.insert(0, s_short.data(), s_short.size()); |
| 380 | assert(s_short == "123/123/123/123/123/123/123/123/" ); |
| 381 | |
| 382 | s_long.insert(0, s_long.data(), s_long.size()); |
| 383 | assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/" ); |
| 384 | } |
| 385 | |
| 386 | return true; |
| 387 | } |
| 388 | |
| 389 | int main(int, char**) { |
| 390 | test<std::string>(); |
| 391 | #if TEST_STD_VER >= 11 |
| 392 | test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>(); |
| 393 | test<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>(); |
| 394 | #endif |
| 395 | |
| 396 | #if TEST_STD_VER > 17 |
| 397 | static_assert(test<std::string>()); |
| 398 | static_assert(test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>()); |
| 399 | #endif |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |