]>
Commit | Line | Data |
---|---|---|
fdc11678 SM |
1 | // { dg-options "-std=gnu++17" } |
2 | ||
42a4f53d | 3 | // Copyright (C) 2013-2019 Free Software Foundation, Inc. |
fdc11678 SM |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING3. If not see | |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
20 | #include <string_view> | |
21 | #include <testsuite_hooks.h> | |
22 | ||
23 | void | |
24 | test01() | |
25 | { | |
26 | using namespace std::literals::string_view_literals; | |
27 | ||
28 | std::string_view planet = "Mercury"sv; | |
29 | #ifdef _GLIBCXX_USE_WCHAR_T | |
30 | std::wstring_view wplanet = L"Venus"sv; | |
31 | #endif | |
32 | std::string_view u8planet = u8"Mars"sv; | |
33 | std::u16string_view u16planet = u"Jupiter"sv; | |
34 | std::u32string_view u32planet = U"Saturn"sv; | |
35 | ||
36 | VERIFY( planet == std::string_view("Mercury") ); | |
37 | #ifdef _GLIBCXX_USE_WCHAR_T | |
38 | VERIFY( wplanet == std::wstring_view(L"Venus") ); | |
39 | #endif | |
40 | VERIFY( u8planet == std::string_view(u8"Mars") ); | |
41 | VERIFY( u16planet == std::u16string_view(u"Jupiter") ); | |
42 | VERIFY( u32planet == std::u32string_view(U"Saturn") ); | |
43 | } | |
44 | ||
45 | void | |
46 | test02() | |
47 | { | |
48 | using namespace std::literals::string_view_literals; | |
49 | ||
50 | std::string_view planet_cratered = "Mercury\0cratered"sv; | |
51 | #ifdef _GLIBCXX_USE_WCHAR_T | |
52 | std::wstring_view wplanet_cratered = L"Venus\0cratered"sv; | |
53 | #endif | |
54 | std::string_view u8planet_cratered = u8"Mars\0cratered"sv; | |
55 | std::u16string_view u16planet_cratered = u"Jupiter\0cratered"sv; | |
56 | std::u32string_view u32planet_cratered = U"Saturn\0cratered"sv; | |
57 | ||
58 | VERIFY( planet_cratered == std::string_view("Mercury\0cratered", 16) ); | |
59 | #ifdef _GLIBCXX_USE_WCHAR_T | |
60 | VERIFY( wplanet_cratered == std::wstring_view(L"Venus\0cratered", 14) ); | |
61 | #endif | |
62 | VERIFY( u8planet_cratered == std::string_view(u8"Mars\0cratered", 13) ); | |
63 | VERIFY( u16planet_cratered == std::u16string_view(u"Jupiter\0cratered", 16) ); | |
64 | VERIFY( u32planet_cratered == std::u32string_view(U"Saturn\0cratered", 15) ); | |
65 | } | |
66 | ||
67 | int | |
68 | main() | |
69 | { | |
70 | test01(); | |
71 | test02(); | |
72 | } |