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);
17 #include "test_macros.h"
18 #include "min_allocator.h"
22 test(S s
, typename
S::size_type n
, S expected
)
24 if (n
<= s
.max_size())
27 LIBCPP_ASSERT(s
.__invariants());
28 assert(s
== expected
);
30 #ifndef TEST_HAS_NO_EXCEPTIONS
38 catch (std::length_error
&)
40 assert(n
> s
.max_size());
49 typedef std::string S
;
51 test(S(), 1, S(1, '\0'));
52 test(S(), 10, S(10, '\0'));
53 test(S(), 100, S(100, '\0'));
54 test(S("12345"), 0, S());
55 test(S("12345"), 2, S("12"));
56 test(S("12345"), 5, S("12345"));
57 test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
58 test(S("12345678901234567890123456789012345678901234567890"), 0, S());
59 test(S("12345678901234567890123456789012345678901234567890"), 10,
61 test(S("12345678901234567890123456789012345678901234567890"), 50,
62 S("12345678901234567890123456789012345678901234567890"));
63 test(S("12345678901234567890123456789012345678901234567890"), 60,
64 S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
65 test(S(), S::npos
, 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
;
71 test(S(), 1, S(1, '\0'));
72 test(S(), 10, S(10, '\0'));
73 test(S(), 100, S(100, '\0'));
74 test(S("12345"), 0, S());
75 test(S("12345"), 2, S("12"));
76 test(S("12345"), 5, S("12345"));
77 test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
78 test(S("12345678901234567890123456789012345678901234567890"), 0, S());
79 test(S("12345678901234567890123456789012345678901234567890"), 10,
81 test(S("12345678901234567890123456789012345678901234567890"), 50,
82 S("12345678901234567890123456789012345678901234567890"));
83 test(S("12345678901234567890123456789012345678901234567890"), 60,
84 S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
85 test(S(), S::npos
, S("not going to happen"));