libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

ends_with.ptr.pass.cpp (1636B)


      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(const CharT *x) const;
     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     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     LIBCPP_ASSERT_NOEXCEPT(s0.ends_with(""));
     35 
     36     assert ( s0.ends_with(""));
     37     assert (!s0.ends_with("e"));
     38 
     39     assert ( s1.ends_with(""));
     40     assert ( s1.ends_with("e"));
     41     assert (!s1.ends_with("de"));
     42     assert (!s1.ends_with("cde"));
     43     assert (!s1.ends_with("bcde"));
     44     assert (!s1.ends_with("abcde"));
     45     assert (!s1.ends_with("def"));
     46 
     47     assert ( s2.ends_with(""));
     48     assert ( s2.ends_with("e"));
     49     assert ( s2.ends_with("de"));
     50     assert (!s2.ends_with("cde"));
     51     assert (!s2.ends_with("bcde"));
     52     assert (!s2.ends_with("abcde"));
     53     assert (!s2.ends_with("def"));
     54 
     55     assert ( sNot.ends_with(""));
     56     assert (!sNot.ends_with("e"));
     57     assert (!sNot.ends_with("de"));
     58     assert (!sNot.ends_with("cde"));
     59     assert (!sNot.ends_with("bcde"));
     60     assert (!sNot.ends_with("abcde"));
     61     assert ( sNot.ends_with("def"));
     62     }
     63 }