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 //===----------------------------------------------------------------------===//
8
9
10 // <string_view>
11
12 // void remove_suffix(size_type _n)
13
14 #include <string_view>
15 #include <cassert>
16
17 #include "test_macros.h"
18
19 template<typename CharT>
test(const CharT * s,size_t len)20 void test ( const CharT *s, size_t len ) {
21 typedef std::basic_string_view<CharT> SV;
22 {
23 SV sv1 ( s );
24 assert ( sv1.size() == len );
25 assert ( sv1.data() == s );
26
27 if ( len > 0 ) {
28 sv1.remove_suffix ( 1 );
29 assert ( sv1.size() == (len - 1));
30 assert ( sv1.data() == s);
31 sv1.remove_suffix ( len - 1 );
32 }
33
34 assert ( sv1.size() == 0 );
35 sv1.remove_suffix ( 0 );
36 assert ( sv1.size() == 0 );
37 }
38
39 }
40
41 #if TEST_STD_VER > 11
test_ce(size_t n,size_t k)42 constexpr 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();
47 }
48 #endif
49
main(int,char **)50 int main(int, char**) {
51 test ( "ABCDE", 5 );
52 test ( "a", 1 );
53 test ( "", 0 );
54
55 test ( L"ABCDE", 5 );
56 test ( L"a", 1 );
57 test ( L"", 0 );
58
59 #if TEST_STD_VER >= 11
60 test ( u"ABCDE", 5 );
61 test ( u"a", 1 );
62 test ( u"", 0 );
63
64 test ( U"ABCDE", 5 );
65 test ( U"a", 1 );
66 test ( U"", 0 );
67 #endif
68
69 #if TEST_STD_VER > 11
70 {
71 static_assert ( test_ce ( 5, 0 ) == 5, "" );
72 static_assert ( test_ce ( 5, 1 ) == 4, "" );
73 static_assert ( test_ce ( 5, 5 ) == 0, "" );
74 static_assert ( test_ce ( 9, 3 ) == 6, "" );
75 }
76 #endif
77
78 return 0;
79 }
80