summaryrefslogtreecommitdiff
path: root/test/std/strings/basic.string/string.cons
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/strings/basic.string/string.cons')
-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
6 files changed, 106 insertions, 32 deletions
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
+}