1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <string>
11
12 // void resize(size_type n, charT c);
13
14 #include <string>
15 #include <stdexcept>
16 #include <cassert>
17
18 #include "min_allocator.h"
19
20 template <class S>
21 void
test(S s,typename S::size_type n,typename S::value_type c,S expected)22 test(S s, typename S::size_type n, typename S::value_type c, S expected)
23 {
24 try
25 {
26 s.resize(n, c);
27 assert(s.__invariants());
28 assert(n <= s.max_size());
29 assert(s == expected);
30 }
31 catch (std::length_error&)
32 {
33 assert(n > s.max_size());
34 }
35 }
36
main()37 int main()
38 {
39 {
40 typedef std::string S;
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',
51 S("1234567890"));
52 test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
53 S("12345678901234567890123456789012345678901234567890"));
54 test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
55 S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
56 test(S(), S::npos, 'a', S("not going to happen"));
57 }
58 #if __cplusplus >= 201103L
59 {
60 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
61 test(S(), 0, 'a', S());
62 test(S(), 1, 'a', S("a"));
63 test(S(), 10, 'a', S(10, 'a'));
64 test(S(), 100, 'a', S(100, 'a'));
65 test(S("12345"), 0, 'a', S());
66 test(S("12345"), 2, 'a', S("12"));
67 test(S("12345"), 5, 'a', S("12345"));
68 test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
69 test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
70 test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
71 S("1234567890"));
72 test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
73 S("12345678901234567890123456789012345678901234567890"));
74 test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
75 S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
76 test(S(), S::npos, 'a', S("not going to happen"));
77 }
78 #endif
79 }
80