]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/strings/string.view/string.view.modifiers/clear.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / strings / string.view / string.view.modifiers / clear.pass.cpp
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 clear() noexcept
14
15 #include <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::basic_string_view<CharT> SV;
23     {
24     SV sv1 ( s );
25     assert ( sv1.size() == len );
26     assert ( sv1.data() == s );
27
28     sv1.clear ();
29     assert ( sv1.data() == nullptr );
30     assert ( sv1.size() == 0 );
31     assert ( sv1 == SV());
32     }
33 }
34
35 #if TEST_STD_VER > 11
36 constexpr size_t test_ce ( size_t n ) {
37     typedef std::basic_string_view<char> SV;
38     SV sv1{ "ABCDEFGHIJKL", n };
39     sv1.clear();
40     return sv1.size();
41 }
42 #endif
43
44 int main () {
45     test ( "ABCDE", 5 );
46     test ( "a", 1 );
47     test ( "", 0 );
48
49     test ( L"ABCDE", 5 );
50     test ( L"a", 1 );
51     test ( L"", 0 );
52
53 #if TEST_STD_VER >= 11
54     test ( u"ABCDE", 5 );
55     test ( u"a", 1 );
56     test ( u"", 0 );
57
58     test ( U"ABCDE", 5 );
59     test ( U"a", 1 );
60     test ( U"", 0 );
61 #endif
62
63 #if TEST_STD_VER > 11
64     static_assert ( test_ce (5) == 0, "" );
65 #endif
66
67 }