1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++98, c++03 10 11 // <string> 12 13 // basic_string<charT,traits,Allocator>& 14 // operator=(basic_string<charT,traits,Allocator>&& str); 15 16 #include <string> 17 #include <cassert> 18 19 #include "test_macros.h" 20 #include "test_allocator.h" 21 #include "min_allocator.h" 22 23 template <class S> 24 void 25 test(S s1, S s2) 26 { 27 S s0 = s2; 28 s1 = std::move(s2); 29 LIBCPP_ASSERT(s1.__invariants()); 30 LIBCPP_ASSERT(s2.__invariants()); 31 assert(s1 == s0); 32 assert(s1.capacity() >= s1.size()); 33 } 34 35 int main(int, char**) 36 { 37 { 38 typedef std::string S; 39 test(S(), S()); 40 test(S("1"), S()); 41 test(S(), S("1")); 42 test(S("1"), S("2")); 43 test(S("1"), S("2")); 44 45 test(S(), 46 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 47 test(S("123456789"), 48 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 49 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 50 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 51 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 52 "1234567890123456789012345678901234567890123456789012345678901234567890"), 53 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 54 } 55 { 56 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 57 test(S(), S()); 58 test(S("1"), S()); 59 test(S(), S("1")); 60 test(S("1"), S("2")); 61 test(S("1"), S("2")); 62 63 test(S(), 64 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 65 test(S("123456789"), 66 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 67 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 68 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 69 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 70 "1234567890123456789012345678901234567890123456789012345678901234567890"), 71 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 72 } 73 74 return 0; 75 } 76