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