15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65a83710eSEric Fiselier // 75a83710eSEric Fiselier //===----------------------------------------------------------------------===// 85a83710eSEric Fiselier 95a83710eSEric Fiselier // <string> 105a83710eSEric Fiselier 115a83710eSEric Fiselier // basic_string<charT,traits,Allocator>& 125a83710eSEric Fiselier // operator=(const basic_string<charT,traits,Allocator>& str); 135a83710eSEric Fiselier 145a83710eSEric Fiselier #include <string> 155a83710eSEric Fiselier #include <cassert> 165a83710eSEric Fiselier 171f4231f8SEric Fiselier #include "test_macros.h" 185a83710eSEric Fiselier #include "min_allocator.h" 195a83710eSEric Fiselier 205a83710eSEric Fiselier template <class S> 21*e85018b7SNikolas Klauser TEST_CONSTEXPR_CXX20 void 225a83710eSEric Fiselier test(S s1, const S& s2) 235a83710eSEric Fiselier { 245a83710eSEric Fiselier s1 = s2; 251f4231f8SEric Fiselier LIBCPP_ASSERT(s1.__invariants()); 265a83710eSEric Fiselier assert(s1 == s2); 275a83710eSEric Fiselier assert(s1.capacity() >= s1.size()); 285a83710eSEric Fiselier } 295a83710eSEric Fiselier 30*e85018b7SNikolas Klauser bool test() { 315a83710eSEric Fiselier { 325a83710eSEric Fiselier typedef std::string S; 335a83710eSEric Fiselier test(S(), S()); 345a83710eSEric Fiselier test(S("1"), S()); 355a83710eSEric Fiselier test(S(), S("1")); 365a83710eSEric Fiselier test(S("1"), S("2")); 375a83710eSEric Fiselier test(S("1"), S("2")); 385a83710eSEric Fiselier 395a83710eSEric Fiselier test(S(), 405a83710eSEric Fiselier S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 415a83710eSEric Fiselier test(S("123456789"), 425a83710eSEric Fiselier S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 435a83710eSEric Fiselier test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 445a83710eSEric Fiselier S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 455a83710eSEric Fiselier test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 465a83710eSEric Fiselier "1234567890123456789012345678901234567890123456789012345678901234567890"), 475a83710eSEric Fiselier S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 485a83710eSEric Fiselier } 491f4231f8SEric Fiselier #if TEST_STD_VER >= 11 505a83710eSEric Fiselier { 515a83710eSEric Fiselier typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 525a83710eSEric Fiselier test(S(), S()); 535a83710eSEric Fiselier test(S("1"), S()); 545a83710eSEric Fiselier test(S(), S("1")); 555a83710eSEric Fiselier test(S("1"), S("2")); 565a83710eSEric Fiselier test(S("1"), S("2")); 575a83710eSEric Fiselier 585a83710eSEric Fiselier test(S(), 595a83710eSEric Fiselier S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 605a83710eSEric Fiselier test(S("123456789"), 615a83710eSEric Fiselier S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 625a83710eSEric Fiselier test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 635a83710eSEric Fiselier S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 645a83710eSEric Fiselier test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 655a83710eSEric Fiselier "1234567890123456789012345678901234567890123456789012345678901234567890"), 665a83710eSEric Fiselier S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 675a83710eSEric Fiselier } 685a83710eSEric Fiselier #endif 6976b26852SMarshall Clow 7076b26852SMarshall Clow #if TEST_STD_VER > 3 7176b26852SMarshall Clow { // LWG 2946 7276b26852SMarshall Clow std::string s; 7376b26852SMarshall Clow s = {"abc", 1}; 7476b26852SMarshall Clow assert(s.size() == 1); 7576b26852SMarshall Clow assert(s == "a"); 7676b26852SMarshall Clow } 7776b26852SMarshall Clow #endif 782df59c50SJF Bastien 79*e85018b7SNikolas Klauser return true; 80*e85018b7SNikolas Klauser } 81*e85018b7SNikolas Klauser 82*e85018b7SNikolas Klauser int main(int, char**) 83*e85018b7SNikolas Klauser { 84*e85018b7SNikolas Klauser test(); 85*e85018b7SNikolas Klauser #if TEST_STD_VER > 17 86*e85018b7SNikolas Klauser // static_assert(test()); 87*e85018b7SNikolas Klauser #endif 88*e85018b7SNikolas Klauser 892df59c50SJF Bastien return 0; 905a83710eSEric Fiselier } 91