xref: /llvm-project/libcxx/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp (revision 425620ccdd47e56b59512913cdc71e116f951e4e)
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=(charT c); // 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>
22 TEST_CONSTEXPR_CXX20 void
23 test(S s1, typename S::value_type s2)
24 {
25     typedef typename S::traits_type T;
26     s1 = s2;
27     LIBCPP_ASSERT(s1.__invariants());
28     assert(s1.size() == 1);
29     assert(T::eq(s1[0], s2));
30     assert(s1.capacity() >= s1.size());
31 }
32 
33 TEST_CONSTEXPR_CXX20 bool test() {
34   {
35     typedef std::string S;
36     test(S(), 'a');
37     test(S("1"), 'a');
38     test(S("123456789"), 'a');
39     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
40   }
41 #if TEST_STD_VER >= 11
42   {
43     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
44     test(S(), 'a');
45     test(S("1"), 'a');
46     test(S("123456789"), 'a');
47     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
48   }
49 #endif
50 
51   return true;
52 }
53 
54 int main(int, char**)
55 {
56   test();
57 #if TEST_STD_VER > 17
58   static_assert(test());
59 #endif
60 
61   return 0;
62 }
63