[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.capacity / resize_size_char.pass.cpp
blobb5e5aff8424ad5c41d95c9eb52be2e8f61e31237
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 //===----------------------------------------------------------------------===//
9 // <string>
11 // void resize(size_type n, charT c);
13 #include <string>
14 #include <stdexcept>
15 #include <cassert>
17 #include "test_macros.h"
18 #include "min_allocator.h"
20 template <class S>
21 void
22 test(S s, typename S::size_type n, typename S::value_type c, S expected)
24 if (n <= s.max_size())
26 s.resize(n, c);
27 LIBCPP_ASSERT(s.__invariants());
28 assert(s == expected);
30 #ifndef TEST_HAS_NO_EXCEPTIONS
31 else
33 try
35 s.resize(n, c);
36 assert(false);
38 catch (std::length_error&)
40 assert(n > s.max_size());
43 #endif
46 int main(int, char**)
49 typedef std::string S;
50 test(S(), 0, 'a', S());
51 test(S(), 1, 'a', S("a"));
52 test(S(), 10, 'a', S(10, 'a'));
53 test(S(), 100, 'a', S(100, 'a'));
54 test(S("12345"), 0, 'a', S());
55 test(S("12345"), 2, 'a', S("12"));
56 test(S("12345"), 5, 'a', S("12345"));
57 test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
58 test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
59 test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
60 S("1234567890"));
61 test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
62 S("12345678901234567890123456789012345678901234567890"));
63 test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
64 S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
65 test(S(), S::npos, 'a', S("not going to happen"));
67 #if TEST_STD_VER >= 11
69 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
70 test(S(), 0, 'a', S());
71 test(S(), 1, 'a', S("a"));
72 test(S(), 10, 'a', S(10, 'a'));
73 test(S(), 100, 'a', S(100, 'a'));
74 test(S("12345"), 0, 'a', S());
75 test(S("12345"), 2, 'a', S("12"));
76 test(S("12345"), 5, 'a', S("12345"));
77 test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
78 test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
79 test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
80 S("1234567890"));
81 test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
82 S("12345678901234567890123456789012345678901234567890"));
83 test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
84 S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
85 test(S(), S::npos, 'a', S("not going to happen"));
87 #endif
89 return 0;