1*053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2*053d81ceSMarshall Clow //
3*053d81ceSMarshall Clow //                     The LLVM Compiler Infrastructure
4*053d81ceSMarshall Clow //
5*053d81ceSMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open
6*053d81ceSMarshall Clow // Source Licenses. See LICENSE.TXT for details.
7*053d81ceSMarshall Clow //
8*053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
9*053d81ceSMarshall Clow 
10*053d81ceSMarshall Clow 
11*053d81ceSMarshall Clow // <string_view>
12*053d81ceSMarshall Clow 
13*053d81ceSMarshall Clow // void remove_prefix(size_type _n)
14*053d81ceSMarshall Clow 
15*053d81ceSMarshall Clow #include <string_view>
16*053d81ceSMarshall Clow #include <cassert>
17*053d81ceSMarshall Clow #include <iostream>
18*053d81ceSMarshall Clow 
19*053d81ceSMarshall Clow #include "test_macros.h"
20*053d81ceSMarshall Clow 
21*053d81ceSMarshall Clow template<typename CharT>
22*053d81ceSMarshall Clow void test ( const CharT *s, size_t len ) {
23*053d81ceSMarshall Clow     typedef std::basic_string_view<CharT> SV;
24*053d81ceSMarshall Clow     {
25*053d81ceSMarshall Clow     SV sv1 ( s );
26*053d81ceSMarshall Clow     assert ( sv1.size() == len );
27*053d81ceSMarshall Clow     assert ( sv1.data() == s );
28*053d81ceSMarshall Clow 
29*053d81ceSMarshall Clow     if ( len > 0 ) {
30*053d81ceSMarshall Clow         sv1.remove_prefix ( 1 );
31*053d81ceSMarshall Clow         assert ( sv1.size() == (len - 1));
32*053d81ceSMarshall Clow         assert ( sv1.data() == (s + 1));
33*053d81ceSMarshall Clow         sv1.remove_prefix ( len - 1 );
34*053d81ceSMarshall Clow     }
35*053d81ceSMarshall Clow 
36*053d81ceSMarshall Clow     assert ( sv1.size() == 0 );
37*053d81ceSMarshall Clow     sv1.remove_prefix ( 0 );
38*053d81ceSMarshall Clow     assert ( sv1.size() == 0 );
39*053d81ceSMarshall Clow     }
40*053d81ceSMarshall Clow }
41*053d81ceSMarshall Clow 
42*053d81ceSMarshall Clow #if _LIBCPP_STD_VER > 11
43*053d81ceSMarshall Clow constexpr size_t test_ce ( size_t n, size_t k ) {
44*053d81ceSMarshall Clow     typedef std::basic_string_view<char> SV;
45*053d81ceSMarshall Clow     SV sv1{ "ABCDEFGHIJKL", n };
46*053d81ceSMarshall Clow     sv1.remove_prefix ( k );
47*053d81ceSMarshall Clow     return sv1.size();
48*053d81ceSMarshall Clow }
49*053d81ceSMarshall Clow #endif
50*053d81ceSMarshall Clow 
51*053d81ceSMarshall Clow int main () {
52*053d81ceSMarshall Clow     test ( "ABCDE", 5 );
53*053d81ceSMarshall Clow     test ( "a", 1 );
54*053d81ceSMarshall Clow     test ( "", 0 );
55*053d81ceSMarshall Clow 
56*053d81ceSMarshall Clow     test ( L"ABCDE", 5 );
57*053d81ceSMarshall Clow     test ( L"a", 1 );
58*053d81ceSMarshall Clow     test ( L"", 0 );
59*053d81ceSMarshall Clow 
60*053d81ceSMarshall Clow #if TEST_STD_VER >= 11
61*053d81ceSMarshall Clow     test ( u"ABCDE", 5 );
62*053d81ceSMarshall Clow     test ( u"a", 1 );
63*053d81ceSMarshall Clow     test ( u"", 0 );
64*053d81ceSMarshall Clow 
65*053d81ceSMarshall Clow     test ( U"ABCDE", 5 );
66*053d81ceSMarshall Clow     test ( U"a", 1 );
67*053d81ceSMarshall Clow     test ( U"", 0 );
68*053d81ceSMarshall Clow #endif
69*053d81ceSMarshall Clow 
70*053d81ceSMarshall Clow #if _LIBCPP_STD_VER > 11
71*053d81ceSMarshall Clow     {
72*053d81ceSMarshall Clow     static_assert ( test_ce ( 5, 0 ) == 5, "" );
73*053d81ceSMarshall Clow     static_assert ( test_ce ( 5, 1 ) == 4, "" );
74*053d81ceSMarshall Clow     static_assert ( test_ce ( 5, 5 ) == 0, "" );
75*053d81ceSMarshall Clow     static_assert ( test_ce ( 9, 3 ) == 6, "" );
76*053d81ceSMarshall Clow     }
77*053d81ceSMarshall Clow #endif
78*053d81ceSMarshall Clow }
79