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 //===----------------------------------------------------------------------===//
12 // basic_string<charT,traits,Allocator>&
13 // append(const basic_string<charT,traits>& str, size_type pos, size_type n = npos);
14 // the "= npos" was added for C++14
20 #include "test_macros.h"
21 #include "min_allocator.h"
25 test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
27 if (pos <= str.size())
29 s.append(str, pos, n);
30 LIBCPP_ASSERT(s.__invariants());
31 assert(s == expected);
33 #ifndef TEST_HAS_NO_EXCEPTIONS
38 s.append(str, pos, n);
41 catch (std::out_of_range&)
43 assert(pos > str.size());
51 test_npos(S s, S str, typename S::size_type pos, S expected)
53 if (pos <= str.size())
56 LIBCPP_ASSERT(s.__invariants());
57 assert(s == expected);
59 #ifndef TEST_HAS_NO_EXCEPTIONS
67 catch (std::out_of_range&)
69 assert(pos > str.size());
78 typedef std::string S;
79 test(S(), S(), 0, 0, S());
80 test(S(), S(), 1, 0, S());
81 test(S(), S("12345"), 0, 3, S("123"));
82 test(S(), S("12345"), 1, 4, S("2345"));
83 test(S(), S("12345"), 3, 15, S("45"));
84 test(S(), S("12345"), 5, 15, S(""));
85 test(S(), S("12345"), 6, 15, S("not happening"));
86 test(S(), S("12345678901234567890"), 0, 0, S());
87 test(S(), S("12345678901234567890"), 1, 1, S("2"));
88 test(S(), S("12345678901234567890"), 2, 3, S("345"));
89 test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
90 test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
92 test(S("12345"), S(), 0, 0, S("12345"));
93 test(S("12345"), S("12345"), 2, 2, S("1234534"));
94 test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
96 test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
97 test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
98 test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
99 S("123456789012345678906789012345"));
101 #if TEST_STD_VER >= 11
103 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
104 test(S(), S(), 0, 0, S());
105 test(S(), S(), 1, 0, S());
106 test(S(), S("12345"), 0, 3, S("123"));
107 test(S(), S("12345"), 1, 4, S("2345"));
108 test(S(), S("12345"), 3, 15, S("45"));
109 test(S(), S("12345"), 5, 15, S(""));
110 test(S(), S("12345"), 6, 15, S("not happening"));
111 test(S(), S("12345678901234567890"), 0, 0, S());
112 test(S(), S("12345678901234567890"), 1, 1, S("2"));
113 test(S(), S("12345678901234567890"), 2, 3, S("345"));
114 test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
115 test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
117 test(S("12345"), S(), 0, 0, S("12345"));
118 test(S("12345"), S("12345"), 2, 2, S("1234534"));
119 test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
121 test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
122 test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
123 test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
124 S("123456789012345678906789012345"));
128 typedef std::string S;
129 test_npos(S(), S(), 0, S());
130 test_npos(S(), S(), 1, S());
131 test_npos(S(), S("12345"), 0, S("12345"));
132 test_npos(S(), S("12345"), 1, S("2345"));
133 test_npos(S(), S("12345"), 3, S("45"));
134 test_npos(S(), S("12345"), 5, S(""));
135 test_npos(S(), S("12345"), 6, S("not happening"));