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 // template<class InputIterator>
13 //   basic_string& append(InputIterator first, InputIterator last);
14 
15 #include <string>
16 #include <cassert>
17 
18 #include "../../input_iterator.h"
19 #include "min_allocator.h"
20 
21 template <class S, class It>
22 void
test(S s,It first,It last,S expected)23 test(S s, It first, It last, S expected)
24 {
25     s.append(first, last);
26     assert(s.__invariants());
27     assert(s == expected);
28 }
29 
main()30 int main()
31 {
32     {
33     typedef std::string S;
34     const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
35     test(S(), s, s, S());
36     test(S(), s, s+1, S("A"));
37     test(S(), s, s+10, S("ABCDEFGHIJ"));
38     test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
39 
40     test(S("12345"), s, s, S("12345"));
41     test(S("12345"), s, s+1, S("12345A"));
42     test(S("12345"), s, s+10, S("12345ABCDEFGHIJ"));
43     test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
44 
45     test(S("1234567890"), s, s, S("1234567890"));
46     test(S("1234567890"), s, s+1, S("1234567890A"));
47     test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ"));
48     test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
49 
50     test(S("12345678901234567890"), s, s, S("12345678901234567890"));
51     test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A"));
52     test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ"));
53     test(S("12345678901234567890"), s, s+52,
54          S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
55 
56     test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s), S());
57     test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A"));
58     test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
59          S("ABCDEFGHIJ"));
60     test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
61          S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
62 
63     test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s),
64          S("12345"));
65     test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
66          S("12345A"));
67     test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
68          S("12345ABCDEFGHIJ"));
69     test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
70          S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
71 
72     test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
73          S("1234567890"));
74     test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
75          S("1234567890A"));
76     test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
77          S("1234567890ABCDEFGHIJ"));
78     test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
79          S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
80 
81     test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
82          S("12345678901234567890"));
83     test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
84          S("12345678901234567890""A"));
85     test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
86          S("12345678901234567890""ABCDEFGHIJ"));
87     test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
88          S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
89     }
90 #if __cplusplus >= 201103L
91     {
92     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
93     const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
94     test(S(), s, s, S());
95     test(S(), s, s+1, S("A"));
96     test(S(), s, s+10, S("ABCDEFGHIJ"));
97     test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
98 
99     test(S("12345"), s, s, S("12345"));
100     test(S("12345"), s, s+1, S("12345A"));
101     test(S("12345"), s, s+10, S("12345ABCDEFGHIJ"));
102     test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
103 
104     test(S("1234567890"), s, s, S("1234567890"));
105     test(S("1234567890"), s, s+1, S("1234567890A"));
106     test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ"));
107     test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
108 
109     test(S("12345678901234567890"), s, s, S("12345678901234567890"));
110     test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A"));
111     test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ"));
112     test(S("12345678901234567890"), s, s+52,
113          S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
114 
115     test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s), S());
116     test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A"));
117     test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
118          S("ABCDEFGHIJ"));
119     test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
120          S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
121 
122     test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s),
123          S("12345"));
124     test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
125          S("12345A"));
126     test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
127          S("12345ABCDEFGHIJ"));
128     test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
129          S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
130 
131     test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
132          S("1234567890"));
133     test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
134          S("1234567890A"));
135     test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
136          S("1234567890ABCDEFGHIJ"));
137     test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
138          S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
139 
140     test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
141          S("12345678901234567890"));
142     test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
143          S("12345678901234567890""A"));
144     test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
145          S("12345678901234567890""ABCDEFGHIJ"));
146     test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
147          S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
148     }
149 #endif
150 }
151