1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // basic_string<charT,traits,Allocator>&
12 // assign(basic_string_view<charT,traits> sv);
15 #include <string_view>
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "test_allocator.h"
22 template <class S
, class SV
>
24 test(S s
, SV sv
, S expected
)
27 LIBCPP_ASSERT(s
.__invariants());
28 assert(s
== expected
);
31 template <class S
, class SV
>
33 testAlloc(S s
, SV sv
, const typename
S::allocator_type
& a
)
36 LIBCPP_ASSERT(s
.__invariants());
38 assert(s
.get_allocator() == a
);
44 typedef std::string S
;
45 typedef std::string_view SV
;
47 test(S(), SV("12345"), S("12345"));
48 test(S(), SV("1234567890"), S("1234567890"));
49 test(S(), SV("12345678901234567890"), S("12345678901234567890"));
51 test(S("12345"), SV(), S());
52 test(S("12345"), SV("12345"), S("12345"));
53 test(S("12345"), SV("1234567890"), S("1234567890"));
54 test(S("12345"), SV("12345678901234567890"), S("12345678901234567890"));
56 test(S("1234567890"), SV(), S());
57 test(S("1234567890"), SV("12345"), S("12345"));
58 test(S("1234567890"), SV("1234567890"), S("1234567890"));
59 test(S("1234567890"), SV("12345678901234567890"), S("12345678901234567890"));
61 test(S("12345678901234567890"), SV(), S());
62 test(S("12345678901234567890"), SV("12345"), S("12345"));
63 test(S("12345678901234567890"), SV("1234567890"), S("1234567890"));
64 test(S("12345678901234567890"), SV("12345678901234567890"),
65 S("12345678901234567890"));
67 testAlloc(S(), SV(), std::allocator
<char>());
68 testAlloc(S(), SV("12345"), std::allocator
<char>());
69 testAlloc(S(), SV("1234567890"), std::allocator
<char>());
70 testAlloc(S(), SV("12345678901234567890"), std::allocator
<char>());
73 #if TEST_STD_VER >= 11
75 typedef std::basic_string
<char, std::char_traits
<char>, min_allocator
<char>> S
;
76 typedef std::basic_string_view
<char, std::char_traits
<char> > SV
;
78 test(S(), SV("12345"), S("12345"));
79 test(S(), SV("1234567890"), S("1234567890"));
80 test(S(), SV("12345678901234567890"), S("12345678901234567890"));
82 test(S("12345"), SV(), S());
83 test(S("12345"), SV("12345"), S("12345"));
84 test(S("12345"), SV("1234567890"), S("1234567890"));
85 test(S("12345"), SV("12345678901234567890"), S("12345678901234567890"));
87 test(S("1234567890"), SV(), S());
88 test(S("1234567890"), SV("12345"), S("12345"));
89 test(S("1234567890"), SV("1234567890"), S("1234567890"));
90 test(S("1234567890"), SV("12345678901234567890"), S("12345678901234567890"));
92 test(S("12345678901234567890"), SV(), S());
93 test(S("12345678901234567890"), SV("12345"), S("12345"));
94 test(S("12345678901234567890"), SV("1234567890"), S("1234567890"));
95 test(S("12345678901234567890"), SV("12345678901234567890"),
96 S("12345678901234567890"));
98 testAlloc(S(), SV(), min_allocator
<char>());
99 testAlloc(S(), SV("12345"), min_allocator
<char>());
100 testAlloc(S(), SV("1234567890"), min_allocator
<char>());
101 testAlloc(S(), SV("12345678901234567890"), min_allocator
<char>());