73 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <string>11 12// constexpr bool ends_with(const CharT *x) const;13 14#include <string>15#include <cassert>16 17#include "test_macros.h"18 19template <class S>20constexpr void test_string() {21 const char* s = "abcde";22 23 S s0;24 S s1{s + 4, 1};25 S s2{s + 3, 2};26 // S s3 { s + 2, 3 };27 // S s4 { s + 1, 4 };28 // S s5 { s, 5 };29 S sNot{"def", 3};30 31 LIBCPP_ASSERT_NOEXCEPT(s0.ends_with(""));32 33 assert(s0.ends_with(""));34 assert(!s0.ends_with("e"));35 36 assert(s1.ends_with(""));37 assert(s1.ends_with("e"));38 assert(!s1.ends_with("de"));39 assert(!s1.ends_with("cde"));40 assert(!s1.ends_with("bcde"));41 assert(!s1.ends_with("abcde"));42 assert(!s1.ends_with("def"));43 44 assert(s2.ends_with(""));45 assert(s2.ends_with("e"));46 assert(s2.ends_with("de"));47 assert(!s2.ends_with("cde"));48 assert(!s2.ends_with("bcde"));49 assert(!s2.ends_with("abcde"));50 assert(!s2.ends_with("def"));51 52 assert(sNot.ends_with(""));53 assert(!sNot.ends_with("e"));54 assert(!sNot.ends_with("de"));55 assert(!sNot.ends_with("cde"));56 assert(!sNot.ends_with("bcde"));57 assert(!sNot.ends_with("abcde"));58 assert(sNot.ends_with("def"));59}60 61constexpr bool test() {62 test_string<std::string>();63 64 return true;65}66 67int main(int, char**) {68 test();69 static_assert(test());70 71 return 0;72}73