Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / string.view / string.view.modifiers / remove_suffix.pass.cpp
blob6d57f6c24a487740570aeb6a02bf1dd8ed83ff03
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
11 // <string_view>
13 // void remove_suffix(size_type _n)
15 #include <string_view>
16 #include <cassert>
18 #include "test_macros.h"
20 template <typename CharT>
21 void test(const CharT* s, std::size_t len) {
22 typedef std::basic_string_view<CharT> SV;
24 SV sv1(s);
25 assert(sv1.size() == len);
26 assert(sv1.data() == s);
28 if (len > 0) {
29 sv1.remove_suffix(1);
30 assert(sv1.size() == (len - 1));
31 assert(sv1.data() == s);
32 sv1.remove_suffix(len - 1);
35 assert(sv1.size() == 0);
36 sv1.remove_suffix(0);
37 assert(sv1.size() == 0);
41 #if TEST_STD_VER > 11
42 constexpr std::size_t test_ce(size_t n, size_t k) {
43 typedef std::basic_string_view<char> SV;
44 SV sv1{"ABCDEFGHIJKL", n};
45 sv1.remove_suffix(k);
46 return sv1.size();
48 #endif
50 int main(int, char**) {
51 test("ABCDE", 5);
52 test("a", 1);
53 test("", 0);
55 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
56 test(L"ABCDE", 5);
57 test(L"a", 1);
58 test(L"", 0);
59 #endif
61 #if TEST_STD_VER >= 11
62 test(u"ABCDE", 5);
63 test(u"a", 1);
64 test(u"", 0);
66 test(U"ABCDE", 5);
67 test(U"a", 1);
68 test(U"", 0);
69 #endif
71 #if TEST_STD_VER > 11
73 static_assert(test_ce(5, 0) == 5, "");
74 static_assert(test_ce(5, 1) == 4, "");
75 static_assert(test_ce(5, 5) == 0, "");
76 static_assert(test_ce(9, 3) == 6, "");
78 #endif
80 return 0;