1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // XFAIL: libcpp-no-exceptions
13 // void resize(size_type n);
19 #include "min_allocator.h"
23 test(S s, typename S::size_type n, S expected)
28 assert(s.__invariants());
29 assert(n <= s.max_size());
30 assert(s == expected);
32 catch (std::length_error&)
34 assert(n > s.max_size());
41 typedef std::string S;
43 test(S(), 1, S(1, '\0'));
44 test(S(), 10, S(10, '\0'));
45 test(S(), 100, S(100, '\0'));
46 test(S("12345"), 0, S());
47 test(S("12345"), 2, S("12"));
48 test(S("12345"), 5, S("12345"));
49 test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
50 test(S("12345678901234567890123456789012345678901234567890"), 0, S());
51 test(S("12345678901234567890123456789012345678901234567890"), 10,
53 test(S("12345678901234567890123456789012345678901234567890"), 50,
54 S("12345678901234567890123456789012345678901234567890"));
55 test(S("12345678901234567890123456789012345678901234567890"), 60,
56 S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
57 test(S(), S::npos, S("not going to happen"));
59 #if __cplusplus >= 201103L
61 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
63 test(S(), 1, S(1, '\0'));
64 test(S(), 10, S(10, '\0'));
65 test(S(), 100, S(100, '\0'));
66 test(S("12345"), 0, S());
67 test(S("12345"), 2, S("12"));
68 test(S("12345"), 5, S("12345"));
69 test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
70 test(S("12345678901234567890123456789012345678901234567890"), 0, S());
71 test(S("12345678901234567890123456789012345678901234567890"), 10,
73 test(S("12345678901234567890123456789012345678901234567890"), 50,
74 S("12345678901234567890123456789012345678901234567890"));
75 test(S("12345678901234567890123456789012345678901234567890"), 60,
76 S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
77 test(S(), S::npos, S("not going to happen"));