summaryrefslogtreecommitdiff
path: root/test/std/strings/basic.string
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:08 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:08 +0000
commit0564cdb94a7a1facbb0dbf888ceb90638aa70ecd (patch)
tree3ccbf1ba827928fca93419d0b6cf83ce0f650f2a /test/std/strings/basic.string
parentdbabdb5220c44e5938d404eefb84b5ed55667ea8 (diff)
Notes
Diffstat (limited to 'test/std/strings/basic.string')
-rw-r--r--test/std/strings/basic.string/string.access/at.pass.cpp4
-rw-r--r--test/std/strings/basic.string/string.capacity/empty.fail.cpp28
-rw-r--r--test/std/strings/basic.string/string.capacity/empty.pass.cpp4
-rw-r--r--test/std/strings/basic.string/string.cons/alloc.pass.cpp16
-rw-r--r--test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp26
-rw-r--r--test/std/strings/basic.string/string.cons/move_alloc.pass.cpp12
-rw-r--r--test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp6
-rw-r--r--test/std/strings/basic.string/string.cons/string_view.fail.cpp4
-rw-r--r--test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp74
-rw-r--r--test/std/strings/basic.string/string.ends_with/ends_with.char.pass.cpp34
-rw-r--r--test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp63
-rw-r--r--test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp72
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp52
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp24
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp24
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp16
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp46
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp20
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp24
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp38
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp24
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp24
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp239
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp60
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp24
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp24
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string_view.pass.cpp286
-rw-r--r--test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp384
-rw-r--r--test/std/strings/basic.string/string.nonmembers/string.special/swap_noexcept.pass.cpp2
-rw-r--r--test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp4
-rw-r--r--test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp2
-rw-r--r--test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp2
-rw-r--r--test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp2
-rw-r--r--test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp4
-rw-r--r--test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp2
-rw-r--r--test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp4
-rw-r--r--test/std/strings/basic.string/string.starts_with/starts_with.char.pass.cpp34
-rw-r--r--test/std/strings/basic.string/string.starts_with/starts_with.ptr.pass.cpp62
-rw-r--r--test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp72
39 files changed, 1604 insertions, 238 deletions
diff --git a/test/std/strings/basic.string/string.access/at.pass.cpp b/test/std/strings/basic.string/string.access/at.pass.cpp
index 891648930e3c..16121cbf6bbf 100644
--- a/test/std/strings/basic.string/string.access/at.pass.cpp
+++ b/test/std/strings/basic.string/string.access/at.pass.cpp
@@ -35,7 +35,7 @@ test(S s, typename S::size_type pos)
{
try
{
- s.at(pos);
+ TEST_IGNORE_NODISCARD s.at(pos);
assert(false);
}
catch (std::out_of_range&)
@@ -44,7 +44,7 @@ test(S s, typename S::size_type pos)
}
try
{
- cs.at(pos);
+ TEST_IGNORE_NODISCARD cs.at(pos);
assert(false);
}
catch (std::out_of_range&)
diff --git a/test/std/strings/basic.string/string.capacity/empty.fail.cpp b/test/std/strings/basic.string/string.capacity/empty.fail.cpp
new file mode 100644
index 000000000000..addb02ed3cbc
--- /dev/null
+++ b/test/std/strings/basic.string/string.capacity/empty.fail.cpp
@@ -0,0 +1,28 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// class deque
+
+// bool empty() const noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
+
+#include <string>
+
+#include "test_macros.h"
+
+int main ()
+{
+ std::string c;
+ c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+}
diff --git a/test/std/strings/basic.string/string.capacity/empty.pass.cpp b/test/std/strings/basic.string/string.capacity/empty.pass.cpp
index fbed5c36c3f4..a61a410a444a 100644
--- a/test/std/strings/basic.string/string.capacity/empty.pass.cpp
+++ b/test/std/strings/basic.string/string.capacity/empty.pass.cpp
@@ -9,17 +9,19 @@
// <string>
-// bool empty() const;
+// bool empty() const noexcept;
#include <string>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
template <class S>
void
test(const S& s)
{
+ ASSERT_NOEXCEPT(s.empty());
assert(s.empty() == (s.size() == 0));
}
diff --git a/test/std/strings/basic.string/string.cons/alloc.pass.cpp b/test/std/strings/basic.string/string.cons/alloc.pass.cpp
index 81537ba52bb6..9e3fb0722604 100644
--- a/test/std/strings/basic.string/string.cons/alloc.pass.cpp
+++ b/test/std/strings/basic.string/string.cons/alloc.pass.cpp
@@ -24,9 +24,9 @@ test()
{
{
#if TEST_STD_VER > 14
- static_assert((noexcept(S{})), "" );
+ static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
- static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
+ static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
#endif
S s;
LIBCPP_ASSERT(s.__invariants());
@@ -37,9 +37,9 @@ test()
}
{
#if TEST_STD_VER > 14
- static_assert((noexcept(S{typename S::allocator_type{}})), "" );
+ static_assert((noexcept(S{typename S::allocator_type{}})), "" );
#elif TEST_STD_VER >= 11
- static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
+ static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
#endif
S s(typename S::allocator_type(5));
LIBCPP_ASSERT(s.__invariants());
@@ -58,9 +58,9 @@ test2()
{
{
#if TEST_STD_VER > 14
- static_assert((noexcept(S{})), "" );
+ static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
- static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
+ static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
#endif
S s;
LIBCPP_ASSERT(s.__invariants());
@@ -71,9 +71,9 @@ test2()
}
{
#if TEST_STD_VER > 14
- static_assert((noexcept(S{typename S::allocator_type{}})), "" );
+ static_assert((noexcept(S{typename S::allocator_type{}})), "" );
#elif TEST_STD_VER >= 11
- static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
+ static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
#endif
S s(typename S::allocator_type{});
LIBCPP_ASSERT(s.__invariants());
diff --git a/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp b/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
index 982bb43289d7..edd5c6e32d56 100644
--- a/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
+++ b/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
@@ -69,9 +69,9 @@ bool operator!=(const poca_alloc<T>& lhs, const poca_alloc<U>& rhs)
template <class S>
void test_assign(S &s1, const S& s2)
{
- try { s1 = s2; }
- catch ( std::bad_alloc &) { return; }
- assert(false);
+ try { s1 = s2; }
+ catch ( std::bad_alloc &) { return; }
+ assert(false);
}
#endif
@@ -110,21 +110,21 @@ int main()
{
typedef poca_alloc<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
- const char * p1 = "This is my first string";
- const char * p2 = "This is my second string";
+ const char * p1 = "This is my first string";
+ const char * p2 = "This is my second string";
alloc_imp<char> imp1;
alloc_imp<char> imp2;
- S s1(p1, A(&imp1));
- S s2(p2, A(&imp2));
+ S s1(p1, A(&imp1));
+ S s2(p2, A(&imp2));
- assert(s1 == p1);
- assert(s2 == p2);
+ assert(s1 == p1);
+ assert(s2 == p2);
- imp2.deactivate();
- test_assign(s1, s2);
- assert(s1 == p1);
- assert(s2 == p2);
+ imp2.deactivate();
+ test_assign(s1, s2);
+ assert(s1 == p1);
+ assert(s2 == p2);
}
#endif
#endif
diff --git a/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp b/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
index d4866921af7a..bb7bdcd1434f 100644
--- a/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
+++ b/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
@@ -41,9 +41,9 @@ int main()
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
#if TEST_STD_VER > 14
- static_assert((noexcept(S{})), "" );
+ static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
- static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
+ static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
#endif
test(S(), A(3));
test(S("1"), A(5));
@@ -55,9 +55,9 @@ int main()
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
#if TEST_STD_VER > 14
- static_assert((noexcept(S{})), "" );
+ static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
- static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
+ static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
#endif
S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
S s2 (std::move(s1), A(1));
@@ -67,9 +67,9 @@ int main()
typedef min_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
#if TEST_STD_VER > 14
- static_assert((noexcept(S{})), "" );
+ static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
- static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
+ static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
#endif
test(S(), A());
test(S("1"), A());
diff --git a/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp b/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp
index 136a60fe627b..0720543420a8 100644
--- a/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp
+++ b/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp
@@ -16,7 +16,7 @@
// allocator_traits<allocator_type>::propagate_on_container_move_assignment::value ||
// allocator_traits<allocator_type>::is_always_equal::value); // C++17
//
-// before C++17, we use the conforming extension
+// before C++17, we use the conforming extension
// noexcept(
// allocator_type::propagate_on_container_move_assignment::value &&
// is_nothrow_move_assignable<allocator_type>::value);
@@ -81,12 +81,12 @@ int main()
}
#if TEST_STD_VER > 14
{
- // POCMA is false, always equal
+ // POCMA is false, always equal
typedef std::basic_string<char, std::char_traits<char>, some_alloc2<char>> C;
static_assert( std::is_nothrow_move_assignable<C>::value, "");
}
{
- // POCMA is false, not always equal
+ // POCMA is false, not always equal
typedef std::basic_string<char, std::char_traits<char>, some_alloc3<char>> C;
static_assert(!std::is_nothrow_move_assignable<C>::value, "");
}
diff --git a/test/std/strings/basic.string/string.cons/string_view.fail.cpp b/test/std/strings/basic.string/string.cons/string_view.fail.cpp
index 70459b2dcfb4..3d3bf4178fd2 100644
--- a/test/std/strings/basic.string/string.cons/string_view.fail.cpp
+++ b/test/std/strings/basic.string/string.cons/string_view.fail.cpp
@@ -18,6 +18,6 @@ void foo ( const string &s ) {}
int main()
{
- std::string_view sv = "ABCDE";
- foo(sv); // requires implicit conversion from string_view to string
+ std::string_view sv = "ABCDE";
+ foo(sv); // requires implicit conversion from string_view to string
}
diff --git a/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp b/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
new file mode 100644
index 000000000000..1d400b79b1c8
--- /dev/null
+++ b/test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& operator=(basic_string_view<charT, traits> sv);
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+#include "min_allocator.h"
+
+template <class S, class SV>
+void
+test(S s1, SV sv)
+{
+ typedef typename S::traits_type T;
+ s1 = sv;
+ LIBCPP_ASSERT(s1.__invariants());
+ assert(s1.size() == sv.size());
+ assert(T::compare(s1.data(), sv.data(), s1.size()) == 0);
+ assert(s1.capacity() >= s1.size());
+}
+
+int main()
+{
+ {
+ typedef std::string S;
+ typedef std::string_view SV;
+ test(S(), SV(""));
+ test(S("1"), SV(""));
+ test(S(), SV("1"));
+ test(S("1"), SV("2"));
+ test(S("1"), SV("2"));
+
+ test(S(),
+ SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+ test(S("123456789"),
+ SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+ test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+ SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+ test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890123456789012345678901234567890"),
+ SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+ typedef std::string_view SV;
+ test(S(), SV(""));
+ test(S("1"), SV(""));
+ test(S(), SV("1"));
+ test(S("1"), SV("2"));
+ test(S("1"), SV("2"));
+
+ test(S(),
+ SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+ test(S("123456789"),
+ SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+ test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+ SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+ test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890123456789012345678901234567890"),
+ SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+ }
+#endif
+}
diff --git a/test/std/strings/basic.string/string.ends_with/ends_with.char.pass.cpp b/test/std/strings/basic.string/string.ends_with/ends_with.char.pass.cpp
new file mode 100644
index 000000000000..6091e0c066d3
--- /dev/null
+++ b/test/std/strings/basic.string/string.ends_with/ends_with.char.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// <string>
+
+// bool ends_with(charT x) const noexcept;
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ {
+ typedef std::string S;
+ S s1 {};
+ S s2 { "abcde", 5 };
+
+ ASSERT_NOEXCEPT(s1.ends_with('e'));
+
+ assert (!s1.ends_with('e'));
+ assert (!s1.ends_with('x'));
+ assert ( s2.ends_with('e'));
+ assert (!s2.ends_with('x'));
+ }
+}
diff --git a/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp b/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp
new file mode 100644
index 000000000000..b1f5fcd50cf3
--- /dev/null
+++ b/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// <string>
+
+// bool ends_with(const CharT *x) const;
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ {
+ typedef std::string S;
+ const char *s = "abcde";
+
+ S s0;
+ S s1 { s + 4, 1 };
+ S s2 { s + 3, 2 };
+// S s3 { s + 2, 3 };
+// S s4 { s + 1, 4 };
+// S s5 { s, 5 };
+ S sNot { "def", 3 };
+
+ LIBCPP_ASSERT_NOEXCEPT(s0.ends_with(""));
+
+ assert ( s0.ends_with(""));
+ assert (!s0.ends_with("e"));
+
+ assert ( s1.ends_with(""));
+ assert ( s1.ends_with("e"));
+ assert (!s1.ends_with("de"));
+ assert (!s1.ends_with("cde"));
+ assert (!s1.ends_with("bcde"));
+ assert (!s1.ends_with("abcde"));
+ assert (!s1.ends_with("def"));
+
+ assert ( s2.ends_with(""));
+ assert ( s2.ends_with("e"));
+ assert ( s2.ends_with("de"));
+ assert (!s2.ends_with("cde"));
+ assert (!s2.ends_with("bcde"));
+ assert (!s2.ends_with("abcde"));
+ assert (!s2.ends_with("def"));
+
+ assert ( sNot.ends_with(""));
+ assert (!sNot.ends_with("e"));
+ assert (!sNot.ends_with("de"));
+ assert (!sNot.ends_with("cde"));
+ assert (!sNot.ends_with("bcde"));
+ assert (!sNot.ends_with("abcde"));
+ assert ( sNot.ends_with("def"));
+ }
+}
diff --git a/test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp b/test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp
new file mode 100644
index 000000000000..4bbd4bc864b2
--- /dev/null
+++ b/test/std/strings/basic.string/string.ends_with/ends_with.string_view.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// <string>
+
+// bool ends_with(basic_string_view x) const noexcept;
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ {
+ typedef std::string S;
+ typedef std::string_view SV;
+ const char *s = "abcde";
+
+ S s0;
+ S s1 { s + 4, 1 };
+ S s2 { s + 3, 2 };
+// S s3 { s + 2, 3 };
+// S s4 { s + 1, 4 };
+// S s5 { s, 5 };
+ S sNot { "def", 3 };
+
+ SV sv0;
+ SV sv1 { s + 4, 1 };
+ SV sv2 { s + 3, 2 };
+ SV sv3 { s + 2, 3 };
+ SV sv4 { s + 1, 4 };
+ SV sv5 { s , 5 };
+ SV svNot {"def", 3 };
+
+ ASSERT_NOEXCEPT(s0.ends_with(sv0));
+
+ assert ( s0.ends_with(sv0));
+ assert (!s0.ends_with(sv1));
+
+ assert ( s1.ends_with(sv0));
+ assert ( s1.ends_with(sv1));
+ assert (!s1.ends_with(sv2));
+ assert (!s1.ends_with(sv3));
+ assert (!s1.ends_with(sv4));
+ assert (!s1.ends_with(sv5));
+ assert (!s1.ends_with(svNot));
+
+ assert ( s2.ends_with(sv0));
+ assert ( s2.ends_with(sv1));
+ assert ( s2.ends_with(sv2));
+ assert (!s2.ends_with(sv3));
+ assert (!s2.ends_with(sv4));
+ assert (!s2.ends_with(sv5));
+ assert (!s2.ends_with(svNot));
+
+ assert ( sNot.ends_with(sv0));
+ assert (!sNot.ends_with(sv1));
+ assert (!sNot.ends_with(sv2));
+ assert (!sNot.ends_with(sv3));
+ assert (!sNot.ends_with(sv4));
+ assert (!sNot.ends_with(sv5));
+ assert ( sNot.ends_with(svNot));
+ }
+}
diff --git a/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
index b464291d4c5d..7ed55403927e 100644
--- a/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
@@ -32,11 +32,11 @@ template <class S, class It>
void
test_exceptions(S s, It first, It last)
{
- S aCopy = s;
+ S aCopy = s;
try {
- s.append(first, last);
- assert(false);
- }
+ s.append(first, last);
+ assert(false);
+ }
catch (...) {}
LIBCPP_ASSERT(s.__invariants());
assert(s == aCopy);
@@ -164,7 +164,7 @@ int main()
}
#endif
#ifndef TEST_HAS_NO_EXCEPTIONS
- { // test iterator operations that throw
+ { // test iterator operations that throw
typedef std::string S;
typedef ThrowingIterator<char> TIter;
typedef input_iterator<TIter> IIter;
@@ -176,33 +176,33 @@ int main()
test_exceptions(S(), TIter(s, s+10, 4, TIter::TAIncrement), TIter());
test_exceptions(S(), TIter(s, s+10, 5, TIter::TADereference), TIter());
test_exceptions(S(), TIter(s, s+10, 6, TIter::TAComparison), TIter());
- }
+ }
#endif
- { // test appending to self
+ { // test appending to self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
-
- s_short.append(s_short.begin(), s_short.end());
- assert(s_short == "123/123/");
- s_short.append(s_short.begin(), s_short.end());
- assert(s_short == "123/123/123/123/");
- s_short.append(s_short.begin(), s_short.end());
- assert(s_short == "123/123/123/123/123/123/123/123/");
-
- s_long.append(s_long.begin(), s_long.end());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+
+ s_short.append(s_short.begin(), s_short.end());
+ assert(s_short == "123/123/");
+ s_short.append(s_short.begin(), s_short.end());
+ assert(s_short == "123/123/123/123/");
+ s_short.append(s_short.begin(), s_short.end());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
+
+ s_long.append(s_long.begin(), s_long.end());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
- { // test appending a different type
+ { // test appending a different type
typedef std::string S;
- const uint8_t p[] = "ABCD";
+ const uint8_t p[] = "ABCD";
- S s;
- s.append(p, p + 4);
- assert(s == "ABCD");
- }
+ S s;
+ s.append(p, p + 4);
+ assert(s == "ABCD");
+ }
{ // test with a move iterator that returns char&&
typedef forward_iterator<const char*> It;
diff --git a/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
index eb552ca83928..823905df4a14 100644
--- a/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
@@ -62,19 +62,19 @@ int main()
}
#endif
- { // test appending to self
+ { // test appending to self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.append(s_short.c_str());
- assert(s_short == "123/123/");
- s_short.append(s_short.c_str());
- assert(s_short == "123/123/123/123/");
- s_short.append(s_short.c_str());
- assert(s_short == "123/123/123/123/123/123/123/123/");
+ s_short.append(s_short.c_str());
+ assert(s_short == "123/123/");
+ s_short.append(s_short.c_str());
+ assert(s_short == "123/123/123/123/");
+ s_short.append(s_short.c_str());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
- s_long.append(s_long.c_str());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ s_long.append(s_long.c_str());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
index fc80d7cccce6..f09ec682e9f9 100644
--- a/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
@@ -71,19 +71,19 @@ int main()
}
#endif
- { // test appending to self
+ { // test appending to self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.append(s_short.data(), s_short.size());
- assert(s_short == "123/123/");
- s_short.append(s_short.data(), s_short.size());
- assert(s_short == "123/123/123/123/");
- s_short.append(s_short.data(), s_short.size());
- assert(s_short == "123/123/123/123/123/123/123/123/");
+ s_short.append(s_short.data(), s_short.size());
+ assert(s_short == "123/123/");
+ s_short.append(s_short.data(), s_short.size());
+ assert(s_short == "123/123/123/123/");
+ s_short.append(s_short.data(), s_short.size());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
- s_long.append(s_long.data(), s_long.size());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ s_long.append(s_long.data(), s_long.size());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
index f2fb8782a21d..5ca5aaf8629c 100644
--- a/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
@@ -17,6 +17,12 @@
#include "test_macros.h"
#include "min_allocator.h"
+struct veryLarge
+{
+ long long a;
+ char b;
+};
+
template <class S>
void
test(S s, typename S::value_type c, S expected)
@@ -42,4 +48,14 @@ int main()
test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
}
#endif
+#if 0
+ {
+// https://bugs.llvm.org/show_bug.cgi?id=31454
+ std::basic_string<veryLarge> s;
+ veryLarge vl;
+ s.push_back(vl);
+ s.push_back(vl);
+ s.push_back(vl);
+ }
+#endif
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
index e5312e6db6ce..cb83f25d7117 100644
--- a/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
@@ -33,10 +33,10 @@ template <class S, class It>
void
test_exceptions(S s, It first, It last)
{
- S aCopy = s;
+ S aCopy = s;
try {
- s.assign(first, last);
- assert(false);
+ s.assign(first, last);
+ assert(false);
}
catch (...) {}
LIBCPP_ASSERT(s.__invariants());
@@ -165,7 +165,7 @@ int main()
}
#endif
#ifndef TEST_HAS_NO_EXCEPTIONS
- { // test iterator operations that throw
+ { // test iterator operations that throw
typedef std::string S;
typedef ThrowingIterator<char> TIter;
typedef input_iterator<TIter> IIter;
@@ -177,32 +177,32 @@ int main()
test_exceptions(S(), TIter(s, s+10, 4, TIter::TAIncrement), TIter());
test_exceptions(S(), TIter(s, s+10, 5, TIter::TADereference), TIter());
test_exceptions(S(), TIter(s, s+10, 6, TIter::TAComparison), TIter());
- }
+ }
#endif
- { // test assigning to self
+ { // test assigning to self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.assign(s_short.begin(), s_short.end());
- assert(s_short == "123/");
- s_short.assign(s_short.begin() + 2, s_short.end());
- assert(s_short == "3/");
+ s_short.assign(s_short.begin(), s_short.end());
+ assert(s_short == "123/");
+ s_short.assign(s_short.begin() + 2, s_short.end());
+ assert(s_short == "3/");
- s_long.assign(s_long.begin(), s_long.end());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/");
+ s_long.assign(s_long.begin(), s_long.end());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/");
- s_long.assign(s_long.begin() + 30, s_long.end());
- assert(s_long == "nsectetur/");
- }
+ s_long.assign(s_long.begin() + 30, s_long.end());
+ assert(s_long == "nsectetur/");
+ }
- { // test assigning a different type
+ { // test assigning a different type
typedef std::string S;
- const uint8_t p[] = "ABCD";
+ const uint8_t p[] = "ABCD";
- S s;
- s.assign(p, p + 4);
- assert(s == "ABCD");
- }
+ S s;
+ s.assign(p, p + 4);
+ assert(s == "ABCD");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
index b0876b388d83..b592455a350e 100644
--- a/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
@@ -62,17 +62,17 @@ int main()
}
#endif
- { // test assignment to self
+ { // test assignment to self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.assign(s_short.c_str());
- assert(s_short == "123/");
- s_short.assign(s_short.c_str() + 2);
- assert(s_short == "3/");
+ s_short.assign(s_short.c_str());
+ assert(s_short == "123/");
+ s_short.assign(s_short.c_str() + 2);
+ assert(s_short == "3/");
- s_long.assign(s_long.c_str() + 30);
- assert(s_long == "nsectetur/");
- }
+ s_long.assign(s_long.c_str() + 30);
+ assert(s_long == "nsectetur/");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
index 97a9990f5180..70b00619a913 100644
--- a/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
@@ -70,20 +70,20 @@ int main()
S("12345678901234567890"));
}
#endif
- { // test assign to self
+ { // test assign to self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.assign(s_short.data(), s_short.size());
- assert(s_short == "123/");
- s_short.assign(s_short.data() + 2, s_short.size() - 2);
- assert(s_short == "3/");
+ s_short.assign(s_short.data(), s_short.size());
+ assert(s_short == "123/");
+ s_short.assign(s_short.data() + 2, s_short.size() - 2);
+ assert(s_short == "3/");
- s_long.assign(s_long.data(), s_long.size());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/");
+ s_long.assign(s_long.data(), s_long.size());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/");
- s_long.assign(s_long.data() + 2, 8 );
- assert(s_long == "rem ipsu");
- }
+ s_long.assign(s_long.data() + 2, 8 );
+ assert(s_long == "rem ipsu");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
index 2c8b6e4a1882..cb4b40f9e8cf 100644
--- a/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
@@ -39,7 +39,7 @@ void
test_exceptions(S s, typename S::difference_type pos, It first, It last)
{
typename S::const_iterator p = s.cbegin() + pos;
- S aCopy = s;
+ S aCopy = s;
try {
s.insert(p, first, last);
assert(false);
@@ -145,7 +145,7 @@ int main()
}
#endif
#ifndef TEST_HAS_NO_EXCEPTIONS
- { // test iterator operations that throw
+ { // test iterator operations that throw
typedef std::string S;
typedef ThrowingIterator<char> TIter;
typedef input_iterator<TIter> IIter;
@@ -157,7 +157,7 @@ int main()
test_exceptions(S(), 0, TIter(s, s+10, 4, TIter::TAIncrement), TIter());
test_exceptions(S(), 0, TIter(s, s+10, 5, TIter::TADereference), TIter());
test_exceptions(S(), 0, TIter(s, s+10, 6, TIter::TAComparison), TIter());
- }
+ }
#endif
#if _LIBCPP_DEBUG >= 1
{
@@ -170,30 +170,30 @@ int main()
}
#endif
- { // test inserting into self
+ { // test inserting into self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
-
- s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
- assert(s_short == "123/123/");
- s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
- assert(s_short == "123/123/123/123/");
- s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
- assert(s_short == "123/123/123/123/123/123/123/123/");
-
- s_long.insert(s_long.begin(), s_long.begin(), s_long.end());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+
+ s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
+ assert(s_short == "123/123/");
+ s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
+ assert(s_short == "123/123/123/123/");
+ s_short.insert(s_short.begin(), s_short.begin(), s_short.end());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
+
+ s_long.insert(s_long.begin(), s_long.begin(), s_long.end());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
- { // test assigning a different type
+ { // test assigning a different type
typedef std::string S;
const uint8_t p[] = "ABCD";
S s;
s.insert(s.begin(), p, p + 4);
assert(s == "ABCD");
- }
+ }
{ // test with a move iterator that returns char&&
typedef input_iterator<const char*> It;
diff --git a/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
index e49f57a7f9ad..b4505a4c1f3e 100644
--- a/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
@@ -219,19 +219,19 @@ int main()
}
#endif
- { // test inserting into self
+ { // test inserting into self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.insert(0, s_short.c_str());
- assert(s_short == "123/123/");
- s_short.insert(0, s_short.c_str());
- assert(s_short == "123/123/123/123/");
- s_short.insert(0, s_short.c_str());
- assert(s_short == "123/123/123/123/123/123/123/123/");
+ s_short.insert(0, s_short.c_str());
+ assert(s_short == "123/123/");
+ s_short.insert(0, s_short.c_str());
+ assert(s_short == "123/123/123/123/");
+ s_short.insert(0, s_short.c_str());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
- s_long.insert(0, s_long.c_str());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ s_long.insert(0, s_long.c_str());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
index a42a60ddcdb4..ee5991c15966 100644
--- a/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
@@ -700,19 +700,19 @@ int main()
}
#endif
- { // test inserting into self
+ { // test inserting into self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.insert(0, s_short.data(), s_short.size());
- assert(s_short == "123/123/");
- s_short.insert(0, s_short.data(), s_short.size());
- assert(s_short == "123/123/123/123/");
- s_short.insert(0, s_short.data(), s_short.size());
- assert(s_short == "123/123/123/123/123/123/123/123/");
+ s_short.insert(0, s_short.data(), s_short.size());
+ assert(s_short == "123/123/");
+ s_short.insert(0, s_short.data(), s_short.size());
+ assert(s_short == "123/123/123/123/");
+ s_short.insert(0, s_short.data(), s_short.size());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
- s_long.insert(0, s_long.data(), s_long.size());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ s_long.insert(0, s_long.data(), s_long.size());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp
new file mode 100644
index 000000000000..970cbcb1756c
--- /dev/null
+++ b/test/std/strings/basic.string/string.modifiers/string_insert/string_view.pass.cpp
@@ -0,0 +1,239 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>&
+// insert(size_type pos, string_view sv);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "test_macros.h"
+#include "min_allocator.h"
+
+template <class S, class SV>
+void
+test(S s, typename S::size_type pos, SV sv, S expected)
+{
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos <= old_size)
+ {
+ s.insert(pos, sv);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
+ {
+ try
+ {
+ s.insert(pos, sv);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos > old_size);
+ assert(s == s0);
+ }
+ }
+#endif
+}
+
+int main()
+{
+ {
+ typedef std::string S;
+ typedef std::string_view SV;
+ test(S(""), 0, SV(""), S(""));
+ test(S(""), 0, SV("12345"), S("12345"));
+ test(S(""), 0, SV("1234567890"), S("1234567890"));
+ test(S(""), 0, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S(""), 1, SV(""), S("can't happen"));
+ test(S(""), 1, SV("12345"), S("can't happen"));
+ test(S(""), 1, SV("1234567890"), S("can't happen"));
+ test(S(""), 1, SV("12345678901234567890"), S("can't happen"));
+ test(S("abcde"), 0, SV(""), S("abcde"));
+ test(S("abcde"), 0, SV("12345"), S("12345abcde"));
+ test(S("abcde"), 0, SV("1234567890"), S("1234567890abcde"));
+ test(S("abcde"), 0, SV("12345678901234567890"), S("12345678901234567890abcde"));
+ test(S("abcde"), 1, SV(""), S("abcde"));
+ test(S("abcde"), 1, SV("12345"), S("a12345bcde"));
+ test(S("abcde"), 1, SV("1234567890"), S("a1234567890bcde"));
+ test(S("abcde"), 1, SV("12345678901234567890"), S("a12345678901234567890bcde"));
+ test(S("abcde"), 2, SV(""), S("abcde"));
+ test(S("abcde"), 2, SV("12345"), S("ab12345cde"));
+ test(S("abcde"), 2, SV("1234567890"), S("ab1234567890cde"));
+ test(S("abcde"), 2, SV("12345678901234567890"), S("ab12345678901234567890cde"));
+ test(S("abcde"), 4, SV(""), S("abcde"));
+ test(S("abcde"), 4, SV("12345"), S("abcd12345e"));
+ test(S("abcde"), 4, SV("1234567890"), S("abcd1234567890e"));
+ test(S("abcde"), 4, SV("12345678901234567890"), S("abcd12345678901234567890e"));
+ test(S("abcde"), 5, SV(""), S("abcde"));
+ test(S("abcde"), 5, SV("12345"), S("abcde12345"));
+ test(S("abcde"), 5, SV("1234567890"), S("abcde1234567890"));
+ test(S("abcde"), 5, SV("12345678901234567890"), S("abcde12345678901234567890"));
+ test(S("abcde"), 6, SV(""), S("can't happen"));
+ test(S("abcde"), 6, SV("12345"), S("can't happen"));
+ test(S("abcde"), 6, SV("1234567890"), S("can't happen"));
+ test(S("abcde"), 6, SV("12345678901234567890"), S("can't happen"));
+ test(S("abcdefghij"), 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 0, SV("12345"), S("12345abcdefghij"));
+ test(S("abcdefghij"), 0, SV("1234567890"), S("1234567890abcdefghij"));
+ test(S("abcdefghij"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghij"));
+ test(S("abcdefghij"), 1, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 1, SV("12345"), S("a12345bcdefghij"));
+ test(S("abcdefghij"), 1, SV("1234567890"), S("a1234567890bcdefghij"));
+ test(S("abcdefghij"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+ test(S("abcdefghij"), 5, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 5, SV("12345"), S("abcde12345fghij"));
+ test(S("abcdefghij"), 5, SV("1234567890"), S("abcde1234567890fghij"));
+ test(S("abcdefghij"), 5, SV("12345678901234567890"), S("abcde12345678901234567890fghij"));
+ test(S("abcdefghij"), 9, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 9, SV("12345"), S("abcdefghi12345j"));
+ test(S("abcdefghij"), 9, SV("1234567890"), S("abcdefghi1234567890j"));
+ test(S("abcdefghij"), 9, SV("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+ test(S("abcdefghij"), 10, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 10, SV("12345"), S("abcdefghij12345"));
+ test(S("abcdefghij"), 10, SV("1234567890"), S("abcdefghij1234567890"));
+ test(S("abcdefghij"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+ test(S("abcdefghij"), 11, SV(""), S("can't happen"));
+ test(S("abcdefghij"), 11, SV("12345"), S("can't happen"));
+ test(S("abcdefghij"), 11, SV("1234567890"), S("can't happen"));
+ test(S("abcdefghij"), 11, SV("12345678901234567890"), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, SV("12345"), S("12345abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, SV("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, SV("12345"), S("a12345bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, SV("12345"), S("abcdefghij12345klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, SV("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 19, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 19, SV("12345"), S("abcdefghijklmnopqrs12345t"));
+ test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 19, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 20, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 20, SV("12345"), S("abcdefghijklmnopqrst12345"));
+ test(S("abcdefghijklmnopqrst"), 20, SV("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+ test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 21, SV(""), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, SV("12345"), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), S("can't happen"));
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+ typedef std::string_view SV;
+ test(S(""), 0, SV(""), S(""));
+ test(S(""), 0, SV("12345"), S("12345"));
+ test(S(""), 0, SV("1234567890"), S("1234567890"));
+ test(S(""), 0, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S(""), 1, SV(""), S("can't happen"));
+ test(S(""), 1, SV("12345"), S("can't happen"));
+ test(S(""), 1, SV("1234567890"), S("can't happen"));
+ test(S(""), 1, SV("12345678901234567890"), S("can't happen"));
+ test(S("abcde"), 0, SV(""), S("abcde"));
+ test(S("abcde"), 0, SV("12345"), S("12345abcde"));
+ test(S("abcde"), 0, SV("1234567890"), S("1234567890abcde"));
+ test(S("abcde"), 0, SV("12345678901234567890"), S("12345678901234567890abcde"));
+ test(S("abcde"), 1, SV(""), S("abcde"));
+ test(S("abcde"), 1, SV("12345"), S("a12345bcde"));
+ test(S("abcde"), 1, SV("1234567890"), S("a1234567890bcde"));
+ test(S("abcde"), 1, SV("12345678901234567890"), S("a12345678901234567890bcde"));
+ test(S("abcde"), 2, SV(""), S("abcde"));
+ test(S("abcde"), 2, SV("12345"), S("ab12345cde"));
+ test(S("abcde"), 2, SV("1234567890"), S("ab1234567890cde"));
+ test(S("abcde"), 2, SV("12345678901234567890"), S("ab12345678901234567890cde"));
+ test(S("abcde"), 4, SV(""), S("abcde"));
+ test(S("abcde"), 4, SV("12345"), S("abcd12345e"));
+ test(S("abcde"), 4, SV("1234567890"), S("abcd1234567890e"));
+ test(S("abcde"), 4, SV("12345678901234567890"), S("abcd12345678901234567890e"));
+ test(S("abcde"), 5, SV(""), S("abcde"));
+ test(S("abcde"), 5, SV("12345"), S("abcde12345"));
+ test(S("abcde"), 5, SV("1234567890"), S("abcde1234567890"));
+ test(S("abcde"), 5, SV("12345678901234567890"), S("abcde12345678901234567890"));
+ test(S("abcde"), 6, SV(""), S("can't happen"));
+ test(S("abcde"), 6, SV("12345"), S("can't happen"));
+ test(S("abcde"), 6, SV("1234567890"), S("can't happen"));
+ test(S("abcde"), 6, SV("12345678901234567890"), S("can't happen"));
+ test(S("abcdefghij"), 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 0, SV("12345"), S("12345abcdefghij"));
+ test(S("abcdefghij"), 0, SV("1234567890"), S("1234567890abcdefghij"));
+ test(S("abcdefghij"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghij"));
+ test(S("abcdefghij"), 1, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 1, SV("12345"), S("a12345bcdefghij"));
+ test(S("abcdefghij"), 1, SV("1234567890"), S("a1234567890bcdefghij"));
+ test(S("abcdefghij"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+ test(S("abcdefghij"), 5, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 5, SV("12345"), S("abcde12345fghij"));
+ test(S("abcdefghij"), 5, SV("1234567890"), S("abcde1234567890fghij"));
+ test(S("abcdefghij"), 5, SV("12345678901234567890"), S("abcde12345678901234567890fghij"));
+ test(S("abcdefghij"), 9, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 9, SV("12345"), S("abcdefghi12345j"));
+ test(S("abcdefghij"), 9, SV("1234567890"), S("abcdefghi1234567890j"));
+ test(S("abcdefghij"), 9, SV("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+ test(S("abcdefghij"), 10, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 10, SV("12345"), S("abcdefghij12345"));
+ test(S("abcdefghij"), 10, SV("1234567890"), S("abcdefghij1234567890"));
+ test(S("abcdefghij"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+ test(S("abcdefghij"), 11, SV(""), S("can't happen"));
+ test(S("abcdefghij"), 11, SV("12345"), S("can't happen"));
+ test(S("abcdefghij"), 11, SV("1234567890"), S("can't happen"));
+ test(S("abcdefghij"), 11, SV("12345678901234567890"), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, SV("12345"), S("12345abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, SV("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, SV("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, SV("12345"), S("a12345bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, SV("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, SV("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, SV("12345"), S("abcdefghij12345klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, SV("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 19, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 19, SV("12345"), S("abcdefghijklmnopqrs12345t"));
+ test(S("abcdefghijklmnopqrst"), 19, SV("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 19, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 20, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 20, SV("12345"), S("abcdefghijklmnopqrst12345"));
+ test(S("abcdefghijklmnopqrst"), 20, SV("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+ test(S("abcdefghijklmnopqrst"), 20, SV("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 21, SV(""), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, SV("12345"), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, SV("1234567890"), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, SV("12345678901234567890"), S("can't happen"));
+ }
+#endif
+
+ { // test inserting into self
+ typedef std::string S;
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+
+ s_short.insert(0, s_short.c_str());
+ assert(s_short == "123/123/");
+ s_short.insert(0, s_short.c_str());
+ assert(s_short == "123/123/123/123/");
+ s_short.insert(0, s_short.c_str());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
+
+ s_long.insert(0, s_long.c_str());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
+}
diff --git a/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp
index e456d395220b..f8126bcaf7de 100644
--- a/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp
@@ -42,12 +42,12 @@ test_exceptions(S s, typename S::size_type pos1, typename S::size_type n1, It f,
{
typename S::const_iterator first = s.begin() + pos1;
typename S::const_iterator last = s.begin() + pos1 + n1;
- S aCopy = s;
- try {
- s.replace(first, last, f, l);
- assert(false);
- }
- catch (...) {}
+ S aCopy = s;
+ try {
+ s.replace(first, last, f, l);
+ assert(false);
+ }
+ catch (...) {}
LIBCPP_ASSERT(s.__invariants());
assert(s == aCopy);
}
@@ -993,7 +993,7 @@ int main()
}
#endif
#ifndef TEST_HAS_NO_EXCEPTIONS
- { // test iterator operations that throw
+ { // test iterator operations that throw
typedef std::string S;
typedef ThrowingIterator<char> TIter;
typedef input_iterator<TIter> IIter;
@@ -1005,36 +1005,36 @@ int main()
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, TIter(s, s+10, 4, TIter::TAIncrement), TIter());
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, TIter(s, s+10, 5, TIter::TADereference), TIter());
test_exceptions(S("abcdefghijklmnopqrst"), 10, 5, TIter(s, s+10, 6, TIter::TAComparison), TIter());
- }
+ }
#endif
- { // test replacing into self
+ { // test replacing into self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
- assert(s_short == "123/123/");
- s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
- assert(s_short == "123/123/123/123/");
- s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
- assert(s_short == "123/123/123/123/123/123/123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
+ assert(s_short == "123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
+ assert(s_short == "123/123/123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.begin(), s_short.end());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
- s_long.replace(s_long.begin(), s_long.begin(), s_long.begin(), s_long.end());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ s_long.replace(s_long.begin(), s_long.begin(), s_long.begin(), s_long.end());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
- { // test assigning a different type
+ { // test assigning a different type
typedef std::string S;
- const uint8_t pc[] = "ABCD";
- uint8_t p[] = "EFGH";
+ const uint8_t pc[] = "ABCD";
+ uint8_t p[] = "EFGH";
- S s;
- s.replace(s.begin(), s.end(), pc, pc + 4);
- assert(s == "ABCD");
+ S s;
+ s.replace(s.begin(), s.end(), pc, pc + 4);
+ assert(s == "ABCD");
- s.clear();
- s.replace(s.begin(), s.end(), p, p + 4);
- assert(s == "EFGH");
- }
+ s.clear();
+ s.replace(s.begin(), s.end(), p, p + 4);
+ assert(s == "EFGH");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp
index f642d3a4f921..a7d6a6e3ce3c 100644
--- a/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp
@@ -283,19 +283,19 @@ int main()
}
#endif
- { // test replacing into self
+ { // test replacing into self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
- assert(s_short == "123/123/");
- s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
- assert(s_short == "123/123/123/123/");
- s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
- assert(s_short == "123/123/123/123/123/123/123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
+ assert(s_short == "123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
+ assert(s_short == "123/123/123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.c_str());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
- s_long.replace(s_long.begin(), s_long.begin(), s_long.c_str());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ s_long.replace(s_long.begin(), s_long.begin(), s_long.c_str());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp
index 695036807223..6c68b156641f 100644
--- a/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp
+++ b/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp
@@ -973,19 +973,19 @@ int main()
}
#endif
- { // test replacing into self
+ { // test replacing into self
typedef std::string S;
- S s_short = "123/";
- S s_long = "Lorem ipsum dolor sit amet, consectetur/";
+ S s_short = "123/";
+ S s_long = "Lorem ipsum dolor sit amet, consectetur/";
- s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
- assert(s_short == "123/123/");
- s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
- assert(s_short == "123/123/123/123/");
- s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
- assert(s_short == "123/123/123/123/123/123/123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
+ assert(s_short == "123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
+ assert(s_short == "123/123/123/123/");
+ s_short.replace(s_short.begin(), s_short.begin(), s_short.data(), s_short.size());
+ assert(s_short == "123/123/123/123/123/123/123/123/");
- s_long.replace(s_long.begin(), s_long.begin(), s_long.data(), s_long.size());
- assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
- }
+ s_long.replace(s_long.begin(), s_long.begin(), s_long.data(), s_long.size());
+ assert(s_long == "Lorem ipsum dolor sit amet, consectetur/Lorem ipsum dolor sit amet, consectetur/");
+ }
}
diff --git a/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string_view.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string_view.pass.cpp
new file mode 100644
index 000000000000..ec81001df663
--- /dev/null
+++ b/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string_view.pass.cpp
@@ -0,0 +1,286 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>&
+// replace(const_iterator i1, const_iterator i2, basic_string_view<charT,traits> sv);
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+#include "test_macros.h"
+#include "min_allocator.h"
+
+template <class S, class SV>
+void
+test(S s, typename S::size_type pos1, typename S::size_type n1, SV sv, S expected)
+{
+ typename S::size_type old_size = s.size();
+ typename S::const_iterator first = s.begin() + pos1;
+ typename S::const_iterator last = s.begin() + pos1 + n1;
+ typename S::size_type xlen = last - first;
+ s.replace(first, last, sv);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type rlen = sv.size();
+ assert(s.size() == old_size - xlen + rlen);
+}
+
+template <class S, class SV>
+void test0()
+{
+ test(S(""), 0, 0, SV(""), S(""));
+ test(S(""), 0, 0, SV("12345"), S("12345"));
+ test(S(""), 0, 0, SV("1234567890"), S("1234567890"));
+ test(S(""), 0, 0, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcde"), 0, 0, SV(""), S("abcde"));
+ test(S("abcde"), 0, 0, SV("12345"), S("12345abcde"));
+ test(S("abcde"), 0, 0, SV("1234567890"), S("1234567890abcde"));
+ test(S("abcde"), 0, 0, SV("12345678901234567890"), S("12345678901234567890abcde"));
+ test(S("abcde"), 0, 1, SV(""), S("bcde"));
+ test(S("abcde"), 0, 1, SV("12345"), S("12345bcde"));
+ test(S("abcde"), 0, 1, SV("1234567890"), S("1234567890bcde"));
+ test(S("abcde"), 0, 1, SV("12345678901234567890"), S("12345678901234567890bcde"));
+ test(S("abcde"), 0, 2, SV(""), S("cde"));
+ test(S("abcde"), 0, 2, SV("12345"), S("12345cde"));
+ test(S("abcde"), 0, 2, SV("1234567890"), S("1234567890cde"));
+ test(S("abcde"), 0, 2, SV("12345678901234567890"), S("12345678901234567890cde"));
+ test(S("abcde"), 0, 4, SV(""), S("e"));
+ test(S("abcde"), 0, 4, SV("12345"), S("12345e"));
+ test(S("abcde"), 0, 4, SV("1234567890"), S("1234567890e"));
+ test(S("abcde"), 0, 4, SV("12345678901234567890"), S("12345678901234567890e"));
+ test(S("abcde"), 0, 5, SV(""), S(""));
+ test(S("abcde"), 0, 5, SV("12345"), S("12345"));
+ test(S("abcde"), 0, 5, SV("1234567890"), S("1234567890"));
+ test(S("abcde"), 0, 5, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcde"), 1, 0, SV(""), S("abcde"));
+ test(S("abcde"), 1, 0, SV("12345"), S("a12345bcde"));
+ test(S("abcde"), 1, 0, SV("1234567890"), S("a1234567890bcde"));
+ test(S("abcde"), 1, 0, SV("12345678901234567890"), S("a12345678901234567890bcde"));
+ test(S("abcde"), 1, 1, SV(""), S("acde"));
+ test(S("abcde"), 1, 1, SV("12345"), S("a12345cde"));
+ test(S("abcde"), 1, 1, SV("1234567890"), S("a1234567890cde"));
+ test(S("abcde"), 1, 1, SV("12345678901234567890"), S("a12345678901234567890cde"));
+ test(S("abcde"), 1, 2, SV(""), S("ade"));
+ test(S("abcde"), 1, 2, SV("12345"), S("a12345de"));
+ test(S("abcde"), 1, 2, SV("1234567890"), S("a1234567890de"));
+ test(S("abcde"), 1, 2, SV("12345678901234567890"), S("a12345678901234567890de"));
+ test(S("abcde"), 1, 3, SV(""), S("ae"));
+ test(S("abcde"), 1, 3, SV("12345"), S("a12345e"));
+ test(S("abcde"), 1, 3, SV("1234567890"), S("a1234567890e"));
+ test(S("abcde"), 1, 3, SV("12345678901234567890"), S("a12345678901234567890e"));
+ test(S("abcde"), 1, 4, SV(""), S("a"));
+ test(S("abcde"), 1, 4, SV("12345"), S("a12345"));
+ test(S("abcde"), 1, 4, SV("1234567890"), S("a1234567890"));
+ test(S("abcde"), 1, 4, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcde"), 2, 0, SV(""), S("abcde"));
+ test(S("abcde"), 2, 0, SV("12345"), S("ab12345cde"));
+ test(S("abcde"), 2, 0, SV("1234567890"), S("ab1234567890cde"));
+ test(S("abcde"), 2, 0, SV("12345678901234567890"), S("ab12345678901234567890cde"));
+ test(S("abcde"), 2, 1, SV(""), S("abde"));
+ test(S("abcde"), 2, 1, SV("12345"), S("ab12345de"));
+ test(S("abcde"), 2, 1, SV("1234567890"), S("ab1234567890de"));
+ test(S("abcde"), 2, 1, SV("12345678901234567890"), S("ab12345678901234567890de"));
+ test(S("abcde"), 2, 2, SV(""), S("abe"));
+ test(S("abcde"), 2, 2, SV("12345"), S("ab12345e"));
+ test(S("abcde"), 2, 2, SV("1234567890"), S("ab1234567890e"));
+ test(S("abcde"), 2, 2, SV("12345678901234567890"), S("ab12345678901234567890e"));
+ test(S("abcde"), 2, 3, SV(""), S("ab"));
+ test(S("abcde"), 2, 3, SV("12345"), S("ab12345"));
+ test(S("abcde"), 2, 3, SV("1234567890"), S("ab1234567890"));
+ test(S("abcde"), 2, 3, SV("12345678901234567890"), S("ab12345678901234567890"));
+ test(S("abcde"), 4, 0, SV(""), S("abcde"));
+ test(S("abcde"), 4, 0, SV("12345"), S("abcd12345e"));
+ test(S("abcde"), 4, 0, SV("1234567890"), S("abcd1234567890e"));
+ test(S("abcde"), 4, 0, SV("12345678901234567890"), S("abcd12345678901234567890e"));
+ test(S("abcde"), 4, 1, SV(""), S("abcd"));
+ test(S("abcde"), 4, 1, SV("12345"), S("abcd12345"));
+ test(S("abcde"), 4, 1, SV("1234567890"), S("abcd1234567890"));
+ test(S("abcde"), 4, 1, SV("12345678901234567890"), S("abcd12345678901234567890"));
+ test(S("abcde"), 5, 0, SV(""), S("abcde"));
+ test(S("abcde"), 5, 0, SV("12345"), S("abcde12345"));
+ test(S("abcde"), 5, 0, SV("1234567890"), S("abcde1234567890"));
+ test(S("abcde"), 5, 0, SV("12345678901234567890"), S("abcde12345678901234567890"));
+ test(S("abcdefghij"), 0, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 0, 0, SV("12345"), S("12345abcdefghij"));
+ test(S("abcdefghij"), 0, 0, SV("1234567890"), S("1234567890abcdefghij"));
+ test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), S("12345678901234567890abcdefghij"));
+ test(S("abcdefghij"), 0, 1, SV(""), S("bcdefghij"));
+ test(S("abcdefghij"), 0, 1, SV("12345"), S("12345bcdefghij"));
+ test(S("abcdefghij"), 0, 1, SV("1234567890"), S("1234567890bcdefghij"));
+ test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), S("12345678901234567890bcdefghij"));
+ test(S("abcdefghij"), 0, 5, SV(""), S("fghij"));
+ test(S("abcdefghij"), 0, 5, SV("12345"), S("12345fghij"));
+ test(S("abcdefghij"), 0, 5, SV("1234567890"), S("1234567890fghij"));
+ test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), S("12345678901234567890fghij"));
+ test(S("abcdefghij"), 0, 9, SV(""), S("j"));
+ test(S("abcdefghij"), 0, 9, SV("12345"), S("12345j"));
+ test(S("abcdefghij"), 0, 9, SV("1234567890"), S("1234567890j"));
+ test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), S("12345678901234567890j"));
+ test(S("abcdefghij"), 0, 10, SV(""), S(""));
+ test(S("abcdefghij"), 0, 10, SV("12345"), S("12345"));
+ test(S("abcdefghij"), 0, 10, SV("1234567890"), S("1234567890"));
+ test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcdefghij"), 1, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 1, 0, SV("12345"), S("a12345bcdefghij"));
+ test(S("abcdefghij"), 1, 0, SV("1234567890"), S("a1234567890bcdefghij"));
+ test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+ test(S("abcdefghij"), 1, 1, SV(""), S("acdefghij"));
+ test(S("abcdefghij"), 1, 1, SV("12345"), S("a12345cdefghij"));
+ test(S("abcdefghij"), 1, 1, SV("1234567890"), S("a1234567890cdefghij"));
+ test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), S("a12345678901234567890cdefghij"));
+}
+
+template <class S, class SV>
+void test1()
+{
+ test(S("abcdefghij"), 1, 4, SV(""), S("afghij"));
+ test(S("abcdefghij"), 1, 4, SV("12345"), S("a12345fghij"));
+ test(S("abcdefghij"), 1, 4, SV("1234567890"), S("a1234567890fghij"));
+ test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), S("a12345678901234567890fghij"));
+ test(S("abcdefghij"), 1, 8, SV(""), S("aj"));
+ test(S("abcdefghij"), 1, 8, SV("12345"), S("a12345j"));
+ test(S("abcdefghij"), 1, 8, SV("1234567890"), S("a1234567890j"));
+ test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), S("a12345678901234567890j"));
+ test(S("abcdefghij"), 1, 9, SV(""), S("a"));
+ test(S("abcdefghij"), 1, 9, SV("12345"), S("a12345"));
+ test(S("abcdefghij"), 1, 9, SV("1234567890"), S("a1234567890"));
+ test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcdefghij"), 5, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 5, 0, SV("12345"), S("abcde12345fghij"));
+ test(S("abcdefghij"), 5, 0, SV("1234567890"), S("abcde1234567890fghij"));
+ test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), S("abcde12345678901234567890fghij"));
+ test(S("abcdefghij"), 5, 1, SV(""), S("abcdeghij"));
+ test(S("abcdefghij"), 5, 1, SV("12345"), S("abcde12345ghij"));
+ test(S("abcdefghij"), 5, 1, SV("1234567890"), S("abcde1234567890ghij"));
+ test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), S("abcde12345678901234567890ghij"));
+ test(S("abcdefghij"), 5, 2, SV(""), S("abcdehij"));
+ test(S("abcdefghij"), 5, 2, SV("12345"), S("abcde12345hij"));
+ test(S("abcdefghij"), 5, 2, SV("1234567890"), S("abcde1234567890hij"));
+ test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), S("abcde12345678901234567890hij"));
+ test(S("abcdefghij"), 5, 4, SV(""), S("abcdej"));
+ test(S("abcdefghij"), 5, 4, SV("12345"), S("abcde12345j"));
+ test(S("abcdefghij"), 5, 4, SV("1234567890"), S("abcde1234567890j"));
+ test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), S("abcde12345678901234567890j"));
+ test(S("abcdefghij"), 5, 5, SV(""), S("abcde"));
+ test(S("abcdefghij"), 5, 5, SV("12345"), S("abcde12345"));
+ test(S("abcdefghij"), 5, 5, SV("1234567890"), S("abcde1234567890"));
+ test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), S("abcde12345678901234567890"));
+ test(S("abcdefghij"), 9, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 9, 0, SV("12345"), S("abcdefghi12345j"));
+ test(S("abcdefghij"), 9, 0, SV("1234567890"), S("abcdefghi1234567890j"));
+ test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+ test(S("abcdefghij"), 9, 1, SV(""), S("abcdefghi"));
+ test(S("abcdefghij"), 9, 1, SV("12345"), S("abcdefghi12345"));
+ test(S("abcdefghij"), 9, 1, SV("1234567890"), S("abcdefghi1234567890"));
+ test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), S("abcdefghi12345678901234567890"));
+ test(S("abcdefghij"), 10, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 10, 0, SV("12345"), S("abcdefghij12345"));
+ test(S("abcdefghij"), 10, 0, SV("1234567890"), S("abcdefghij1234567890"));
+ test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 0, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), S("12345abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 1, SV(""), S("bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), S("12345bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), S("1234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), S("12345678901234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 10, SV(""), S("klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), S("12345klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), S("1234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), S("12345678901234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 19, SV(""), S("t"));
+ test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), S("12345t"));
+ test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), S("1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), S("12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 0, 20, SV(""), S(""));
+ test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), S("12345"));
+ test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), S("1234567890"));
+ test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 1, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), S("a12345bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 1, SV(""), S("acdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), S("a12345cdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), S("a1234567890cdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), S("a12345678901234567890cdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 9, SV(""), S("aklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), S("a12345klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), S("a1234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), S("a12345678901234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 18, SV(""), S("at"));
+ test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), S("a12345t"));
+ test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), S("a1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), S("a12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 1, 19, SV(""), S("a"));
+ test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), S("a12345"));
+ test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), S("a1234567890"));
+ test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 10, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), S("abcdefghij12345klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 1, SV(""), S("abcdefghijlmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), S("abcdefghij12345lmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), S("abcdefghij1234567890lmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), S("abcdefghij12345678901234567890lmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 5, SV(""), S("abcdefghijpqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), S("abcdefghij12345pqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), S("abcdefghij1234567890pqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), S("abcdefghij12345678901234567890pqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 9, SV(""), S("abcdefghijt"));
+ test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), S("abcdefghij12345t"));
+ test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), S("abcdefghij1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), S("abcdefghij12345678901234567890t"));
+}
+
+template <class S, class SV>
+void test2()
+{
+ test(S("abcdefghijklmnopqrst"), 10, 10, SV(""), S("abcdefghij"));
+ test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), S("abcdefghij12345"));
+ test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), S("abcdefghij1234567890"));
+ test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 19, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), S("abcdefghijklmnopqrs12345t"));
+ test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 19, 1, SV(""), S("abcdefghijklmnopqrs"));
+ test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), S("abcdefghijklmnopqrs12345"));
+ test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), S("abcdefghijklmnopqrs1234567890"));
+ test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 20, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), S("abcdefghijklmnopqrst12345"));
+ test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+ test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+}
+
+int main()
+{
+ {
+ typedef std::string S;
+ typedef std::string_view SV;
+ test0<S, SV>();
+ test1<S, SV>();
+ test2<S, SV>();
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+ typedef std::string_view SV;
+ test0<S, SV>();
+ test1<S, SV>();
+ test2<S, SV>();
+ }
+#endif
+}
diff --git a/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp
new file mode 100644
index 000000000000..60ecd67f1f7d
--- /dev/null
+++ b/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_view.pass.cpp
@@ -0,0 +1,384 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>&
+// replace(size_type pos1, size_type n1, basic_string_view<charT,traits> sv);
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "test_macros.h"
+#include "min_allocator.h"
+
+template <class S, class SV>
+void
+test(S s, typename S::size_type pos1, typename S::size_type n1, SV sv, S expected)
+{
+ const typename S::size_type old_size = s.size();
+ S s0 = s;
+ if (pos1 <= old_size)
+ {
+ s.replace(pos1, n1, sv);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ typename S::size_type xlen = std::min(n1, old_size - pos1);
+ typename S::size_type rlen = sv.size();
+ assert(s.size() == old_size - xlen + rlen);
+ }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
+ {
+ try
+ {
+ s.replace(pos1, n1, sv);
+ assert(false);
+ }
+ catch (std::out_of_range&)
+ {
+ assert(pos1 > old_size);
+ assert(s == s0);
+ }
+ }
+#endif
+}
+
+template <class S, class SV>
+void test0()
+{
+ test(S(""), 0, 0, SV(""), S(""));
+ test(S(""), 0, 0, SV("12345"), S("12345"));
+ test(S(""), 0, 0, SV("1234567890"), S("1234567890"));
+ test(S(""), 0, 0, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S(""), 0, 1, SV(""), S(""));
+ test(S(""), 0, 1, SV("12345"), S("12345"));
+ test(S(""), 0, 1, SV("1234567890"), S("1234567890"));
+ test(S(""), 0, 1, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S(""), 1, 0, SV(""), S("can't happen"));
+ test(S(""), 1, 0, SV("12345"), S("can't happen"));
+ test(S(""), 1, 0, SV("1234567890"), S("can't happen"));
+ test(S(""), 1, 0, SV("12345678901234567890"), S("can't happen"));
+ test(S("abcde"), 0, 0, SV(""), S("abcde"));
+ test(S("abcde"), 0, 0, SV("12345"), S("12345abcde"));
+ test(S("abcde"), 0, 0, SV("1234567890"), S("1234567890abcde"));
+ test(S("abcde"), 0, 0, SV("12345678901234567890"), S("12345678901234567890abcde"));
+ test(S("abcde"), 0, 1, SV(""), S("bcde"));
+ test(S("abcde"), 0, 1, SV("12345"), S("12345bcde"));
+ test(S("abcde"), 0, 1, SV("1234567890"), S("1234567890bcde"));
+ test(S("abcde"), 0, 1, SV("12345678901234567890"), S("12345678901234567890bcde"));
+ test(S("abcde"), 0, 2, SV(""), S("cde"));
+ test(S("abcde"), 0, 2, SV("12345"), S("12345cde"));
+ test(S("abcde"), 0, 2, SV("1234567890"), S("1234567890cde"));
+ test(S("abcde"), 0, 2, SV("12345678901234567890"), S("12345678901234567890cde"));
+ test(S("abcde"), 0, 4, SV(""), S("e"));
+ test(S("abcde"), 0, 4, SV("12345"), S("12345e"));
+ test(S("abcde"), 0, 4, SV("1234567890"), S("1234567890e"));
+ test(S("abcde"), 0, 4, SV("12345678901234567890"), S("12345678901234567890e"));
+ test(S("abcde"), 0, 5, SV(""), S(""));
+ test(S("abcde"), 0, 5, SV("12345"), S("12345"));
+ test(S("abcde"), 0, 5, SV("1234567890"), S("1234567890"));
+ test(S("abcde"), 0, 5, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcde"), 0, 6, SV(""), S(""));
+ test(S("abcde"), 0, 6, SV("12345"), S("12345"));
+ test(S("abcde"), 0, 6, SV("1234567890"), S("1234567890"));
+ test(S("abcde"), 0, 6, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcde"), 1, 0, SV(""), S("abcde"));
+ test(S("abcde"), 1, 0, SV("12345"), S("a12345bcde"));
+ test(S("abcde"), 1, 0, SV("1234567890"), S("a1234567890bcde"));
+ test(S("abcde"), 1, 0, SV("12345678901234567890"), S("a12345678901234567890bcde"));
+ test(S("abcde"), 1, 1, SV(""), S("acde"));
+ test(S("abcde"), 1, 1, SV("12345"), S("a12345cde"));
+ test(S("abcde"), 1, 1, SV("1234567890"), S("a1234567890cde"));
+ test(S("abcde"), 1, 1, SV("12345678901234567890"), S("a12345678901234567890cde"));
+ test(S("abcde"), 1, 2, SV(""), S("ade"));
+ test(S("abcde"), 1, 2, SV("12345"), S("a12345de"));
+ test(S("abcde"), 1, 2, SV("1234567890"), S("a1234567890de"));
+ test(S("abcde"), 1, 2, SV("12345678901234567890"), S("a12345678901234567890de"));
+ test(S("abcde"), 1, 3, SV(""), S("ae"));
+ test(S("abcde"), 1, 3, SV("12345"), S("a12345e"));
+ test(S("abcde"), 1, 3, SV("1234567890"), S("a1234567890e"));
+ test(S("abcde"), 1, 3, SV("12345678901234567890"), S("a12345678901234567890e"));
+ test(S("abcde"), 1, 4, SV(""), S("a"));
+ test(S("abcde"), 1, 4, SV("12345"), S("a12345"));
+ test(S("abcde"), 1, 4, SV("1234567890"), S("a1234567890"));
+ test(S("abcde"), 1, 4, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcde"), 1, 5, SV(""), S("a"));
+ test(S("abcde"), 1, 5, SV("12345"), S("a12345"));
+ test(S("abcde"), 1, 5, SV("1234567890"), S("a1234567890"));
+ test(S("abcde"), 1, 5, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcde"), 2, 0, SV(""), S("abcde"));
+ test(S("abcde"), 2, 0, SV("12345"), S("ab12345cde"));
+ test(S("abcde"), 2, 0, SV("1234567890"), S("ab1234567890cde"));
+ test(S("abcde"), 2, 0, SV("12345678901234567890"), S("ab12345678901234567890cde"));
+ test(S("abcde"), 2, 1, SV(""), S("abde"));
+ test(S("abcde"), 2, 1, SV("12345"), S("ab12345de"));
+ test(S("abcde"), 2, 1, SV("1234567890"), S("ab1234567890de"));
+ test(S("abcde"), 2, 1, SV("12345678901234567890"), S("ab12345678901234567890de"));
+ test(S("abcde"), 2, 2, SV(""), S("abe"));
+ test(S("abcde"), 2, 2, SV("12345"), S("ab12345e"));
+ test(S("abcde"), 2, 2, SV("1234567890"), S("ab1234567890e"));
+ test(S("abcde"), 2, 2, SV("12345678901234567890"), S("ab12345678901234567890e"));
+ test(S("abcde"), 2, 3, SV(""), S("ab"));
+ test(S("abcde"), 2, 3, SV("12345"), S("ab12345"));
+ test(S("abcde"), 2, 3, SV("1234567890"), S("ab1234567890"));
+ test(S("abcde"), 2, 3, SV("12345678901234567890"), S("ab12345678901234567890"));
+ test(S("abcde"), 2, 4, SV(""), S("ab"));
+ test(S("abcde"), 2, 4, SV("12345"), S("ab12345"));
+ test(S("abcde"), 2, 4, SV("1234567890"), S("ab1234567890"));
+ test(S("abcde"), 2, 4, SV("12345678901234567890"), S("ab12345678901234567890"));
+ test(S("abcde"), 4, 0, SV(""), S("abcde"));
+ test(S("abcde"), 4, 0, SV("12345"), S("abcd12345e"));
+ test(S("abcde"), 4, 0, SV("1234567890"), S("abcd1234567890e"));
+ test(S("abcde"), 4, 0, SV("12345678901234567890"), S("abcd12345678901234567890e"));
+ test(S("abcde"), 4, 1, SV(""), S("abcd"));
+ test(S("abcde"), 4, 1, SV("12345"), S("abcd12345"));
+ test(S("abcde"), 4, 1, SV("1234567890"), S("abcd1234567890"));
+ test(S("abcde"), 4, 1, SV("12345678901234567890"), S("abcd12345678901234567890"));
+ test(S("abcde"), 4, 2, SV(""), S("abcd"));
+ test(S("abcde"), 4, 2, SV("12345"), S("abcd12345"));
+ test(S("abcde"), 4, 2, SV("1234567890"), S("abcd1234567890"));
+ test(S("abcde"), 4, 2, SV("12345678901234567890"), S("abcd12345678901234567890"));
+ test(S("abcde"), 5, 0, SV(""), S("abcde"));
+ test(S("abcde"), 5, 0, SV("12345"), S("abcde12345"));
+ test(S("abcde"), 5, 0, SV("1234567890"), S("abcde1234567890"));
+ test(S("abcde"), 5, 0, SV("12345678901234567890"), S("abcde12345678901234567890"));
+ test(S("abcde"), 5, 1, SV(""), S("abcde"));
+ test(S("abcde"), 5, 1, SV("12345"), S("abcde12345"));
+ test(S("abcde"), 5, 1, SV("1234567890"), S("abcde1234567890"));
+ test(S("abcde"), 5, 1, SV("12345678901234567890"), S("abcde12345678901234567890"));
+}
+
+template <class S, class SV>
+void test1()
+{
+ test(S("abcde"), 6, 0, SV(""), S("can't happen"));
+ test(S("abcde"), 6, 0, SV("12345"), S("can't happen"));
+ test(S("abcde"), 6, 0, SV("1234567890"), S("can't happen"));
+ test(S("abcde"), 6, 0, SV("12345678901234567890"), S("can't happen"));
+ test(S("abcdefghij"), 0, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 0, 0, SV("12345"), S("12345abcdefghij"));
+ test(S("abcdefghij"), 0, 0, SV("1234567890"), S("1234567890abcdefghij"));
+ test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), S("12345678901234567890abcdefghij"));
+ test(S("abcdefghij"), 0, 1, SV(""), S("bcdefghij"));
+ test(S("abcdefghij"), 0, 1, SV("12345"), S("12345bcdefghij"));
+ test(S("abcdefghij"), 0, 1, SV("1234567890"), S("1234567890bcdefghij"));
+ test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), S("12345678901234567890bcdefghij"));
+ test(S("abcdefghij"), 0, 5, SV(""), S("fghij"));
+ test(S("abcdefghij"), 0, 5, SV("12345"), S("12345fghij"));
+ test(S("abcdefghij"), 0, 5, SV("1234567890"), S("1234567890fghij"));
+ test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), S("12345678901234567890fghij"));
+ test(S("abcdefghij"), 0, 9, SV(""), S("j"));
+ test(S("abcdefghij"), 0, 9, SV("12345"), S("12345j"));
+ test(S("abcdefghij"), 0, 9, SV("1234567890"), S("1234567890j"));
+ test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), S("12345678901234567890j"));
+ test(S("abcdefghij"), 0, 10, SV(""), S(""));
+ test(S("abcdefghij"), 0, 10, SV("12345"), S("12345"));
+ test(S("abcdefghij"), 0, 10, SV("1234567890"), S("1234567890"));
+ test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcdefghij"), 0, 11, SV(""), S(""));
+ test(S("abcdefghij"), 0, 11, SV("12345"), S("12345"));
+ test(S("abcdefghij"), 0, 11, SV("1234567890"), S("1234567890"));
+ test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcdefghij"), 1, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 1, 0, SV("12345"), S("a12345bcdefghij"));
+ test(S("abcdefghij"), 1, 0, SV("1234567890"), S("a1234567890bcdefghij"));
+ test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+ test(S("abcdefghij"), 1, 1, SV(""), S("acdefghij"));
+ test(S("abcdefghij"), 1, 1, SV("12345"), S("a12345cdefghij"));
+ test(S("abcdefghij"), 1, 1, SV("1234567890"), S("a1234567890cdefghij"));
+ test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), S("a12345678901234567890cdefghij"));
+ test(S("abcdefghij"), 1, 4, SV(""), S("afghij"));
+ test(S("abcdefghij"), 1, 4, SV("12345"), S("a12345fghij"));
+ test(S("abcdefghij"), 1, 4, SV("1234567890"), S("a1234567890fghij"));
+ test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), S("a12345678901234567890fghij"));
+ test(S("abcdefghij"), 1, 8, SV(""), S("aj"));
+ test(S("abcdefghij"), 1, 8, SV("12345"), S("a12345j"));
+ test(S("abcdefghij"), 1, 8, SV("1234567890"), S("a1234567890j"));
+ test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), S("a12345678901234567890j"));
+ test(S("abcdefghij"), 1, 9, SV(""), S("a"));
+ test(S("abcdefghij"), 1, 9, SV("12345"), S("a12345"));
+ test(S("abcdefghij"), 1, 9, SV("1234567890"), S("a1234567890"));
+ test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcdefghij"), 1, 10, SV(""), S("a"));
+ test(S("abcdefghij"), 1, 10, SV("12345"), S("a12345"));
+ test(S("abcdefghij"), 1, 10, SV("1234567890"), S("a1234567890"));
+ test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcdefghij"), 5, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 5, 0, SV("12345"), S("abcde12345fghij"));
+ test(S("abcdefghij"), 5, 0, SV("1234567890"), S("abcde1234567890fghij"));
+ test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), S("abcde12345678901234567890fghij"));
+ test(S("abcdefghij"), 5, 1, SV(""), S("abcdeghij"));
+ test(S("abcdefghij"), 5, 1, SV("12345"), S("abcde12345ghij"));
+ test(S("abcdefghij"), 5, 1, SV("1234567890"), S("abcde1234567890ghij"));
+ test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), S("abcde12345678901234567890ghij"));
+ test(S("abcdefghij"), 5, 2, SV(""), S("abcdehij"));
+ test(S("abcdefghij"), 5, 2, SV("12345"), S("abcde12345hij"));
+ test(S("abcdefghij"), 5, 2, SV("1234567890"), S("abcde1234567890hij"));
+ test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), S("abcde12345678901234567890hij"));
+ test(S("abcdefghij"), 5, 4, SV(""), S("abcdej"));
+ test(S("abcdefghij"), 5, 4, SV("12345"), S("abcde12345j"));
+ test(S("abcdefghij"), 5, 4, SV("1234567890"), S("abcde1234567890j"));
+ test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), S("abcde12345678901234567890j"));
+ test(S("abcdefghij"), 5, 5, SV(""), S("abcde"));
+ test(S("abcdefghij"), 5, 5, SV("12345"), S("abcde12345"));
+ test(S("abcdefghij"), 5, 5, SV("1234567890"), S("abcde1234567890"));
+ test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), S("abcde12345678901234567890"));
+ test(S("abcdefghij"), 5, 6, SV(""), S("abcde"));
+ test(S("abcdefghij"), 5, 6, SV("12345"), S("abcde12345"));
+ test(S("abcdefghij"), 5, 6, SV("1234567890"), S("abcde1234567890"));
+ test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), S("abcde12345678901234567890"));
+ test(S("abcdefghij"), 9, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 9, 0, SV("12345"), S("abcdefghi12345j"));
+ test(S("abcdefghij"), 9, 0, SV("1234567890"), S("abcdefghi1234567890j"));
+ test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+ test(S("abcdefghij"), 9, 1, SV(""), S("abcdefghi"));
+ test(S("abcdefghij"), 9, 1, SV("12345"), S("abcdefghi12345"));
+ test(S("abcdefghij"), 9, 1, SV("1234567890"), S("abcdefghi1234567890"));
+ test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), S("abcdefghi12345678901234567890"));
+ test(S("abcdefghij"), 9, 2, SV(""), S("abcdefghi"));
+ test(S("abcdefghij"), 9, 2, SV("12345"), S("abcdefghi12345"));
+ test(S("abcdefghij"), 9, 2, SV("1234567890"), S("abcdefghi1234567890"));
+ test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), S("abcdefghi12345678901234567890"));
+ test(S("abcdefghij"), 10, 0, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 10, 0, SV("12345"), S("abcdefghij12345"));
+ test(S("abcdefghij"), 10, 0, SV("1234567890"), S("abcdefghij1234567890"));
+ test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+ test(S("abcdefghij"), 10, 1, SV(""), S("abcdefghij"));
+ test(S("abcdefghij"), 10, 1, SV("12345"), S("abcdefghij12345"));
+ test(S("abcdefghij"), 10, 1, SV("1234567890"), S("abcdefghij1234567890"));
+ test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+ test(S("abcdefghij"), 11, 0, SV(""), S("can't happen"));
+ test(S("abcdefghij"), 11, 0, SV("12345"), S("can't happen"));
+ test(S("abcdefghij"), 11, 0, SV("1234567890"), S("can't happen"));
+ test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), S("can't happen"));
+}
+
+template <class S, class SV>
+void test2()
+{
+ test(S("abcdefghijklmnopqrst"), 0, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), S("12345abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 1, SV(""), S("bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), S("12345bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), S("1234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), S("12345678901234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 10, SV(""), S("klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), S("12345klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), S("1234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), S("12345678901234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 0, 19, SV(""), S("t"));
+ test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), S("12345t"));
+ test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), S("1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), S("12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 0, 20, SV(""), S(""));
+ test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), S("12345"));
+ test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), S("1234567890"));
+ test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 0, 21, SV(""), S(""));
+ test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), S("12345"));
+ test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), S("1234567890"));
+ test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), S("12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 1, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), S("a12345bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 1, SV(""), S("acdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), S("a12345cdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), S("a1234567890cdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), S("a12345678901234567890cdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 9, SV(""), S("aklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), S("a12345klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), S("a1234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), S("a12345678901234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 1, 18, SV(""), S("at"));
+ test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), S("a12345t"));
+ test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), S("a1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), S("a12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 1, 19, SV(""), S("a"));
+ test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), S("a12345"));
+ test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), S("a1234567890"));
+ test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 1, 20, SV(""), S("a"));
+ test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), S("a12345"));
+ test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), S("a1234567890"));
+ test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), S("a12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 10, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), S("abcdefghij12345klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 1, SV(""), S("abcdefghijlmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), S("abcdefghij12345lmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), S("abcdefghij1234567890lmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), S("abcdefghij12345678901234567890lmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 5, SV(""), S("abcdefghijpqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), S("abcdefghij12345pqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), S("abcdefghij1234567890pqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), S("abcdefghij12345678901234567890pqrst"));
+ test(S("abcdefghijklmnopqrst"), 10, 9, SV(""), S("abcdefghijt"));
+ test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), S("abcdefghij12345t"));
+ test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), S("abcdefghij1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), S("abcdefghij12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 10, 10, SV(""), S("abcdefghij"));
+ test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), S("abcdefghij12345"));
+ test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), S("abcdefghij1234567890"));
+ test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 10, 11, SV(""), S("abcdefghij"));
+ test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), S("abcdefghij12345"));
+ test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), S("abcdefghij1234567890"));
+ test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), S("abcdefghij12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 19, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), S("abcdefghijklmnopqrs12345t"));
+ test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+ test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+ test(S("abcdefghijklmnopqrst"), 19, 1, SV(""), S("abcdefghijklmnopqrs"));
+ test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), S("abcdefghijklmnopqrs12345"));
+ test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), S("abcdefghijklmnopqrs1234567890"));
+ test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 19, 2, SV(""), S("abcdefghijklmnopqrs"));
+ test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), S("abcdefghijklmnopqrs12345"));
+ test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), S("abcdefghijklmnopqrs1234567890"));
+ test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 20, 0, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), S("abcdefghijklmnopqrst12345"));
+ test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+ test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 20, 1, SV(""), S("abcdefghijklmnopqrst"));
+ test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), S("abcdefghijklmnopqrst12345"));
+ test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+ test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+ test(S("abcdefghijklmnopqrst"), 21, 0, SV(""), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), S("can't happen"));
+ test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), S("can't happen"));
+}
+
+int main()
+{
+ {
+ typedef std::string S;
+ typedef std::string_view SV;
+ test0<S, SV>();
+ test1<S, SV>();
+ test2<S, SV>();
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+ typedef std::string_view SV;
+ test0<S, SV>();
+ test1<S, SV>();
+ test2<S, SV>();
+ }
+#endif
+}
diff --git a/test/std/strings/basic.string/string.nonmembers/string.special/swap_noexcept.pass.cpp b/test/std/strings/basic.string/string.nonmembers/string.special/swap_noexcept.pass.cpp
index 88c1bee32512..73727198f28e 100644
--- a/test/std/strings/basic.string/string.nonmembers/string.special/swap_noexcept.pass.cpp
+++ b/test/std/strings/basic.string/string.nonmembers/string.special/swap_noexcept.pass.cpp
@@ -68,7 +68,7 @@ int main()
{
typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
#if TEST_STD_VER >= 14
- // In c++14, if POCS is set, swapping the allocator is required not to throw
+ // In C++14, if POCS is set, swapping the allocator is required not to throw
static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
#else
static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
diff --git a/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp b/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
index bc2bf656db01..94f7890ddfdb 100644
--- a/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
+++ b/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
@@ -45,7 +45,7 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
{
try
{
- s.compare(pos1, n1, sv, pos2, n2);
+ TEST_IGNORE_NODISCARD s.compare(pos1, n1, sv, pos2, n2);
assert(false);
}
catch (const std::out_of_range&)
@@ -69,7 +69,7 @@ test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1,
{
try
{
- s.compare(pos1, n1, sv, pos2);
+ TEST_IGNORE_NODISCARD s.compare(pos1, n1, sv, pos2);
assert(false);
}
catch (const std::out_of_range&)
diff --git a/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp b/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
index 13f6c5a1cd7a..55af081a7261 100644
--- a/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
+++ b/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
@@ -40,7 +40,7 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
{
try
{
- s.compare(pos1, n1, str);
+ TEST_IGNORE_NODISCARD s.compare(pos1, n1, str);
assert(false);
}
catch (std::out_of_range&)
diff --git a/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp b/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
index fc811c84671b..2fcecc7556a1 100644
--- a/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
+++ b/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
@@ -40,7 +40,7 @@ test(const S& s, typename S::size_type pos, typename S::size_type n1,
{
try
{
- s.compare(pos, n1, str, n2);
+ TEST_IGNORE_NODISCARD s.compare(pos, n1, str, n2);
assert(false);
}
catch (std::out_of_range&)
diff --git a/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp b/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
index b3d7da29fb1f..0ddbf2e2f99f 100644
--- a/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
+++ b/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
@@ -40,7 +40,7 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
{
try
{
- s.compare(pos1, n1, str);
+ TEST_IGNORE_NODISCARD s.compare(pos1, n1, str);
assert(false);
}
catch (std::out_of_range&)
diff --git a/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp b/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
index 42bba9d5eb2b..590a1518812f 100644
--- a/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
+++ b/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
@@ -42,7 +42,7 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
{
try
{
- s.compare(pos1, n1, str, pos2, n2);
+ TEST_IGNORE_NODISCARD s.compare(pos1, n1, str, pos2, n2);
assert(false);
}
catch (const std::out_of_range&)
@@ -65,7 +65,7 @@ test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1,
{
try
{
- s.compare(pos1, n1, str, pos2);
+ TEST_IGNORE_NODISCARD s.compare(pos1, n1, str, pos2);
assert(false);
}
catch (const std::out_of_range&)
diff --git a/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp b/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp
index 6a5ba22cdc8d..53114f37c0e8 100644
--- a/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp
+++ b/test/std/strings/basic.string/string.ops/string_compare/size_size_string_view.pass.cpp
@@ -40,7 +40,7 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
{
try
{
- s.compare(pos1, n1, sv);
+ TEST_IGNORE_NODISCARD s.compare(pos1, n1, sv);
assert(false);
}
catch (std::out_of_range&)
diff --git a/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp b/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp
index 59d216df09b4..7e46ff74a9ec 100644
--- a/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp
+++ b/test/std/strings/basic.string/string.ops/string_find.last.not.of/string_view_size.pass.cpp
@@ -150,8 +150,8 @@ int main()
}
#if TEST_STD_VER >= 11
{
- typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
- typedef std::string_view SV;
+// typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+// typedef std::string_view SV;
// test0<S, SV>();
// test1<S, SV>();
}
diff --git a/test/std/strings/basic.string/string.starts_with/starts_with.char.pass.cpp b/test/std/strings/basic.string/string.starts_with/starts_with.char.pass.cpp
new file mode 100644
index 000000000000..4be35a76596c
--- /dev/null
+++ b/test/std/strings/basic.string/string.starts_with/starts_with.char.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// <string>
+
+// bool starts_with(charT x) const noexcept;
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ {
+ typedef std::string S;
+ S s1 {};
+ S s2 { "abcde", 5 };
+
+ ASSERT_NOEXCEPT(s1.starts_with('e'));
+
+ assert (!s1.starts_with('a'));
+ assert (!s1.starts_with('x'));
+ assert ( s2.starts_with('a'));
+ assert (!s2.starts_with('x'));
+ }
+}
diff --git a/test/std/strings/basic.string/string.starts_with/starts_with.ptr.pass.cpp b/test/std/strings/basic.string/string.starts_with/starts_with.ptr.pass.cpp
new file mode 100644
index 000000000000..5dec2156ed0a
--- /dev/null
+++ b/test/std/strings/basic.string/string.starts_with/starts_with.ptr.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// <string>
+
+// bool starts_with(const CharT *x) const;
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ {
+ typedef std::string S;
+ const char *s = "abcde";
+ S s0 {};
+ S s1 { s, 1 };
+ S s2 { s, 2 };
+// S s3 { s, 3 };
+// S s4 { s, 4 };
+// S s5 { s, 5 };
+ S sNot {"def", 3 };
+
+ LIBCPP_ASSERT_NOEXCEPT(s0.starts_with(""));
+
+ assert ( s0.starts_with(""));
+ assert (!s0.starts_with("a"));
+
+ assert ( s1.starts_with(""));
+ assert ( s1.starts_with("a"));
+ assert (!s1.starts_with("ab"));
+ assert (!s1.starts_with("abc"));
+ assert (!s1.starts_with("abcd"));
+ assert (!s1.starts_with("abcde"));
+ assert (!s1.starts_with("def"));
+
+ assert ( s2.starts_with(""));
+ assert ( s2.starts_with("a"));
+ assert ( s2.starts_with("ab"));
+ assert (!s2.starts_with("abc"));
+ assert (!s2.starts_with("abcd"));
+ assert (!s2.starts_with("abcde"));
+ assert (!s2.starts_with("def"));
+
+ assert ( sNot.starts_with(""));
+ assert (!sNot.starts_with("a"));
+ assert (!sNot.starts_with("ab"));
+ assert (!sNot.starts_with("abc"));
+ assert (!sNot.starts_with("abcd"));
+ assert (!sNot.starts_with("abcde"));
+ assert ( sNot.starts_with("def"));
+ }
+}
diff --git a/test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp b/test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp
new file mode 100644
index 000000000000..d542d3d79e13
--- /dev/null
+++ b/test/std/strings/basic.string/string.starts_with/starts_with.string_view.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// <string>
+
+// bool starts_with(string_view x) const noexcept;
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ {
+ typedef std::string S;
+ typedef std::string_view SV;
+ const char *s = "abcde";
+
+ S s0;
+ S s1 { s, 1 };
+ S s2 { s, 2 };
+// S s3 { s, 3 };
+// S s4 { s, 4 };
+// S s5 { s, 5 };
+ S sNot { "def", 3 };
+
+ SV sv0;
+ SV sv1 { s, 1 };
+ SV sv2 { s, 2 };
+ SV sv3 { s, 3 };
+ SV sv4 { s, 4 };
+ SV sv5 { s, 5 };
+ SV svNot {"def", 3 };
+
+ ASSERT_NOEXCEPT(s0.starts_with(sv0));
+
+ assert ( s0.starts_with(sv0));
+ assert (!s0.starts_with(sv1));
+
+ assert ( s1.starts_with(sv0));
+ assert ( s1.starts_with(sv1));
+ assert (!s1.starts_with(sv2));
+ assert (!s1.starts_with(sv3));
+ assert (!s1.starts_with(sv4));
+ assert (!s1.starts_with(sv5));
+ assert (!s1.starts_with(svNot));
+
+ assert ( s2.starts_with(sv0));
+ assert ( s2.starts_with(sv1));
+ assert ( s2.starts_with(sv2));
+ assert (!s2.starts_with(sv3));
+ assert (!s2.starts_with(sv4));
+ assert (!s2.starts_with(sv5));
+ assert (!s2.starts_with(svNot));
+
+ assert ( sNot.starts_with(sv0));
+ assert (!sNot.starts_with(sv1));
+ assert (!sNot.starts_with(sv2));
+ assert (!sNot.starts_with(sv3));
+ assert (!sNot.starts_with(sv4));
+ assert (!sNot.starts_with(sv5));
+ assert ( sNot.starts_with(svNot));
+ }
+}