1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10
11 // <string_view>
12
13 // constexpr bool ends_with(string_view x) const noexcept;
14
15 #include <string_view>
16 #include <cassert>
17
18 #include "test_macros.h"
19 #include "constexpr_char_traits.hpp"
20
main()21 int main()
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 sv3 { s + 2, 3 };
30 SV sv4 { s + 1, 4 };
31 SV sv5 { s , 5 };
32 SV svNot {"def", 3 };
33
34 ASSERT_NOEXCEPT(sv0.ends_with(sv0));
35
36 assert ( sv0.ends_with(sv0));
37 assert (!sv0.ends_with(sv1));
38
39 assert ( sv1.ends_with(sv0));
40 assert ( sv1.ends_with(sv1));
41 assert (!sv1.ends_with(sv2));
42 assert (!sv1.ends_with(sv3));
43 assert (!sv1.ends_with(sv4));
44 assert (!sv1.ends_with(sv5));
45 assert (!sv1.ends_with(svNot));
46
47 assert ( sv2.ends_with(sv0));
48 assert ( sv2.ends_with(sv1));
49 assert ( sv2.ends_with(sv2));
50 assert (!sv2.ends_with(sv3));
51 assert (!sv2.ends_with(sv4));
52 assert (!sv2.ends_with(sv5));
53 assert (!sv2.ends_with(svNot));
54
55 assert ( svNot.ends_with(sv0));
56 assert (!svNot.ends_with(sv1));
57 assert (!svNot.ends_with(sv2));
58 assert (!svNot.ends_with(sv3));
59 assert (!svNot.ends_with(sv4));
60 assert (!svNot.ends_with(sv5));
61 assert ( svNot.ends_with(svNot));
62 }
63
64 #if TEST_STD_VER > 11
65 {
66 typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
67 constexpr const char *s = "abcde";
68 constexpr SV sv0 {};
69 constexpr SV sv1 { s + 4, 1 };
70 constexpr SV sv2 { s + 3, 2 };
71 constexpr SV sv3 { s + 2, 3 };
72 constexpr SV sv4 { s + 1, 4 };
73 constexpr SV sv5 { s, 5 };
74 constexpr SV svNot {"def", 3 };
75
76 static_assert ( sv0.ends_with(sv0), "" );
77 static_assert (!sv0.ends_with(sv1), "" );
78
79 static_assert ( sv1.ends_with(sv0), "" );
80 static_assert ( sv1.ends_with(sv1), "" );
81 static_assert (!sv1.ends_with(sv2), "" );
82 static_assert (!sv1.ends_with(sv3), "" );
83 static_assert (!sv1.ends_with(sv4), "" );
84 static_assert (!sv1.ends_with(sv5), "" );
85 static_assert (!sv1.ends_with(svNot), "" );
86
87 static_assert ( sv2.ends_with(sv0), "" );
88 static_assert ( sv2.ends_with(sv1), "" );
89 static_assert ( sv2.ends_with(sv2), "" );
90 static_assert (!sv2.ends_with(sv3), "" );
91 static_assert (!sv2.ends_with(sv4), "" );
92 static_assert (!sv2.ends_with(sv5), "" );
93 static_assert (!sv2.ends_with(svNot), "" );
94
95 static_assert ( svNot.ends_with(sv0), "" );
96 static_assert (!svNot.ends_with(sv1), "" );
97 static_assert (!svNot.ends_with(sv2), "" );
98 static_assert (!svNot.ends_with(sv3), "" );
99 static_assert (!svNot.ends_with(sv4), "" );
100 static_assert (!svNot.ends_with(sv5), "" );
101 static_assert ( svNot.ends_with(svNot), "" );
102 }
103 #endif
104 }
105