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>& operator=(basic_string_view<charT, traits> sv); // constexpr since C++20
14 
15 #include <string>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 
21 template <class S, class SV>
22 TEST_CONSTEXPR_CXX20 void
23 test(S s1, SV sv)
24 {
25     typedef typename S::traits_type T;
26     s1 = sv;
27     LIBCPP_ASSERT(s1.__invariants());
28     assert(s1.size() == sv.size());
29     assert(T::compare(s1.data(), sv.data(), s1.size()) == 0);
30     assert(s1.capacity() >= s1.size());
31 }
32 
33 TEST_CONSTEXPR_CXX20 bool test() {
34   {
35     typedef std::string S;
36     typedef std::string_view SV;
37     test(S(), SV(""));
38     test(S("1"), SV(""));
39     test(S(), SV("1"));
40     test(S("1"), SV("2"));
41     test(S("1"), SV("2"));
42 
43     test(S(),
44          SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
45     test(S("123456789"),
46          SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
47     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
48          SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
49     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
50            "1234567890123456789012345678901234567890123456789012345678901234567890"),
51          SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
52   }
53 #if TEST_STD_VER >= 11
54   {
55     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
56     typedef std::string_view SV;
57     test(S(), SV(""));
58     test(S("1"), SV(""));
59     test(S(), SV("1"));
60     test(S("1"), SV("2"));
61     test(S("1"), SV("2"));
62 
63     test(S(),
64          SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
65     test(S("123456789"),
66          SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
67     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
68          SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
69     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
70            "1234567890123456789012345678901234567890123456789012345678901234567890"),
71          SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
72   }
73 #endif
74 
75   return true;
76 }
77 
78 int main(int, char**)
79 {
80   test();
81 #if TEST_STD_VER > 17
82   static_assert(test());
83 #endif
84 
85   return 0;
86 }
87