brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 27897d0 Raw
100 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 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// <string_view>12 13//   constexpr bool ends_with(const CharT *x) const;14 15#include <string_view>16#include <cassert>17 18#include "test_macros.h"19#include "constexpr_char_traits.h"20 21int main(int, char**) {22  {23    typedef std::string_view SV;24    const char* s = "abcde";25    SV sv0{};26    SV sv1{s + 4, 1};27    SV sv2{s + 3, 2};28    SV svNot{"def", 3};29 30    LIBCPP_ASSERT_NOEXCEPT(sv0.ends_with(""));31 32    assert(sv0.ends_with(""));33    assert(!sv0.ends_with("e"));34 35    assert(sv1.ends_with(""));36    assert(sv1.ends_with("e"));37    assert(!sv1.ends_with("de"));38    assert(!sv1.ends_with("cde"));39    assert(!sv1.ends_with("bcde"));40    assert(!sv1.ends_with("abcde"));41    assert(!sv1.ends_with("def"));42 43    assert(sv2.ends_with(""));44    assert(sv2.ends_with("e"));45    assert(sv2.ends_with("de"));46    assert(!sv2.ends_with("cde"));47    assert(!sv2.ends_with("bcde"));48    assert(!sv2.ends_with("abcde"));49    assert(!sv2.ends_with("def"));50 51    assert(svNot.ends_with(""));52    assert(!svNot.ends_with("e"));53    assert(!svNot.ends_with("de"));54    assert(!svNot.ends_with("cde"));55    assert(!svNot.ends_with("bcde"));56    assert(!svNot.ends_with("abcde"));57    assert(svNot.ends_with("def"));58  }59 60#if TEST_STD_VER > 1161  {62    typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;63    constexpr const char* s = "abcde";64    constexpr SV sv0{};65    constexpr SV sv1{s + 4, 1};66    constexpr SV sv2{s + 3, 2};67    constexpr SV svNot{"def", 3};68 69    static_assert(sv0.ends_with(""), "");70    static_assert(!sv0.ends_with("e"), "");71 72    static_assert(sv1.ends_with(""), "");73    static_assert(sv1.ends_with("e"), "");74    static_assert(!sv1.ends_with("de"), "");75    static_assert(!sv1.ends_with("cde"), "");76    static_assert(!sv1.ends_with("bcde"), "");77    static_assert(!sv1.ends_with("abcde"), "");78    static_assert(!sv1.ends_with("def"), "");79 80    static_assert(sv2.ends_with(""), "");81    static_assert(sv2.ends_with("e"), "");82    static_assert(sv2.ends_with("de"), "");83    static_assert(!sv2.ends_with("cde"), "");84    static_assert(!sv2.ends_with("bcde"), "");85    static_assert(!sv2.ends_with("abcde"), "");86    static_assert(!sv2.ends_with("def"), "");87 88    static_assert(svNot.ends_with(""), "");89    static_assert(!svNot.ends_with("e"), "");90    static_assert(!svNot.ends_with("de"), "");91    static_assert(!svNot.ends_with("cde"), "");92    static_assert(!svNot.ends_with("bcde"), "");93    static_assert(!svNot.ends_with("abcde"), "");94    static_assert(svNot.ends_with("def"), "");95  }96#endif97 98  return 0;99}100