blob: 4273860f41ad89989e08b4fe1d344fd134fd187f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
Howard Hinnant6e0a1f42010-08-22 00:47:54 +000012// basic_string<charT,traits,Allocator>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000013// assign(basic_string<charT,traits>&& str);
14
15#include <string>
Marshall Clow6b913d72015-01-09 20:25:52 +000016#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000017#include <cassert>
18
Marshall Clow061d0cc2013-11-26 20:58:02 +000019#include "min_allocator.h"
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000020
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021template <class S>
22void
23test(S s, S str, S expected)
24{
25 s.assign(std::move(str));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070026 assert(s.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027 assert(s == expected);
28}
29
30int main()
31{
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000032 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033 typedef std::string S;
34 test(S(), S(), S());
35 test(S(), S("12345"), S("12345"));
36 test(S(), S("1234567890"), S("1234567890"));
37 test(S(), S("12345678901234567890"), S("12345678901234567890"));
38
39 test(S("12345"), S(), S());
40 test(S("12345"), S("12345"), S("12345"));
41 test(S("12345"), S("1234567890"), S("1234567890"));
42 test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
43
44 test(S("1234567890"), S(), S());
45 test(S("1234567890"), S("12345"), S("12345"));
46 test(S("1234567890"), S("1234567890"), S("1234567890"));
47 test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
48
49 test(S("12345678901234567890"), S(), S());
50 test(S("12345678901234567890"), S("12345"), S("12345"));
51 test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
52 test(S("12345678901234567890"), S("12345678901234567890"),
53 S("12345678901234567890"));
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000054 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070055#if __cplusplus >= 201103L
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000056 {
57 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
58 test(S(), S(), S());
59 test(S(), S("12345"), S("12345"));
60 test(S(), S("1234567890"), S("1234567890"));
61 test(S(), S("12345678901234567890"), S("12345678901234567890"));
62
63 test(S("12345"), S(), S());
64 test(S("12345"), S("12345"), S("12345"));
65 test(S("12345"), S("1234567890"), S("1234567890"));
66 test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
67
68 test(S("1234567890"), S(), S());
69 test(S("1234567890"), S("12345"), S("12345"));
70 test(S("1234567890"), S("1234567890"), S("1234567890"));
71 test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
72
73 test(S("12345678901234567890"), S(), S());
74 test(S("12345678901234567890"), S("12345"), S("12345"));
75 test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
76 test(S("12345678901234567890"), S("12345678901234567890"),
77 S("12345678901234567890"));
78 }
79#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000080}