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 //   bool ends_with(basic_string_view x) const noexcept;
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 int main(int, char**)
20 {
21     {
22     typedef std::string S;
23     typedef std::string_view SV;
24     const char *s = "abcde";
25 
26     S   s0;
27     S   s1  { s + 4, 1 };
28     S   s2  { s + 3, 2 };
29 //  S   s3  { s + 2, 3 };
30 //  S   s4  { s + 1, 4 };
31 //  S   s5  { s,     5 };
32     S  sNot { "def", 3 };
33 
34     SV  sv0;
35     SV  sv1 { s + 4, 1 };
36     SV  sv2 { s + 3, 2 };
37     SV  sv3 { s + 2, 3 };
38     SV  sv4 { s + 1, 4 };
39     SV  sv5 { s    , 5 };
40     SV svNot {"def", 3 };
41 
42     ASSERT_NOEXCEPT(s0.ends_with(sv0));
43 
44     assert ( s0.ends_with(sv0));
45     assert (!s0.ends_with(sv1));
46 
47     assert ( s1.ends_with(sv0));
48     assert ( s1.ends_with(sv1));
49     assert (!s1.ends_with(sv2));
50     assert (!s1.ends_with(sv3));
51     assert (!s1.ends_with(sv4));
52     assert (!s1.ends_with(sv5));
53     assert (!s1.ends_with(svNot));
54 
55     assert ( s2.ends_with(sv0));
56     assert ( s2.ends_with(sv1));
57     assert ( s2.ends_with(sv2));
58     assert (!s2.ends_with(sv3));
59     assert (!s2.ends_with(sv4));
60     assert (!s2.ends_with(sv5));
61     assert (!s2.ends_with(svNot));
62 
63     assert ( sNot.ends_with(sv0));
64     assert (!sNot.ends_with(sv1));
65     assert (!sNot.ends_with(sv2));
66     assert (!sNot.ends_with(sv3));
67     assert (!sNot.ends_with(sv4));
68     assert (!sNot.ends_with(sv5));
69     assert ( sNot.ends_with(svNot));
70     }
71 
72   return 0;
73 }
74