xref: /llvm-project/libcxx/test/std/strings/basic.string/string.ends_with/ends_with.ptr.pass.cpp (revision 6e1dcc9335116f650d68cdbed12bbb34a99b2d9b)
1800259c9SMarshall Clow //===----------------------------------------------------------------------===//
2800259c9SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6800259c9SMarshall Clow //
7800259c9SMarshall Clow //===----------------------------------------------------------------------===//
831cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14, c++17
9800259c9SMarshall Clow 
10800259c9SMarshall Clow // <string>
11800259c9SMarshall Clow 
12425620ccSNikolas Klauser // constexpr bool ends_with(const CharT *x) const;
13800259c9SMarshall Clow 
14800259c9SMarshall Clow #include <string>
15800259c9SMarshall Clow #include <cassert>
16800259c9SMarshall Clow 
17800259c9SMarshall Clow #include "test_macros.h"
18800259c9SMarshall Clow 
19*6e1dcc93SLouis Dionne template <class S>
test_string()20*6e1dcc93SLouis Dionne constexpr void test_string() {
21800259c9SMarshall Clow   const char* s = "abcde";
22800259c9SMarshall Clow 
23800259c9SMarshall Clow   S s0;
24800259c9SMarshall Clow   S s1{s + 4, 1};
25800259c9SMarshall Clow   S s2{s + 3, 2};
26800259c9SMarshall Clow   //  S   s3  { s + 2, 3 };
27800259c9SMarshall Clow   //  S   s4  { s + 1, 4 };
28800259c9SMarshall Clow   //  S   s5  { s,     5 };
29800259c9SMarshall Clow   S sNot{"def", 3};
30800259c9SMarshall Clow 
31800259c9SMarshall Clow   LIBCPP_ASSERT_NOEXCEPT(s0.ends_with(""));
32800259c9SMarshall Clow 
33800259c9SMarshall Clow   assert(s0.ends_with(""));
34800259c9SMarshall Clow   assert(!s0.ends_with("e"));
35800259c9SMarshall Clow 
36800259c9SMarshall Clow   assert(s1.ends_with(""));
37800259c9SMarshall Clow   assert(s1.ends_with("e"));
38800259c9SMarshall Clow   assert(!s1.ends_with("de"));
39800259c9SMarshall Clow   assert(!s1.ends_with("cde"));
40800259c9SMarshall Clow   assert(!s1.ends_with("bcde"));
41800259c9SMarshall Clow   assert(!s1.ends_with("abcde"));
42800259c9SMarshall Clow   assert(!s1.ends_with("def"));
43800259c9SMarshall Clow 
44800259c9SMarshall Clow   assert(s2.ends_with(""));
45800259c9SMarshall Clow   assert(s2.ends_with("e"));
46800259c9SMarshall Clow   assert(s2.ends_with("de"));
47800259c9SMarshall Clow   assert(!s2.ends_with("cde"));
48800259c9SMarshall Clow   assert(!s2.ends_with("bcde"));
49800259c9SMarshall Clow   assert(!s2.ends_with("abcde"));
50800259c9SMarshall Clow   assert(!s2.ends_with("def"));
51800259c9SMarshall Clow 
52800259c9SMarshall Clow   assert(sNot.ends_with(""));
53800259c9SMarshall Clow   assert(!sNot.ends_with("e"));
54800259c9SMarshall Clow   assert(!sNot.ends_with("de"));
55800259c9SMarshall Clow   assert(!sNot.ends_with("cde"));
56800259c9SMarshall Clow   assert(!sNot.ends_with("bcde"));
57800259c9SMarshall Clow   assert(!sNot.ends_with("abcde"));
58800259c9SMarshall Clow   assert(sNot.ends_with("def"));
59800259c9SMarshall Clow }
602df59c50SJF Bastien 
test()61*6e1dcc93SLouis Dionne constexpr bool test() {
62*6e1dcc93SLouis Dionne   test_string<std::string>();
63*6e1dcc93SLouis Dionne 
64c515b652SNikolas Klauser   return true;
65c515b652SNikolas Klauser }
66c515b652SNikolas Klauser 
main(int,char **)67c515b652SNikolas Klauser int main(int, char**) {
68c515b652SNikolas Klauser   test();
69425620ccSNikolas Klauser   static_assert(test());
70c515b652SNikolas Klauser 
712df59c50SJF Bastien   return 0;
72800259c9SMarshall Clow }
73