[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.modifiers / string_assign / string.pass.cpp
blobfae45c80de0c6673c80cec50b1aa4b39c9c973ca
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <string>
11 // basic_string<charT,traits,Allocator>&
12 // assign(const basic_string<charT,traits>& str);
14 #include <string>
15 #include <cassert>
17 #include "test_macros.h"
18 #include "min_allocator.h"
19 #include "test_allocator.h"
21 template <class S>
22 void
23 test(S s, S str, S expected)
25 s.assign(str);
26 LIBCPP_ASSERT(s.__invariants());
27 assert(s == expected);
30 template <class S>
31 void
32 testAlloc(S s, S str, const typename S::allocator_type& a)
34 s.assign(str);
35 LIBCPP_ASSERT(s.__invariants());
36 assert(s == str);
37 assert(s.get_allocator() == a);
40 int main(int, char**)
43 typedef std::string S;
44 test(S(), S(), S());
45 test(S(), S("12345"), S("12345"));
46 test(S(), S("1234567890"), S("1234567890"));
47 test(S(), S("12345678901234567890"), S("12345678901234567890"));
49 test(S("12345"), S(), S());
50 test(S("12345"), S("12345"), S("12345"));
51 test(S("12345"), S("1234567890"), S("1234567890"));
52 test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
54 test(S("1234567890"), S(), S());
55 test(S("1234567890"), S("12345"), S("12345"));
56 test(S("1234567890"), S("1234567890"), S("1234567890"));
57 test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
59 test(S("12345678901234567890"), S(), S());
60 test(S("12345678901234567890"), S("12345"), S("12345"));
61 test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
62 test(S("12345678901234567890"), S("12345678901234567890"),
63 S("12345678901234567890"));
65 testAlloc(S(), S(), std::allocator<char>());
66 testAlloc(S(), S("12345"), std::allocator<char>());
67 testAlloc(S(), S("1234567890"), std::allocator<char>());
68 testAlloc(S(), S("12345678901234567890"), std::allocator<char>());
71 { // LWG#5579 make sure assign takes the allocators where appropriate
72 typedef other_allocator<char> A; // has POCCA --> true
73 typedef std::basic_string<char, std::char_traits<char>, A> S;
74 testAlloc(S(A(5)), S(A(3)), A(3));
75 testAlloc(S(A(5)), S("1"), A());
76 testAlloc(S(A(5)), S("1", A(7)), A(7));
77 testAlloc(S(A(5)), S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), A(7));
80 #if TEST_STD_VER >= 11
82 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
83 test(S(), S(), S());
84 test(S(), S("12345"), S("12345"));
85 test(S(), S("1234567890"), S("1234567890"));
86 test(S(), S("12345678901234567890"), S("12345678901234567890"));
88 test(S("12345"), S(), S());
89 test(S("12345"), S("12345"), S("12345"));
90 test(S("12345"), S("1234567890"), S("1234567890"));
91 test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
93 test(S("1234567890"), S(), S());
94 test(S("1234567890"), S("12345"), S("12345"));
95 test(S("1234567890"), S("1234567890"), S("1234567890"));
96 test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
98 test(S("12345678901234567890"), S(), S());
99 test(S("12345678901234567890"), S("12345"), S("12345"));
100 test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
101 test(S("12345678901234567890"), S("12345678901234567890"),
102 S("12345678901234567890"));
104 testAlloc(S(), S(), min_allocator<char>());
105 testAlloc(S(), S("12345"), min_allocator<char>());
106 testAlloc(S(), S("1234567890"), min_allocator<char>());
107 testAlloc(S(), S("12345678901234567890"), min_allocator<char>());
109 #endif
110 #if TEST_STD_VER > 14
112 typedef std::string S;
113 static_assert(noexcept(S().assign(S())), ""); // LWG#2063
115 #endif
117 return 0;