Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libc++ / trunk / test / experimental / 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 <experimental/string_view>
16 #include <cassert>
17
18 template<typename CharT>
19 void test ( const CharT *s, size_t len ) {
20     typedef std::experimental::basic_string_view<CharT> SV;
21     {
22     SV sv1 ( s );
23     assert ( sv1.size() == len );
24     assert ( sv1.data() == s );
25
26     sv1.clear ();
27     assert ( sv1.data() == nullptr );
28     assert ( sv1.size() == 0 );
29     assert ( sv1 == SV());
30     }
31 }
32
33 #if _LIBCPP_STD_VER > 11
34 constexpr size_t test_ce ( size_t n ) {
35     typedef std::experimental::basic_string_view<char> SV;
36     SV sv1{ "ABCDEFGHIJKL", n };
37     sv1.clear();
38     return sv1.size();
39 }
40 #endif
41
42 int main () {
43     test ( "ABCDE", 5 );
44     test ( "a", 1 );
45     test ( "", 0 );
46
47     test ( L"ABCDE", 5 );
48     test ( L"a", 1 );
49     test ( L"", 0 );
50
51 #if __cplusplus >= 201103L
52     test ( u"ABCDE", 5 );
53     test ( u"a", 1 );
54     test ( u"", 0 );
55
56     test ( U"ABCDE", 5 );
57     test ( U"a", 1 );
58     test ( U"", 0 );
59 #endif
60
61 #if _LIBCPP_STD_VER > 11
62     static_assert ( test_ce (5) == 0, "" );
63 #endif
64
65 }