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 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 sv3 { s + 2, 3 }; 30 // SV sv4 { s + 1, 4 }; 31 // SV sv5 { s , 5 }; 32 SV svNot {"def", 3 }; 33 34 LIBCPP_ASSERT_NOEXCEPT(sv0.ends_with("")); 35 36 assert ( sv0.ends_with("")); 37 assert (!sv0.ends_with("e")); 38 39 assert ( sv1.ends_with("")); 40 assert ( sv1.ends_with("e")); 41 assert (!sv1.ends_with("de")); 42 assert (!sv1.ends_with("cde")); 43 assert (!sv1.ends_with("bcde")); 44 assert (!sv1.ends_with("abcde")); 45 assert (!sv1.ends_with("def")); 46 47 assert ( sv2.ends_with("")); 48 assert ( sv2.ends_with("e")); 49 assert ( sv2.ends_with("de")); 50 assert (!sv2.ends_with("cde")); 51 assert (!sv2.ends_with("bcde")); 52 assert (!sv2.ends_with("abcde")); 53 assert (!sv2.ends_with("def")); 54 55 assert ( svNot.ends_with("")); 56 assert (!svNot.ends_with("e")); 57 assert (!svNot.ends_with("de")); 58 assert (!svNot.ends_with("cde")); 59 assert (!svNot.ends_with("bcde")); 60 assert (!svNot.ends_with("abcde")); 61 assert ( svNot.ends_with("def")); 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(""), "" ); 77 static_assert (!sv0.ends_with("e"), "" ); 78 79 static_assert ( sv1.ends_with(""), "" ); 80 static_assert ( sv1.ends_with("e"), "" ); 81 static_assert (!sv1.ends_with("de"), "" ); 82 static_assert (!sv1.ends_with("cde"), "" ); 83 static_assert (!sv1.ends_with("bcde"), "" ); 84 static_assert (!sv1.ends_with("abcde"), "" ); 85 static_assert (!sv1.ends_with("def"), "" ); 86 87 static_assert ( sv2.ends_with(""), "" ); 88 static_assert ( sv2.ends_with("e"), "" ); 89 static_assert ( sv2.ends_with("de"), "" ); 90 static_assert (!sv2.ends_with("cde"), "" ); 91 static_assert (!sv2.ends_with("bcde"), "" ); 92 static_assert (!sv2.ends_with("abcde"), "" ); 93 static_assert (!sv2.ends_with("def"), "" ); 94 95 static_assert ( svNot.ends_with(""), "" ); 96 static_assert (!svNot.ends_with("e"), "" ); 97 static_assert (!svNot.ends_with("de"), "" ); 98 static_assert (!svNot.ends_with("cde"), "" ); 99 static_assert (!svNot.ends_with("bcde"), "" ); 100 static_assert (!svNot.ends_with("abcde"), "" ); 101 static_assert ( svNot.ends_with("def"), "" ); 102 } 103 #endif 104 105 return 0; 106 } 107