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& assign(InputIterator first, InputIterator last);
14
15#include <string>
16#include <cassert>
17
18#include "../../input_iterator.h"
19#include "min_allocator.h"
20
21template <class S, class It>
22void
23test(S s, It first, It last, S expected)
24{
25    s.assign(first, last);
26    assert(s.__invariants());
27    assert(s == expected);
28}
29
30int 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());
41    test(S("12345"), s, s+1, S("A"));
42    test(S("12345"), s, s+10, S("ABCDEFGHIJ"));
43    test(S("12345"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
44
45    test(S("1234567890"), s, s, S());
46    test(S("1234567890"), s, s+1, S("A"));
47    test(S("1234567890"), s, s+10, S("ABCDEFGHIJ"));
48    test(S("1234567890"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
49
50    test(S("12345678901234567890"), s, s, S());
51    test(S("12345678901234567890"), s, s+1, S("A"));
52    test(S("12345678901234567890"), s, s+10, S("ABCDEFGHIJ"));
53    test(S("12345678901234567890"), s, s+52,
54         S("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());
65    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
66         S("A"));
67    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
68         S("ABCDEFGHIJ"));
69    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
70         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
71
72    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
73         S());
74    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
75         S("A"));
76    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
77         S("ABCDEFGHIJ"));
78    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
79         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
80
81    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
82         S());
83    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
84         S("A"));
85    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
86         S("ABCDEFGHIJ"));
87    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
88         S("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());
100    test(S("12345"), s, s+1, S("A"));
101    test(S("12345"), s, s+10, S("ABCDEFGHIJ"));
102    test(S("12345"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
103
104    test(S("1234567890"), s, s, S());
105    test(S("1234567890"), s, s+1, S("A"));
106    test(S("1234567890"), s, s+10, S("ABCDEFGHIJ"));
107    test(S("1234567890"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
108
109    test(S("12345678901234567890"), s, s, S());
110    test(S("12345678901234567890"), s, s+1, S("A"));
111    test(S("12345678901234567890"), s, s+10, S("ABCDEFGHIJ"));
112    test(S("12345678901234567890"), s, s+52,
113         S("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());
124    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
125         S("A"));
126    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
127         S("ABCDEFGHIJ"));
128    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
129         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
130
131    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
132         S());
133    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
134         S("A"));
135    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
136         S("ABCDEFGHIJ"));
137    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
138         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
139
140    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
141         S());
142    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
143         S("A"));
144    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
145         S("ABCDEFGHIJ"));
146    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
147         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
148    }
149#endif
150}
151