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(const CharT *x) const; 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 const char *s = "abcde"; 24 25 S s0; 26 S s1 { s + 4, 1 }; 27 S s2 { s + 3, 2 }; 28 // S s3 { s + 2, 3 }; 29 // S s4 { s + 1, 4 }; 30 // S s5 { s, 5 }; 31 S sNot { "def", 3 }; 32 33 LIBCPP_ASSERT_NOEXCEPT(s0.ends_with("")); 34 35 assert ( s0.ends_with("")); 36 assert (!s0.ends_with("e")); 37 38 assert ( s1.ends_with("")); 39 assert ( s1.ends_with("e")); 40 assert (!s1.ends_with("de")); 41 assert (!s1.ends_with("cde")); 42 assert (!s1.ends_with("bcde")); 43 assert (!s1.ends_with("abcde")); 44 assert (!s1.ends_with("def")); 45 46 assert ( s2.ends_with("")); 47 assert ( s2.ends_with("e")); 48 assert ( s2.ends_with("de")); 49 assert (!s2.ends_with("cde")); 50 assert (!s2.ends_with("bcde")); 51 assert (!s2.ends_with("abcde")); 52 assert (!s2.ends_with("def")); 53 54 assert ( sNot.ends_with("")); 55 assert (!sNot.ends_with("e")); 56 assert (!sNot.ends_with("de")); 57 assert (!sNot.ends_with("cde")); 58 assert (!sNot.ends_with("bcde")); 59 assert (!sNot.ends_with("abcde")); 60 assert ( sNot.ends_with("def")); 61 } 62 63 return 0; 64 } 65