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 //===----------------------------------------------------------------------===//
831cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14, c++17
9800259c9SMarshall Clow 
10800259c9SMarshall Clow // <string>
11800259c9SMarshall Clow 
12*425620ccSNikolas Klauser // constexpr bool ends_with(basic_string_view x) const noexcept;
13800259c9SMarshall Clow 
14800259c9SMarshall Clow #include <string>
15800259c9SMarshall Clow #include <cassert>
16800259c9SMarshall Clow 
17800259c9SMarshall Clow #include "test_macros.h"
18800259c9SMarshall Clow 
test()19*425620ccSNikolas Klauser constexpr bool test() {
20800259c9SMarshall Clow   {
21800259c9SMarshall Clow     typedef std::string S;
22800259c9SMarshall Clow     typedef std::string_view SV;
23800259c9SMarshall Clow     const char *s = "abcde";
24800259c9SMarshall Clow 
25800259c9SMarshall Clow     S   s0;
26800259c9SMarshall Clow     S   s1  { s + 4, 1 };
27800259c9SMarshall Clow     S   s2  { s + 3, 2 };
28800259c9SMarshall Clow //  S   s3  { s + 2, 3 };
29800259c9SMarshall Clow //  S   s4  { s + 1, 4 };
30800259c9SMarshall Clow //  S   s5  { s,     5 };
31800259c9SMarshall Clow     S  sNot { "def", 3 };
32800259c9SMarshall Clow 
33800259c9SMarshall Clow     SV  sv0;
34800259c9SMarshall Clow     SV  sv1 { s + 4, 1 };
35800259c9SMarshall Clow     SV  sv2 { s + 3, 2 };
36800259c9SMarshall Clow     SV  sv3 { s + 2, 3 };
37800259c9SMarshall Clow     SV  sv4 { s + 1, 4 };
38800259c9SMarshall Clow     SV  sv5 { s    , 5 };
39800259c9SMarshall Clow     SV svNot {"def", 3 };
40800259c9SMarshall Clow 
41800259c9SMarshall Clow     ASSERT_NOEXCEPT(s0.ends_with(sv0));
42800259c9SMarshall Clow 
43800259c9SMarshall Clow     assert ( s0.ends_with(sv0));
44800259c9SMarshall Clow     assert (!s0.ends_with(sv1));
45800259c9SMarshall Clow 
46800259c9SMarshall Clow     assert ( s1.ends_with(sv0));
47800259c9SMarshall Clow     assert ( s1.ends_with(sv1));
48800259c9SMarshall Clow     assert (!s1.ends_with(sv2));
49800259c9SMarshall Clow     assert (!s1.ends_with(sv3));
50800259c9SMarshall Clow     assert (!s1.ends_with(sv4));
51800259c9SMarshall Clow     assert (!s1.ends_with(sv5));
52800259c9SMarshall Clow     assert (!s1.ends_with(svNot));
53800259c9SMarshall Clow 
54800259c9SMarshall Clow     assert ( s2.ends_with(sv0));
55800259c9SMarshall Clow     assert ( s2.ends_with(sv1));
56800259c9SMarshall Clow     assert ( s2.ends_with(sv2));
57800259c9SMarshall Clow     assert (!s2.ends_with(sv3));
58800259c9SMarshall Clow     assert (!s2.ends_with(sv4));
59800259c9SMarshall Clow     assert (!s2.ends_with(sv5));
60800259c9SMarshall Clow     assert (!s2.ends_with(svNot));
61800259c9SMarshall Clow 
62800259c9SMarshall Clow     assert ( sNot.ends_with(sv0));
63800259c9SMarshall Clow     assert (!sNot.ends_with(sv1));
64800259c9SMarshall Clow     assert (!sNot.ends_with(sv2));
65800259c9SMarshall Clow     assert (!sNot.ends_with(sv3));
66800259c9SMarshall Clow     assert (!sNot.ends_with(sv4));
67800259c9SMarshall Clow     assert (!sNot.ends_with(sv5));
68800259c9SMarshall Clow     assert ( sNot.ends_with(svNot));
69800259c9SMarshall Clow   }
702df59c50SJF Bastien 
71c515b652SNikolas Klauser   return true;
72c515b652SNikolas Klauser }
73c515b652SNikolas Klauser 
main(int,char **)74c515b652SNikolas Klauser int main(int, char**) {
75c515b652SNikolas Klauser   test();
76*425620ccSNikolas Klauser   static_assert(test());
77c515b652SNikolas Klauser 
782df59c50SJF Bastien   return 0;
79800259c9SMarshall Clow }
80