1800259c9SMarshall Clow //===----------------------------------------------------------------------===//
2800259c9SMarshall 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
6800259c9SMarshall Clow //
7800259c9SMarshall Clow //===----------------------------------------------------------------------===//
8*02d11757SLouis Dionne 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14, c++17
10800259c9SMarshall Clow 
11800259c9SMarshall Clow // <string_view>
12800259c9SMarshall Clow 
13800259c9SMarshall Clow //   constexpr bool ends_with(string_view x) const noexcept;
14800259c9SMarshall Clow 
15800259c9SMarshall Clow #include <string_view>
16800259c9SMarshall Clow #include <cassert>
17800259c9SMarshall Clow 
18800259c9SMarshall Clow #include "test_macros.h"
19cc89063bSNico Weber #include "constexpr_char_traits.h"
20800259c9SMarshall Clow 
main(int,char **)212df59c50SJF Bastien int main(int, char**)
22800259c9SMarshall Clow {
23800259c9SMarshall Clow     {
24800259c9SMarshall Clow     typedef std::string_view SV;
25800259c9SMarshall Clow     const char *s = "abcde";
26800259c9SMarshall Clow     SV  sv0;
27800259c9SMarshall Clow     SV  sv1 { s + 4, 1 };
28800259c9SMarshall Clow     SV  sv2 { s + 3, 2 };
29800259c9SMarshall Clow     SV  sv3 { s + 2, 3 };
30800259c9SMarshall Clow     SV  sv4 { s + 1, 4 };
31800259c9SMarshall Clow     SV  sv5 { s    , 5 };
32800259c9SMarshall Clow     SV  svNot {"def", 3 };
33800259c9SMarshall Clow 
34800259c9SMarshall Clow     ASSERT_NOEXCEPT(sv0.ends_with(sv0));
35800259c9SMarshall Clow 
36800259c9SMarshall Clow     assert ( sv0.ends_with(sv0));
37800259c9SMarshall Clow     assert (!sv0.ends_with(sv1));
38800259c9SMarshall Clow 
39800259c9SMarshall Clow     assert ( sv1.ends_with(sv0));
40800259c9SMarshall Clow     assert ( sv1.ends_with(sv1));
41800259c9SMarshall Clow     assert (!sv1.ends_with(sv2));
42800259c9SMarshall Clow     assert (!sv1.ends_with(sv3));
43800259c9SMarshall Clow     assert (!sv1.ends_with(sv4));
44800259c9SMarshall Clow     assert (!sv1.ends_with(sv5));
45800259c9SMarshall Clow     assert (!sv1.ends_with(svNot));
46800259c9SMarshall Clow 
47800259c9SMarshall Clow     assert ( sv2.ends_with(sv0));
48800259c9SMarshall Clow     assert ( sv2.ends_with(sv1));
49800259c9SMarshall Clow     assert ( sv2.ends_with(sv2));
50800259c9SMarshall Clow     assert (!sv2.ends_with(sv3));
51800259c9SMarshall Clow     assert (!sv2.ends_with(sv4));
52800259c9SMarshall Clow     assert (!sv2.ends_with(sv5));
53800259c9SMarshall Clow     assert (!sv2.ends_with(svNot));
54800259c9SMarshall Clow 
55800259c9SMarshall Clow     assert ( svNot.ends_with(sv0));
56800259c9SMarshall Clow     assert (!svNot.ends_with(sv1));
57800259c9SMarshall Clow     assert (!svNot.ends_with(sv2));
58800259c9SMarshall Clow     assert (!svNot.ends_with(sv3));
59800259c9SMarshall Clow     assert (!svNot.ends_with(sv4));
60800259c9SMarshall Clow     assert (!svNot.ends_with(sv5));
61800259c9SMarshall Clow     assert ( svNot.ends_with(svNot));
62800259c9SMarshall Clow     }
63800259c9SMarshall Clow 
64800259c9SMarshall Clow #if TEST_STD_VER > 11
65800259c9SMarshall Clow     {
66800259c9SMarshall Clow     typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
67800259c9SMarshall Clow     constexpr const char *s = "abcde";
68800259c9SMarshall Clow     constexpr SV  sv0 {};
69800259c9SMarshall Clow     constexpr SV  sv1 { s + 4, 1 };
70800259c9SMarshall Clow     constexpr SV  sv2 { s + 3, 2 };
71800259c9SMarshall Clow     constexpr SV  sv3 { s + 2, 3 };
72800259c9SMarshall Clow     constexpr SV  sv4 { s + 1, 4 };
73800259c9SMarshall Clow     constexpr SV  sv5 { s,     5 };
74800259c9SMarshall Clow     constexpr SV  svNot {"def", 3 };
75800259c9SMarshall Clow 
76800259c9SMarshall Clow     static_assert ( sv0.ends_with(sv0), "" );
77800259c9SMarshall Clow     static_assert (!sv0.ends_with(sv1), "" );
78800259c9SMarshall Clow 
79800259c9SMarshall Clow     static_assert ( sv1.ends_with(sv0), "" );
80800259c9SMarshall Clow     static_assert ( sv1.ends_with(sv1), "" );
81800259c9SMarshall Clow     static_assert (!sv1.ends_with(sv2), "" );
82800259c9SMarshall Clow     static_assert (!sv1.ends_with(sv3), "" );
83800259c9SMarshall Clow     static_assert (!sv1.ends_with(sv4), "" );
84800259c9SMarshall Clow     static_assert (!sv1.ends_with(sv5), "" );
85800259c9SMarshall Clow     static_assert (!sv1.ends_with(svNot), "" );
86800259c9SMarshall Clow 
87800259c9SMarshall Clow     static_assert ( sv2.ends_with(sv0), "" );
88800259c9SMarshall Clow     static_assert ( sv2.ends_with(sv1), "" );
89800259c9SMarshall Clow     static_assert ( sv2.ends_with(sv2), "" );
90800259c9SMarshall Clow     static_assert (!sv2.ends_with(sv3), "" );
91800259c9SMarshall Clow     static_assert (!sv2.ends_with(sv4), "" );
92800259c9SMarshall Clow     static_assert (!sv2.ends_with(sv5), "" );
93800259c9SMarshall Clow     static_assert (!sv2.ends_with(svNot), "" );
94800259c9SMarshall Clow 
95800259c9SMarshall Clow     static_assert ( svNot.ends_with(sv0), "" );
96800259c9SMarshall Clow     static_assert (!svNot.ends_with(sv1), "" );
97800259c9SMarshall Clow     static_assert (!svNot.ends_with(sv2), "" );
98800259c9SMarshall Clow     static_assert (!svNot.ends_with(sv3), "" );
99800259c9SMarshall Clow     static_assert (!svNot.ends_with(sv4), "" );
100800259c9SMarshall Clow     static_assert (!svNot.ends_with(sv5), "" );
101800259c9SMarshall Clow     static_assert ( svNot.ends_with(svNot), "" );
102800259c9SMarshall Clow     }
103800259c9SMarshall Clow #endif
1042df59c50SJF Bastien 
1052df59c50SJF Bastien   return 0;
106800259c9SMarshall Clow }
107