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