1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 
11 // <string_view>
12 
13 //   constexpr bool ends_with(const CharT *x) const;
14 
15 #include <string_view>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "constexpr_char_traits.h"
20 
main(int,char **)21 int main(int, char**)
22 {
23     {
24     typedef std::string_view SV;
25     const char *s = "abcde";
26     SV  sv0 {};
27     SV  sv1 { s + 4, 1 };
28     SV  sv2 { s + 3, 2 };
29     SV  svNot {"def", 3 };
30 
31     LIBCPP_ASSERT_NOEXCEPT(sv0.ends_with(""));
32 
33     assert ( sv0.ends_with(""));
34     assert (!sv0.ends_with("e"));
35 
36     assert ( sv1.ends_with(""));
37     assert ( sv1.ends_with("e"));
38     assert (!sv1.ends_with("de"));
39     assert (!sv1.ends_with("cde"));
40     assert (!sv1.ends_with("bcde"));
41     assert (!sv1.ends_with("abcde"));
42     assert (!sv1.ends_with("def"));
43 
44     assert ( sv2.ends_with(""));
45     assert ( sv2.ends_with("e"));
46     assert ( sv2.ends_with("de"));
47     assert (!sv2.ends_with("cde"));
48     assert (!sv2.ends_with("bcde"));
49     assert (!sv2.ends_with("abcde"));
50     assert (!sv2.ends_with("def"));
51 
52     assert ( svNot.ends_with(""));
53     assert (!svNot.ends_with("e"));
54     assert (!svNot.ends_with("de"));
55     assert (!svNot.ends_with("cde"));
56     assert (!svNot.ends_with("bcde"));
57     assert (!svNot.ends_with("abcde"));
58     assert ( svNot.ends_with("def"));
59     }
60 
61 #if TEST_STD_VER > 11
62     {
63     typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
64     constexpr const char *s = "abcde";
65     constexpr SV  sv0 {};
66     constexpr SV  sv1 { s + 4, 1 };
67     constexpr SV  sv2 { s + 3, 2 };
68     constexpr SV  svNot {"def", 3 };
69 
70     static_assert ( sv0.ends_with(""), "" );
71     static_assert (!sv0.ends_with("e"), "" );
72 
73     static_assert ( sv1.ends_with(""), "" );
74     static_assert ( sv1.ends_with("e"), "" );
75     static_assert (!sv1.ends_with("de"), "" );
76     static_assert (!sv1.ends_with("cde"), "" );
77     static_assert (!sv1.ends_with("bcde"), "" );
78     static_assert (!sv1.ends_with("abcde"), "" );
79     static_assert (!sv1.ends_with("def"), "" );
80 
81     static_assert ( sv2.ends_with(""), "" );
82     static_assert ( sv2.ends_with("e"), "" );
83     static_assert ( sv2.ends_with("de"), "" );
84     static_assert (!sv2.ends_with("cde"), "" );
85     static_assert (!sv2.ends_with("bcde"), "" );
86     static_assert (!sv2.ends_with("abcde"), "" );
87     static_assert (!sv2.ends_with("def"), "" );
88 
89     static_assert ( svNot.ends_with(""), "" );
90     static_assert (!svNot.ends_with("e"), "" );
91     static_assert (!svNot.ends_with("de"), "" );
92     static_assert (!svNot.ends_with("cde"), "" );
93     static_assert (!svNot.ends_with("bcde"), "" );
94     static_assert (!svNot.ends_with("abcde"), "" );
95     static_assert ( svNot.ends_with("def"), "" );
96     }
97 #endif
98 
99   return 0;
100 }
101