1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // void resize(size_type n, charT c); // constexpr since C++20
17 #include "test_macros.h"
18 #include "min_allocator.h"
21 TEST_CONSTEXPR_CXX20
void test(S s
, typename
S::size_type n
, typename
S::value_type c
, S expected
) {
22 if (n
<= s
.max_size()) {
24 LIBCPP_ASSERT(s
.__invariants());
25 assert(s
== expected
);
27 #ifndef TEST_HAS_NO_EXCEPTIONS
28 else if (!TEST_IS_CONSTANT_EVALUATED
) {
32 } catch (std::length_error
&) {
33 assert(n
> s
.max_size());
40 TEST_CONSTEXPR_CXX20
void test_string() {
41 test(S(), 0, 'a', S());
42 test(S(), 1, 'a', S("a"));
43 test(S(), 10, 'a', S(10, 'a'));
44 test(S(), 100, 'a', S(100, 'a'));
45 test(S("12345"), 0, 'a', S());
46 test(S("12345"), 2, 'a', S("12"));
47 test(S("12345"), 5, 'a', S("12345"));
48 test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
49 test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
50 test(S("12345678901234567890123456789012345678901234567890"), 10, 'a', S("1234567890"));
51 test(S("12345678901234567890123456789012345678901234567890"),
54 S("12345678901234567890123456789012345678901234567890"));
55 test(S("12345678901234567890123456789012345678901234567890"),
58 S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
59 test(S(), S::npos
, 'a', S("not going to happen"));
62 TEST_CONSTEXPR_CXX20
bool test() {
63 test_string
<std::string
>();
64 #if TEST_STD_VER >= 11
65 test_string
<std::basic_string
<char, std::char_traits
<char>, min_allocator
<char>>>();
71 int main(int, char**) {
74 static_assert(test());