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 //   append(basic_string_view<charT,traits> sv); // constexpr since C++20
15 
16 #include <string>
17 #include <string_view>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 
23 template <class S, class SV>
24 TEST_CONSTEXPR_CXX20 void
25 test(S s, SV sv, S expected)
26 {
27     s.append(sv);
28     LIBCPP_ASSERT(s.__invariants());
29     assert(s == expected);
30 }
31 
32 TEST_CONSTEXPR_CXX20 bool test() {
33   {
34     typedef std::string S;
35     typedef std::string_view SV;
36     test(S(), SV(), S());
37     test(S(), SV("12345"), S("12345"));
38     test(S(), SV("1234567890"), S("1234567890"));
39     test(S(), SV("12345678901234567890"), S("12345678901234567890"));
40 
41     test(S("12345"), SV(), S("12345"));
42     test(S("12345"), SV("12345"), S("1234512345"));
43     test(S("12345"), SV("1234567890"), S("123451234567890"));
44     test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
45 
46     test(S("1234567890"), SV(), S("1234567890"));
47     test(S("1234567890"), SV("12345"), S("123456789012345"));
48     test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
49     test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
50 
51     test(S("12345678901234567890"), SV(), S("12345678901234567890"));
52     test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
53     test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
54     test(S("12345678901234567890"), SV("12345678901234567890"),
55          S("1234567890123456789012345678901234567890"));
56   }
57 #if TEST_STD_VER >= 11
58   {
59     typedef std::basic_string     <char, std::char_traits<char>, min_allocator<char>> S;
60     typedef std::basic_string_view<char, std::char_traits<char> > SV;
61     test(S(), SV(), S());
62     test(S(), SV("12345"), S("12345"));
63     test(S(), SV("1234567890"), S("1234567890"));
64     test(S(), SV("12345678901234567890"), S("12345678901234567890"));
65 
66     test(S("12345"), SV(), S("12345"));
67     test(S("12345"), SV("12345"), S("1234512345"));
68     test(S("12345"), SV("1234567890"), S("123451234567890"));
69     test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
70 
71     test(S("1234567890"), SV(), S("1234567890"));
72     test(S("1234567890"), SV("12345"), S("123456789012345"));
73     test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
74     test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
75 
76     test(S("12345678901234567890"), SV(), S("12345678901234567890"));
77     test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
78     test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
79     test(S("12345678901234567890"), SV("12345678901234567890"),
80          S("1234567890123456789012345678901234567890"));
81   }
82 #endif
83 
84   return true;
85 }
86 
87 int main(int, char**)
88 {
89   test();
90 #if TEST_STD_VER > 17
91   static_assert(test());
92 #endif
93 
94   return 0;
95 }
96