1e2addb79SMarshall Clow //===----------------------------------------------------------------------===//
2e2addb79SMarshall Clow //
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
6e2addb79SMarshall Clow //
7e2addb79SMarshall Clow //===----------------------------------------------------------------------===//
8e2addb79SMarshall Clow
9e2addb79SMarshall Clow // <string>
10e2addb79SMarshall Clow
11*425620ccSNikolas Klauser // basic_string<charT,traits,Allocator>& operator=(basic_string_view<charT, traits> sv); // constexpr since C++20
12e2addb79SMarshall Clow
13e2addb79SMarshall Clow #include <string>
14e2addb79SMarshall Clow #include <cassert>
15e2addb79SMarshall Clow
16e2addb79SMarshall Clow #include "test_macros.h"
17e2addb79SMarshall Clow #include "min_allocator.h"
18e2addb79SMarshall Clow
19e2addb79SMarshall Clow template <class S, class SV>
20e85018b7SNikolas Klauser TEST_CONSTEXPR_CXX20 void
test(S s1,SV sv)21e2addb79SMarshall Clow test(S s1, SV sv)
22e2addb79SMarshall Clow {
23e2addb79SMarshall Clow typedef typename S::traits_type T;
24e2addb79SMarshall Clow s1 = sv;
25e2addb79SMarshall Clow LIBCPP_ASSERT(s1.__invariants());
26e2addb79SMarshall Clow assert(s1.size() == sv.size());
27e2addb79SMarshall Clow assert(T::compare(s1.data(), sv.data(), s1.size()) == 0);
28e2addb79SMarshall Clow assert(s1.capacity() >= s1.size());
29e2addb79SMarshall Clow }
30e2addb79SMarshall Clow
test()31*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 bool test() {
32e2addb79SMarshall Clow {
33e2addb79SMarshall Clow typedef std::string S;
34e2addb79SMarshall Clow typedef std::string_view SV;
35e2addb79SMarshall Clow test(S(), SV(""));
36e2addb79SMarshall Clow test(S("1"), SV(""));
37e2addb79SMarshall Clow test(S(), SV("1"));
38e2addb79SMarshall Clow test(S("1"), SV("2"));
39e2addb79SMarshall Clow test(S("1"), SV("2"));
40e2addb79SMarshall Clow
41e2addb79SMarshall Clow test(S(),
42e2addb79SMarshall Clow SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
43e2addb79SMarshall Clow test(S("123456789"),
44e2addb79SMarshall Clow SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
45e2addb79SMarshall Clow test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
46e2addb79SMarshall Clow SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
47e2addb79SMarshall Clow test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
48e2addb79SMarshall Clow "1234567890123456789012345678901234567890123456789012345678901234567890"),
49e2addb79SMarshall Clow SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
50e2addb79SMarshall Clow }
51e2addb79SMarshall Clow #if TEST_STD_VER >= 11
52e2addb79SMarshall Clow {
53e2addb79SMarshall Clow typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
54e2addb79SMarshall Clow typedef std::string_view SV;
55e2addb79SMarshall Clow test(S(), SV(""));
56e2addb79SMarshall Clow test(S("1"), SV(""));
57e2addb79SMarshall Clow test(S(), SV("1"));
58e2addb79SMarshall Clow test(S("1"), SV("2"));
59e2addb79SMarshall Clow test(S("1"), SV("2"));
60e2addb79SMarshall Clow
61e2addb79SMarshall Clow test(S(),
62e2addb79SMarshall Clow SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
63e2addb79SMarshall Clow test(S("123456789"),
64e2addb79SMarshall Clow SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
65e2addb79SMarshall Clow test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
66e2addb79SMarshall Clow SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
67e2addb79SMarshall Clow test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
68e2addb79SMarshall Clow "1234567890123456789012345678901234567890123456789012345678901234567890"),
69e2addb79SMarshall Clow SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
70e2addb79SMarshall Clow }
71e2addb79SMarshall Clow #endif
722df59c50SJF Bastien
73e85018b7SNikolas Klauser return true;
74e85018b7SNikolas Klauser }
75e85018b7SNikolas Klauser
main(int,char **)76e85018b7SNikolas Klauser int main(int, char**)
77e85018b7SNikolas Klauser {
78e85018b7SNikolas Klauser test();
79e85018b7SNikolas Klauser #if TEST_STD_VER > 17
80*425620ccSNikolas Klauser static_assert(test());
81e85018b7SNikolas Klauser #endif
82e85018b7SNikolas Klauser
832df59c50SJF Bastien return 0;
84e2addb79SMarshall Clow }
85