xref: /llvm-project/libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 // void push_back(charT c)
12 
13 #include <string>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 #include "min_allocator.h"
18 
19 struct veryLarge
20 {
21   long long a;
22   char b;
23 };
24 
25 template <class S>
26 void
27 test(S s, typename S::value_type c, S expected)
28 {
29     s.push_back(c);
30     LIBCPP_ASSERT(s.__invariants());
31     assert(s == expected);
32 }
33 
34 int main()
35 {
36     {
37     typedef std::string S;
38     test(S(), 'a', S(1, 'a'));
39     test(S("12345"), 'a', S("12345a"));
40     test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
41     }
42 #if TEST_STD_VER >= 11
43     {
44     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
45     test(S(), 'a', S(1, 'a'));
46     test(S("12345"), 'a', S("12345a"));
47     test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
48     }
49 #endif
50 
51     {
52 // https://bugs.llvm.org/show_bug.cgi?id=31454
53     std::basic_string<veryLarge> s;
54     veryLarge vl = {};
55     s.push_back(vl);
56     s.push_back(vl);
57     s.push_back(vl);
58     }
59 }
60