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