brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 94582ad 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 starts_with(string_view x) const noexcept;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, 1};27    SV sv2{s, 2};28    SV svNot{"def", 3};29 30    LIBCPP_ASSERT_NOEXCEPT(sv0.starts_with(""));31 32    assert(sv0.starts_with(""));33    assert(!sv0.starts_with("a"));34 35    assert(sv1.starts_with(""));36    assert(sv1.starts_with("a"));37    assert(!sv1.starts_with("ab"));38    assert(!sv1.starts_with("abc"));39    assert(!sv1.starts_with("abcd"));40    assert(!sv1.starts_with("abcde"));41    assert(!sv1.starts_with("def"));42 43    assert(sv2.starts_with(s + 5));44    assert(sv2.starts_with("a"));45    assert(sv2.starts_with("ab"));46    assert(!sv2.starts_with("abc"));47    assert(!sv2.starts_with("abcd"));48    assert(!sv2.starts_with("abcde"));49    assert(!sv2.starts_with("def"));50 51    assert(svNot.starts_with(""));52    assert(!svNot.starts_with("a"));53    assert(!svNot.starts_with("ab"));54    assert(!svNot.starts_with("abc"));55    assert(!svNot.starts_with("abcd"));56    assert(!svNot.starts_with("abcde"));57    assert(svNot.starts_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, 1};66    constexpr SV sv2{s, 2};67    constexpr SV svNot{"def", 3};68 69    static_assert(sv0.starts_with(""), "");70    static_assert(!sv0.starts_with("a"), "");71 72    static_assert(sv1.starts_with(""), "");73    static_assert(sv1.starts_with("a"), "");74    static_assert(!sv1.starts_with("ab"), "");75    static_assert(!sv1.starts_with("abc"), "");76    static_assert(!sv1.starts_with("abcd"), "");77    static_assert(!sv1.starts_with("abcde"), "");78    static_assert(!sv1.starts_with("def"), "");79 80    static_assert(sv2.starts_with(s + 5), "");81    static_assert(sv2.starts_with("a"), "");82    static_assert(sv2.starts_with("ab"), "");83    static_assert(!sv2.starts_with("abc"), "");84    static_assert(!sv2.starts_with("abcd"), "");85    static_assert(!sv2.starts_with("abcde"), "");86    static_assert(!sv2.starts_with("def"), "");87 88    static_assert(svNot.starts_with(""), "");89    static_assert(!svNot.starts_with("a"), "");90    static_assert(!svNot.starts_with("ab"), "");91    static_assert(!svNot.starts_with("abc"), "");92    static_assert(!svNot.starts_with("abcd"), "");93    static_assert(!svNot.starts_with("abcde"), "");94    static_assert(svNot.starts_with("def"), "");95  }96#endif97 98  return 0;99}100