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
12*425620ccSNikolas 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
test()19*425620ccSNikolas Klauser constexpr bool test() {
20800259c9SMarshall Clow {
21800259c9SMarshall Clow typedef std::string S;
22800259c9SMarshall Clow const char *s = "abcde";
23800259c9SMarshall Clow
24800259c9SMarshall Clow S s0;
25800259c9SMarshall Clow S s1 { s + 4, 1 };
26800259c9SMarshall Clow S s2 { s + 3, 2 };
27800259c9SMarshall Clow // S s3 { s + 2, 3 };
28800259c9SMarshall Clow // S s4 { s + 1, 4 };
29800259c9SMarshall Clow // S s5 { s, 5 };
30800259c9SMarshall Clow S sNot { "def", 3 };
31800259c9SMarshall Clow
32800259c9SMarshall Clow LIBCPP_ASSERT_NOEXCEPT(s0.ends_with(""));
33800259c9SMarshall Clow
34800259c9SMarshall Clow assert ( s0.ends_with(""));
35800259c9SMarshall Clow assert (!s0.ends_with("e"));
36800259c9SMarshall Clow
37800259c9SMarshall Clow assert ( s1.ends_with(""));
38800259c9SMarshall Clow assert ( s1.ends_with("e"));
39800259c9SMarshall Clow assert (!s1.ends_with("de"));
40800259c9SMarshall Clow assert (!s1.ends_with("cde"));
41800259c9SMarshall Clow assert (!s1.ends_with("bcde"));
42800259c9SMarshall Clow assert (!s1.ends_with("abcde"));
43800259c9SMarshall Clow assert (!s1.ends_with("def"));
44800259c9SMarshall Clow
45800259c9SMarshall Clow assert ( s2.ends_with(""));
46800259c9SMarshall Clow assert ( s2.ends_with("e"));
47800259c9SMarshall Clow assert ( s2.ends_with("de"));
48800259c9SMarshall Clow assert (!s2.ends_with("cde"));
49800259c9SMarshall Clow assert (!s2.ends_with("bcde"));
50800259c9SMarshall Clow assert (!s2.ends_with("abcde"));
51800259c9SMarshall Clow assert (!s2.ends_with("def"));
52800259c9SMarshall Clow
53800259c9SMarshall Clow assert ( sNot.ends_with(""));
54800259c9SMarshall Clow assert (!sNot.ends_with("e"));
55800259c9SMarshall Clow assert (!sNot.ends_with("de"));
56800259c9SMarshall Clow assert (!sNot.ends_with("cde"));
57800259c9SMarshall Clow assert (!sNot.ends_with("bcde"));
58800259c9SMarshall Clow assert (!sNot.ends_with("abcde"));
59800259c9SMarshall Clow assert ( sNot.ends_with("def"));
60800259c9SMarshall Clow }
612df59c50SJF Bastien
62c515b652SNikolas Klauser return true;
63c515b652SNikolas Klauser }
64c515b652SNikolas Klauser
main(int,char **)65c515b652SNikolas Klauser int main(int, char**) {
66c515b652SNikolas Klauser test();
67*425620ccSNikolas Klauser static_assert(test());
68c515b652SNikolas Klauser
692df59c50SJF Bastien return 0;
70800259c9SMarshall Clow }
71