brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · b6edccc Raw
83 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: !stdlib=libc++ && (c++03 || c++11 || c++14)10 11// <string_view>12 13// void remove_suffix(size_type _n)14 15#include <cassert>16#include <cstddef>17#include <string_view>18 19#include "test_macros.h"20 21template <typename CharT>22void test(const CharT* s, std::size_t len) {23  typedef std::basic_string_view<CharT> SV;24  {25    SV sv1(s);26    assert(sv1.size() == len);27    assert(sv1.data() == s);28 29    if (len > 0) {30      sv1.remove_suffix(1);31      assert(sv1.size() == (len - 1));32      assert(sv1.data() == s);33      sv1.remove_suffix(len - 1);34    }35 36    assert(sv1.size() == 0);37    sv1.remove_suffix(0);38    assert(sv1.size() == 0);39  }40}41 42#if TEST_STD_VER > 1143constexpr std::size_t test_ce(size_t n, size_t k) {44  typedef std::basic_string_view<char> SV;45  SV sv1{"ABCDEFGHIJKL", n};46  sv1.remove_suffix(k);47  return sv1.size();48}49#endif50 51int main(int, char**) {52  test("ABCDE", 5);53  test("a", 1);54  test("", 0);55 56#ifndef TEST_HAS_NO_WIDE_CHARACTERS57  test(L"ABCDE", 5);58  test(L"a", 1);59  test(L"", 0);60#endif61 62#if TEST_STD_VER >= 1163  test(u"ABCDE", 5);64  test(u"a", 1);65  test(u"", 0);66 67  test(U"ABCDE", 5);68  test(U"a", 1);69  test(U"", 0);70#endif71 72#if TEST_STD_VER > 1173  {74    static_assert(test_ce(5, 0) == 5, "");75    static_assert(test_ce(5, 1) == 4, "");76    static_assert(test_ce(5, 5) == 0, "");77    static_assert(test_ce(9, 3) == 6, "");78  }79#endif80 81  return 0;82}83