Debian Codegraph @

libcxx/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp

raw
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(size_type n, charT c); // constexpr since C++20
13
14 #include <string>
15 #include <cassert>
16
17 #include "test_macros.h"
18 #include "min_allocator.h"
19 #include "asan_testing.h"
20
21 template <class S>
22 TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) {
23 s.append(n, c);
24 LIBCPP_ASSERT(s.__invariants());
25 assert(s == expected);
26 LIBCPP_ASSERT(is_string_asan_correct(s));
27 }
28
29 template <class S>
30 TEST_CONSTEXPR_CXX20 void test_string() {
31 test(S(), 0, 'a', S());
32 test(S(), 1, 'a', S(1, 'a'));
33 test(S(), 10, 'a', S(10, 'a'));
34 test(S(), 100, 'a', S(100, 'a'));
35
36 test(S("12345"), 0, 'a', S("12345"));
37 test(S("12345"), 1, 'a', S("12345a"));
38 test(S("12345"), 10, 'a', S("12345aaaaaaaaaa"));
39
40 test(S("12345678901234567890"), 0, 'a', S("12345678901234567890"));
41 test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a"));
42 test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa"));
43
44 // Starting from long string (no SSO)
45 test(S("1234567890123456789012345678901234567890"), 0, 'a', S("1234567890123456789012345678901234567890"));
46 test(S("1234567890123456789012345678901234567890"), 1, 'a', S("1234567890123456789012345678901234567890a"));
47 test(S("1234567890123456789012345678901234567890"), 10, 'a', S("1234567890123456789012345678901234567890aaaaaaaaaa"));
48 }
49
50 TEST_CONSTEXPR_CXX20 bool test() {
51 test_string<std::string>();
52 #if TEST_STD_VER >= 11
53 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
54 test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
55 #endif
56
57 return true;
58 }
59
60 int main(int, char**) {
61 test();
62 #if TEST_STD_VER > 17
63 static_assert(test());
64 #endif
65
66 return 0;
67 }