| 2190 | } |
| 2191 | |
| 2192 | void |
| 2193 | testReplace() |
| 2194 | { |
| 2195 | test_vectors const t; |
| 2196 | |
| 2197 | // replace(std::size_t, std::size_t, string_view) |
| 2198 | { |
| 2199 | // pos out of range |
| 2200 | fail_loop([&](storage_ptr const& sp) |
| 2201 | { |
| 2202 | string s(t.v2, sp); |
| 2203 | BOOST_TEST_THROWS_WITH_LOCATION( |
| 2204 | s.replace(s.size() + 1, 1, t.v2)); |
| 2205 | }); |
| 2206 | |
| 2207 | // outside, shrink |
| 2208 | fail_loop([&](storage_ptr const& sp) |
| 2209 | { |
| 2210 | std::string s1(t.v2.data(), t.v2.size()); |
| 2211 | string s2(t.v2, sp); |
| 2212 | BOOST_TEST(s2.replace(0, 4, t.v2.substr(4, 2)) == |
| 2213 | s1.replace(0, 4, t.v2.data() + 4, 2)); |
| 2214 | }); |
| 2215 | |
| 2216 | // outside, grow |
| 2217 | fail_loop([&](storage_ptr const& sp) |
| 2218 | { |
| 2219 | std::string s1(t.v2.data(), t.v2.size()); |
| 2220 | string s2(t.v2, sp); |
| 2221 | BOOST_TEST(s2.replace(0, 1, t.v2.substr(0)) == |
| 2222 | s1.replace(0, 1, t.v2.data(), t.v2.size())); |
| 2223 | }); |
| 2224 | |
| 2225 | // outside, grow, reallocate |
| 2226 | fail_loop([&](storage_ptr const& sp) |
| 2227 | { |
| 2228 | std::string s1(t.v2.data(), t.v2.size()); |
| 2229 | string s2(t.v2, sp); |
| 2230 | s1.append(s1); |
| 2231 | s2.append(s2); |
| 2232 | BOOST_TEST(s2.replace(0, 1, t.v2.substr(0)) == |
| 2233 | s1.replace(0, 1, t.v2.data(), t.v2.size())); |
| 2234 | }); |
| 2235 | |
| 2236 | // outside, same |
| 2237 | fail_loop([&](storage_ptr const& sp) |
| 2238 | { |
| 2239 | std::string s1(t.v2.data(), t.v2.size()); |
| 2240 | string s2(t.v2, sp); |
| 2241 | BOOST_TEST(s2.replace(0, 2, t.v2.substr(0, 2)) == |
| 2242 | s1.replace(0, 2, t.v2.data(), 2)); |
| 2243 | }); |
| 2244 | |
| 2245 | // replace tests for full coverage |
| 2246 | |
| 2247 | // inside, no effect |
| 2248 | fail_loop([&](storage_ptr const& sp) |
| 2249 | { |