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>&
12*425620ccSNikolas Klauser // append(const basic_string<charT,traits>& str); // constexpr since C++20
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>
21dcffa7d3SNikolas Klauser TEST_CONSTEXPR_CXX20 void
test(S s,S str,S expected)225a83710eSEric Fiselier test(S s, S str, S expected)
235a83710eSEric Fiselier {
245a83710eSEric Fiselier s.append(str);
251f4231f8SEric Fiselier LIBCPP_ASSERT(s.__invariants());
265a83710eSEric Fiselier assert(s == expected);
275a83710eSEric Fiselier }
285a83710eSEric Fiselier
test()29*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 bool test() {
305a83710eSEric Fiselier {
315a83710eSEric Fiselier typedef std::string S;
325a83710eSEric Fiselier test(S(), S(), S());
335a83710eSEric Fiselier test(S(), S("12345"), S("12345"));
345a83710eSEric Fiselier test(S(), S("1234567890"), S("1234567890"));
355a83710eSEric Fiselier test(S(), S("12345678901234567890"), S("12345678901234567890"));
365a83710eSEric Fiselier
375a83710eSEric Fiselier test(S("12345"), S(), S("12345"));
385a83710eSEric Fiselier test(S("12345"), S("12345"), S("1234512345"));
395a83710eSEric Fiselier test(S("12345"), S("1234567890"), S("123451234567890"));
405a83710eSEric Fiselier test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
415a83710eSEric Fiselier
425a83710eSEric Fiselier test(S("1234567890"), S(), S("1234567890"));
435a83710eSEric Fiselier test(S("1234567890"), S("12345"), S("123456789012345"));
445a83710eSEric Fiselier test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
455a83710eSEric Fiselier test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
465a83710eSEric Fiselier
475a83710eSEric Fiselier test(S("12345678901234567890"), S(), S("12345678901234567890"));
485a83710eSEric Fiselier test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
495a83710eSEric Fiselier test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
505a83710eSEric Fiselier test(S("12345678901234567890"), S("12345678901234567890"),
515a83710eSEric Fiselier S("1234567890123456789012345678901234567890"));
525a83710eSEric Fiselier }
5376b4afc0SMarshall Clow #if TEST_STD_VER >= 11
545a83710eSEric Fiselier {
555a83710eSEric Fiselier typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
565a83710eSEric Fiselier test(S(), S(), S());
575a83710eSEric Fiselier test(S(), S("12345"), S("12345"));
585a83710eSEric Fiselier test(S(), S("1234567890"), S("1234567890"));
595a83710eSEric Fiselier test(S(), S("12345678901234567890"), S("12345678901234567890"));
605a83710eSEric Fiselier
615a83710eSEric Fiselier test(S("12345"), S(), S("12345"));
625a83710eSEric Fiselier test(S("12345"), S("12345"), S("1234512345"));
635a83710eSEric Fiselier test(S("12345"), S("1234567890"), S("123451234567890"));
645a83710eSEric Fiselier test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
655a83710eSEric Fiselier
665a83710eSEric Fiselier test(S("1234567890"), S(), S("1234567890"));
675a83710eSEric Fiselier test(S("1234567890"), S("12345"), S("123456789012345"));
685a83710eSEric Fiselier test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
695a83710eSEric Fiselier test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
705a83710eSEric Fiselier
715a83710eSEric Fiselier test(S("12345678901234567890"), S(), S("12345678901234567890"));
725a83710eSEric Fiselier test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
735a83710eSEric Fiselier test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
745a83710eSEric Fiselier test(S("12345678901234567890"), S("12345678901234567890"),
755a83710eSEric Fiselier S("1234567890123456789012345678901234567890"));
765a83710eSEric Fiselier }
775a83710eSEric Fiselier #endif
7876b26852SMarshall Clow
7976b26852SMarshall Clow #if TEST_STD_VER > 3
8076b26852SMarshall Clow { // LWG 2946
8176b26852SMarshall Clow std::string s;
8276b26852SMarshall Clow s.append({"abc", 1});
8376b26852SMarshall Clow assert(s.size() == 1);
8476b26852SMarshall Clow assert(s == "a");
8576b26852SMarshall Clow }
8676b26852SMarshall Clow #endif
872df59c50SJF Bastien
88dcffa7d3SNikolas Klauser return true;
89dcffa7d3SNikolas Klauser }
90dcffa7d3SNikolas Klauser
main(int,char **)91dcffa7d3SNikolas Klauser int main(int, char**)
92dcffa7d3SNikolas Klauser {
93dcffa7d3SNikolas Klauser test();
94dcffa7d3SNikolas Klauser #if TEST_STD_VER > 17
95*425620ccSNikolas Klauser static_assert(test());
96dcffa7d3SNikolas Klauser #endif
97dcffa7d3SNikolas Klauser
982df59c50SJF Bastien return 0;
995a83710eSEric Fiselier }
100