]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string_view / literals / values.cc
CommitLineData
6458742a 1// { dg-do run { target c++17 } }
17018005 2
83ffe9cd 3// Copyright (C) 2013-2023 Free Software Foundation, Inc.
17018005
VV
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
102a4fe1
JW
23#ifdef _GLIBCXX_USE_CHAR8_T
24using std::u8string_view;
25#else
26using u8string_view = std::string_view;
27#endif
28
17018005
VV
29void
30test01()
31{
32 using namespace std::literals::string_view_literals;
33
34 std::string_view planet = "Mercury"sv;
17018005 35 std::wstring_view wplanet = L"Venus"sv;
102a4fe1 36 u8string_view u8planet = u8"Mars"sv;
17018005
VV
37 std::u16string_view u16planet = u"Jupiter"sv;
38 std::u32string_view u32planet = U"Saturn"sv;
39
40 VERIFY( planet == std::string_view("Mercury") );
17018005 41 VERIFY( wplanet == std::wstring_view(L"Venus") );
102a4fe1 42 VERIFY( u8planet == u8string_view(u8"Mars") );
17018005
VV
43 VERIFY( u16planet == std::u16string_view(u"Jupiter") );
44 VERIFY( u32planet == std::u32string_view(U"Saturn") );
45}
46
47void
48test02()
49{
50 using namespace std::literals::string_view_literals;
51
52 std::string_view planet_cratered = "Mercury\0cratered"sv;
17018005 53 std::wstring_view wplanet_cratered = L"Venus\0cratered"sv;
102a4fe1 54 u8string_view u8planet_cratered = u8"Mars\0cratered"sv;
17018005
VV
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) );
17018005 59 VERIFY( wplanet_cratered == std::wstring_view(L"Venus\0cratered", 14) );
102a4fe1 60 VERIFY( u8planet_cratered == u8string_view(u8"Mars\0cratered", 13) );
17018005
VV
61 VERIFY( u16planet_cratered == std::u16string_view(u"Jupiter\0cratered", 16) );
62 VERIFY( u32planet_cratered == std::u32string_view(U"Saturn\0cratered", 15) );
63}
64
65int
66main()
67{
68 test01();
69 test02();
70}