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
13d1da3462SMarek Kurdej // constexpr bool ends_with(const CharT *x) const;
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 svNot {"def", 3 };
30800259c9SMarshall Clow
31800259c9SMarshall Clow LIBCPP_ASSERT_NOEXCEPT(sv0.ends_with(""));
32800259c9SMarshall Clow
33800259c9SMarshall Clow assert ( sv0.ends_with(""));
34800259c9SMarshall Clow assert (!sv0.ends_with("e"));
35800259c9SMarshall Clow
36800259c9SMarshall Clow assert ( sv1.ends_with(""));
37800259c9SMarshall Clow assert ( sv1.ends_with("e"));
38800259c9SMarshall Clow assert (!sv1.ends_with("de"));
39800259c9SMarshall Clow assert (!sv1.ends_with("cde"));
40800259c9SMarshall Clow assert (!sv1.ends_with("bcde"));
41800259c9SMarshall Clow assert (!sv1.ends_with("abcde"));
42800259c9SMarshall Clow assert (!sv1.ends_with("def"));
43800259c9SMarshall Clow
44800259c9SMarshall Clow assert ( sv2.ends_with(""));
45800259c9SMarshall Clow assert ( sv2.ends_with("e"));
46800259c9SMarshall Clow assert ( sv2.ends_with("de"));
47800259c9SMarshall Clow assert (!sv2.ends_with("cde"));
48800259c9SMarshall Clow assert (!sv2.ends_with("bcde"));
49800259c9SMarshall Clow assert (!sv2.ends_with("abcde"));
50800259c9SMarshall Clow assert (!sv2.ends_with("def"));
51800259c9SMarshall Clow
52800259c9SMarshall Clow assert ( svNot.ends_with(""));
53800259c9SMarshall Clow assert (!svNot.ends_with("e"));
54800259c9SMarshall Clow assert (!svNot.ends_with("de"));
55800259c9SMarshall Clow assert (!svNot.ends_with("cde"));
56800259c9SMarshall Clow assert (!svNot.ends_with("bcde"));
57800259c9SMarshall Clow assert (!svNot.ends_with("abcde"));
58800259c9SMarshall Clow assert ( svNot.ends_with("def"));
59800259c9SMarshall Clow }
60800259c9SMarshall Clow
61800259c9SMarshall Clow #if TEST_STD_VER > 11
62800259c9SMarshall Clow {
63800259c9SMarshall Clow typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
64800259c9SMarshall Clow constexpr const char *s = "abcde";
65800259c9SMarshall Clow constexpr SV sv0 {};
66800259c9SMarshall Clow constexpr SV sv1 { s + 4, 1 };
67800259c9SMarshall Clow constexpr SV sv2 { s + 3, 2 };
68800259c9SMarshall Clow constexpr SV svNot {"def", 3 };
69800259c9SMarshall Clow
70800259c9SMarshall Clow static_assert ( sv0.ends_with(""), "" );
71800259c9SMarshall Clow static_assert (!sv0.ends_with("e"), "" );
72800259c9SMarshall Clow
73800259c9SMarshall Clow static_assert ( sv1.ends_with(""), "" );
74800259c9SMarshall Clow static_assert ( sv1.ends_with("e"), "" );
75800259c9SMarshall Clow static_assert (!sv1.ends_with("de"), "" );
76800259c9SMarshall Clow static_assert (!sv1.ends_with("cde"), "" );
77800259c9SMarshall Clow static_assert (!sv1.ends_with("bcde"), "" );
78800259c9SMarshall Clow static_assert (!sv1.ends_with("abcde"), "" );
79800259c9SMarshall Clow static_assert (!sv1.ends_with("def"), "" );
80800259c9SMarshall Clow
81800259c9SMarshall Clow static_assert ( sv2.ends_with(""), "" );
82800259c9SMarshall Clow static_assert ( sv2.ends_with("e"), "" );
83800259c9SMarshall Clow static_assert ( sv2.ends_with("de"), "" );
84800259c9SMarshall Clow static_assert (!sv2.ends_with("cde"), "" );
85800259c9SMarshall Clow static_assert (!sv2.ends_with("bcde"), "" );
86800259c9SMarshall Clow static_assert (!sv2.ends_with("abcde"), "" );
87800259c9SMarshall Clow static_assert (!sv2.ends_with("def"), "" );
88800259c9SMarshall Clow
89800259c9SMarshall Clow static_assert ( svNot.ends_with(""), "" );
90800259c9SMarshall Clow static_assert (!svNot.ends_with("e"), "" );
91800259c9SMarshall Clow static_assert (!svNot.ends_with("de"), "" );
92800259c9SMarshall Clow static_assert (!svNot.ends_with("cde"), "" );
93800259c9SMarshall Clow static_assert (!svNot.ends_with("bcde"), "" );
94800259c9SMarshall Clow static_assert (!svNot.ends_with("abcde"), "" );
95800259c9SMarshall Clow static_assert ( svNot.ends_with("def"), "" );
96800259c9SMarshall Clow }
97800259c9SMarshall Clow #endif
982df59c50SJF Bastien
992df59c50SJF Bastien return 0;
100800259c9SMarshall Clow }
101