]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/string_view/literals/values-char8_t.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / string_view / literals / values-char8_t.cc
CommitLineData
46ca1dd7
TH
1// { dg-options "-fchar8_t" }
2// { dg-do run { target c++14 } }
3
8d9254fc 4// Copyright (C) 2013-2020 Free Software Foundation, Inc.
46ca1dd7
TH
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
20
21#include <experimental/string_view>
22#include <testsuite_hooks.h>
23
24void
25test01()
26{
27 using namespace std::experimental::literals::string_view_literals;
28
29 std::experimental::string_view planet = "Mercury"sv;
30#ifdef _GLIBCXX_USE_WCHAR_T
31 std::experimental::wstring_view wplanet = L"Venus"sv;
32#endif
33#ifdef _GLIBCXX_USE_CHAR8_T
34 std::experimental::u8string_view u8planet = u8"Mars"sv;
35#else
36 std::experimental::string_view u8planet = u8"Mars"sv;
37#endif
38 std::experimental::u16string_view u16planet = u"Jupiter"sv;
39 std::experimental::u32string_view u32planet = U"Saturn"sv;
40
41 VERIFY( planet == std::experimental::string_view("Mercury") );
42#ifdef _GLIBCXX_USE_WCHAR_T
43 VERIFY( wplanet == std::experimental::wstring_view(L"Venus") );
44#endif
45#ifdef _GLIBCXX_USE_CHAR8_T
46 VERIFY( u8planet == std::experimental::u8string_view(u8"Mars") );
47#else
48 VERIFY( u8planet == std::experimental::string_view(u8"Mars") );
49#endif
50 VERIFY( u16planet == std::experimental::u16string_view(u"Jupiter") );
51 VERIFY( u32planet == std::experimental::u32string_view(U"Saturn") );
52}
53
54void
55test02()
56{
57 using namespace std::experimental::literals::string_view_literals;
58
59 std::experimental::string_view planet_cratered = "Mercury\0cratered"sv;
60#ifdef _GLIBCXX_USE_WCHAR_T
61 std::experimental::wstring_view wplanet_cratered = L"Venus\0cratered"sv;
62#endif
63#ifdef _GLIBCXX_USE_CHAR8_T
64 std::experimental::u8string_view u8planet_cratered = u8"Mars\0cratered"sv;
65#else
66 std::experimental::string_view u8planet_cratered = u8"Mars\0cratered"sv;
67#endif
68 std::experimental::u16string_view u16planet_cratered = u"Jupiter\0cratered"sv;
69 std::experimental::u32string_view u32planet_cratered = U"Saturn\0cratered"sv;
70
71 VERIFY( planet_cratered ==
72 std::experimental::string_view("Mercury\0cratered", 16) );
73#ifdef _GLIBCXX_USE_WCHAR_T
74 VERIFY( wplanet_cratered ==
75 std::experimental::wstring_view(L"Venus\0cratered", 14) );
76#endif
77#ifdef _GLIBCXX_USE_CHAR8_T
78 VERIFY( u8planet_cratered ==
79 std::experimental::u8string_view(u8"Mars\0cratered", 13) );
80#else
81 VERIFY( u8planet_cratered ==
82 std::experimental::string_view(u8"Mars\0cratered", 13) );
83#endif
84 VERIFY( u16planet_cratered ==
85 std::experimental::u16string_view(u"Jupiter\0cratered", 16) );
86 VERIFY( u32planet_cratered ==
87 std::experimental::u32string_view(U"Saturn\0cratered", 15) );
88}
89
90int
91main()
92{
93 test01();
94 test02();
95}