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 // basic_string<charT,traits,Allocator>&
13 //   operator=(const basic_string<charT,traits,Allocator>& str);
14 
15 #include <string>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 
21 template <class S>
22 void
test(S s1,const S & s2)23 test(S s1, const S& s2)
24 {
25     s1 = s2;
26     LIBCPP_ASSERT(s1.__invariants());
27     assert(s1 == s2);
28     assert(s1.capacity() >= s1.size());
29 }
30 
main()31 int main()
32 {
33     {
34     typedef std::string S;
35     test(S(), S());
36     test(S("1"), S());
37     test(S(), S("1"));
38     test(S("1"), S("2"));
39     test(S("1"), S("2"));
40 
41     test(S(),
42          S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
43     test(S("123456789"),
44          S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
45     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
46          S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
47     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
48            "1234567890123456789012345678901234567890123456789012345678901234567890"),
49          S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
50     }
51 #if TEST_STD_VER >= 11
52     {
53     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
54     test(S(), S());
55     test(S("1"), S());
56     test(S(), S("1"));
57     test(S("1"), S("2"));
58     test(S("1"), S("2"));
59 
60     test(S(),
61          S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
62     test(S("123456789"),
63          S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
64     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
65          S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
66     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
67            "1234567890123456789012345678901234567890123456789012345678901234567890"),
68          S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
69     }
70 #endif
71 
72 #if TEST_STD_VER > 3
73     {   // LWG 2946
74     std::string s;
75     s = {"abc", 1};
76     assert(s.size() == 1);
77     assert(s == "a");
78     }
79 #endif
80 }
81