1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // XFAIL: LIBCXX-AIX-FIXME
10 
11 // <string>
12 
13 // basic_string<charT,traits,Allocator>&
14 //   assign(basic_string<charT,traits>&& str); // constexpr since C++20
15 
16 #include <string>
17 #include <utility>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 
23 template <class S>
24 TEST_CONSTEXPR_CXX20 void
25 test(S s, S str, S expected)
26 {
27     s.assign(std::move(str));
28     LIBCPP_ASSERT(s.__invariants());
29     assert(s == expected);
30 }
31 
32 TEST_CONSTEXPR_CXX20 bool test() {
33   {
34     typedef std::string S;
35     test(S(), S(), S());
36     test(S(), S("12345"), S("12345"));
37     test(S(), S("1234567890"), S("1234567890"));
38     test(S(), S("12345678901234567890"), S("12345678901234567890"));
39 
40     test(S("12345"), S(), S());
41     test(S("12345"), S("12345"), S("12345"));
42     test(S("12345"), S("1234567890"), S("1234567890"));
43     test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
44 
45     test(S("1234567890"), S(), S());
46     test(S("1234567890"), S("12345"), S("12345"));
47     test(S("1234567890"), S("1234567890"), S("1234567890"));
48     test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
49 
50     test(S("12345678901234567890"), S(), S());
51     test(S("12345678901234567890"), S("12345"), S("12345"));
52     test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
53     test(S("12345678901234567890"), S("12345678901234567890"),
54          S("12345678901234567890"));
55   }
56 #if TEST_STD_VER >= 11
57   {
58     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
59     test(S(), S(), S());
60     test(S(), S("12345"), S("12345"));
61     test(S(), S("1234567890"), S("1234567890"));
62     test(S(), S("12345678901234567890"), S("12345678901234567890"));
63 
64     test(S("12345"), S(), S());
65     test(S("12345"), S("12345"), S("12345"));
66     test(S("12345"), S("1234567890"), S("1234567890"));
67     test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
68 
69     test(S("1234567890"), S(), S());
70     test(S("1234567890"), S("12345"), S("12345"));
71     test(S("1234567890"), S("1234567890"), S("1234567890"));
72     test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
73 
74     test(S("12345678901234567890"), S(), S());
75     test(S("12345678901234567890"), S("12345"), S("12345"));
76     test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
77     test(S("12345678901234567890"), S("12345678901234567890"),
78          S("12345678901234567890"));
79   }
80 #endif
81 
82   return true;
83 }
84 
85 int main(int, char**)
86 {
87   test();
88 #if TEST_STD_VER > 17
89   static_assert(test());
90 #endif
91 
92   return 0;
93 }
94