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