blob: 6b89df98de72b35cd01c224da7786a3b24df7998 [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
Eric Fiselier375e2f62016-04-28 22:28:23 +000019#include "test_macros.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000020#include "min_allocator.h"
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000021
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022template <class S>
23void
24test(S s, S str, S expected)
25{
26 s.assign(std::move(str));
Eric Fiselier375e2f62016-04-28 22:28:23 +000027 LIBCPP_ASSERT(s.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000028 assert(s == expected);
29}
30
31int main()
32{
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000033 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034 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"));
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000055 }
Marshall Clowdf9db312016-01-13 21:54:34 +000056#if TEST_STD_VER >= 11
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000057 {
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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000081}