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