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