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 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 
10 // <string>
11 
12 // constexpr bool ends_with(const CharT *x) const;
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 constexpr bool test() {
20   {
21     typedef std::string S;
22     const char *s = "abcde";
23 
24     S   s0;
25     S   s1  { s + 4, 1 };
26     S   s2  { s + 3, 2 };
27 //  S   s3  { s + 2, 3 };
28 //  S   s4  { s + 1, 4 };
29 //  S   s5  { s,     5 };
30     S  sNot { "def", 3 };
31 
32     LIBCPP_ASSERT_NOEXCEPT(s0.ends_with(""));
33 
34     assert ( s0.ends_with(""));
35     assert (!s0.ends_with("e"));
36 
37     assert ( s1.ends_with(""));
38     assert ( s1.ends_with("e"));
39     assert (!s1.ends_with("de"));
40     assert (!s1.ends_with("cde"));
41     assert (!s1.ends_with("bcde"));
42     assert (!s1.ends_with("abcde"));
43     assert (!s1.ends_with("def"));
44 
45     assert ( s2.ends_with(""));
46     assert ( s2.ends_with("e"));
47     assert ( s2.ends_with("de"));
48     assert (!s2.ends_with("cde"));
49     assert (!s2.ends_with("bcde"));
50     assert (!s2.ends_with("abcde"));
51     assert (!s2.ends_with("def"));
52 
53     assert ( sNot.ends_with(""));
54     assert (!sNot.ends_with("e"));
55     assert (!sNot.ends_with("de"));
56     assert (!sNot.ends_with("cde"));
57     assert (!sNot.ends_with("bcde"));
58     assert (!sNot.ends_with("abcde"));
59     assert ( sNot.ends_with("def"));
60   }
61 
62   return true;
63 }
64 
65 int main(int, char**) {
66   test();
67   static_assert(test());
68 
69   return 0;
70 }
71