1053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2053d81ceSMarshall 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
6053d81ceSMarshall Clow //
7053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
8053d81ceSMarshall Clow
9053d81ceSMarshall Clow // <string>
10053d81ceSMarshall Clow
11053d81ceSMarshall Clow // basic_string<charT,traits,Allocator>&
12*425620ccSNikolas Klauser // append(basic_string_view<charT,traits> sv); // constexpr since C++20
13053d81ceSMarshall Clow
14053d81ceSMarshall Clow #include <string>
15053d81ceSMarshall Clow #include <string_view>
16053d81ceSMarshall Clow #include <cassert>
17053d81ceSMarshall Clow
18053d81ceSMarshall Clow #include "test_macros.h"
19053d81ceSMarshall Clow #include "min_allocator.h"
20053d81ceSMarshall Clow
21053d81ceSMarshall Clow template <class S, class SV>
22dcffa7d3SNikolas Klauser TEST_CONSTEXPR_CXX20 void
test(S s,SV sv,S expected)23053d81ceSMarshall Clow test(S s, SV sv, S expected)
24053d81ceSMarshall Clow {
25053d81ceSMarshall Clow s.append(sv);
26053d81ceSMarshall Clow LIBCPP_ASSERT(s.__invariants());
27053d81ceSMarshall Clow assert(s == expected);
28053d81ceSMarshall Clow }
29053d81ceSMarshall Clow
test()30*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 bool test() {
31053d81ceSMarshall Clow {
32053d81ceSMarshall Clow typedef std::string S;
33053d81ceSMarshall Clow typedef std::string_view SV;
34053d81ceSMarshall Clow test(S(), SV(), S());
35053d81ceSMarshall Clow test(S(), SV("12345"), S("12345"));
36053d81ceSMarshall Clow test(S(), SV("1234567890"), S("1234567890"));
37053d81ceSMarshall Clow test(S(), SV("12345678901234567890"), S("12345678901234567890"));
38053d81ceSMarshall Clow
39053d81ceSMarshall Clow test(S("12345"), SV(), S("12345"));
40053d81ceSMarshall Clow test(S("12345"), SV("12345"), S("1234512345"));
41053d81ceSMarshall Clow test(S("12345"), SV("1234567890"), S("123451234567890"));
42053d81ceSMarshall Clow test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
43053d81ceSMarshall Clow
44053d81ceSMarshall Clow test(S("1234567890"), SV(), S("1234567890"));
45053d81ceSMarshall Clow test(S("1234567890"), SV("12345"), S("123456789012345"));
46053d81ceSMarshall Clow test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
47053d81ceSMarshall Clow test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
48053d81ceSMarshall Clow
49053d81ceSMarshall Clow test(S("12345678901234567890"), SV(), S("12345678901234567890"));
50053d81ceSMarshall Clow test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
51053d81ceSMarshall Clow test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
52053d81ceSMarshall Clow test(S("12345678901234567890"), SV("12345678901234567890"),
53053d81ceSMarshall Clow S("1234567890123456789012345678901234567890"));
54053d81ceSMarshall Clow }
55053d81ceSMarshall Clow #if TEST_STD_VER >= 11
56053d81ceSMarshall Clow {
57053d81ceSMarshall Clow typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S;
58053d81ceSMarshall Clow typedef std::basic_string_view<char, std::char_traits<char> > SV;
59053d81ceSMarshall Clow test(S(), SV(), S());
60053d81ceSMarshall Clow test(S(), SV("12345"), S("12345"));
61053d81ceSMarshall Clow test(S(), SV("1234567890"), S("1234567890"));
62053d81ceSMarshall Clow test(S(), SV("12345678901234567890"), S("12345678901234567890"));
63053d81ceSMarshall Clow
64053d81ceSMarshall Clow test(S("12345"), SV(), S("12345"));
65053d81ceSMarshall Clow test(S("12345"), SV("12345"), S("1234512345"));
66053d81ceSMarshall Clow test(S("12345"), SV("1234567890"), S("123451234567890"));
67053d81ceSMarshall Clow test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
68053d81ceSMarshall Clow
69053d81ceSMarshall Clow test(S("1234567890"), SV(), S("1234567890"));
70053d81ceSMarshall Clow test(S("1234567890"), SV("12345"), S("123456789012345"));
71053d81ceSMarshall Clow test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
72053d81ceSMarshall Clow test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
73053d81ceSMarshall Clow
74053d81ceSMarshall Clow test(S("12345678901234567890"), SV(), S("12345678901234567890"));
75053d81ceSMarshall Clow test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
76053d81ceSMarshall Clow test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
77053d81ceSMarshall Clow test(S("12345678901234567890"), SV("12345678901234567890"),
78053d81ceSMarshall Clow S("1234567890123456789012345678901234567890"));
79053d81ceSMarshall Clow }
80053d81ceSMarshall Clow #endif
812df59c50SJF Bastien
82dcffa7d3SNikolas Klauser return true;
83dcffa7d3SNikolas Klauser }
84dcffa7d3SNikolas Klauser
main(int,char **)85dcffa7d3SNikolas Klauser int main(int, char**)
86dcffa7d3SNikolas Klauser {
87dcffa7d3SNikolas Klauser test();
88dcffa7d3SNikolas Klauser #if TEST_STD_VER > 17
89*425620ccSNikolas Klauser static_assert(test());
90dcffa7d3SNikolas Klauser #endif
91dcffa7d3SNikolas Klauser
922df59c50SJF Bastien return 0;
93053d81ceSMarshall Clow }
94