]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc
libstdc++: Ensure c++NN effective target present in all C++17 tests
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string_view / literals / values.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do run { target c++17 } }
3
4 // Copyright (C) 2013-2020 Free Software Foundation, Inc.
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 <string_view>
22 #include <testsuite_hooks.h>
23
24 #ifdef _GLIBCXX_USE_CHAR8_T
25 using std::u8string_view;
26 #else
27 using u8string_view = std::string_view;
28 #endif
29
30 void
31 test01()
32 {
33 using namespace std::literals::string_view_literals;
34
35 std::string_view planet = "Mercury"sv;
36 #ifdef _GLIBCXX_USE_WCHAR_T
37 std::wstring_view wplanet = L"Venus"sv;
38 #endif
39 u8string_view u8planet = u8"Mars"sv;
40 std::u16string_view u16planet = u"Jupiter"sv;
41 std::u32string_view u32planet = U"Saturn"sv;
42
43 VERIFY( planet == std::string_view("Mercury") );
44 #ifdef _GLIBCXX_USE_WCHAR_T
45 VERIFY( wplanet == std::wstring_view(L"Venus") );
46 #endif
47 VERIFY( u8planet == u8string_view(u8"Mars") );
48 VERIFY( u16planet == std::u16string_view(u"Jupiter") );
49 VERIFY( u32planet == std::u32string_view(U"Saturn") );
50 }
51
52 void
53 test02()
54 {
55 using namespace std::literals::string_view_literals;
56
57 std::string_view planet_cratered = "Mercury\0cratered"sv;
58 #ifdef _GLIBCXX_USE_WCHAR_T
59 std::wstring_view wplanet_cratered = L"Venus\0cratered"sv;
60 #endif
61 u8string_view u8planet_cratered = u8"Mars\0cratered"sv;
62 std::u16string_view u16planet_cratered = u"Jupiter\0cratered"sv;
63 std::u32string_view u32planet_cratered = U"Saturn\0cratered"sv;
64
65 VERIFY( planet_cratered == std::string_view("Mercury\0cratered", 16) );
66 #ifdef _GLIBCXX_USE_WCHAR_T
67 VERIFY( wplanet_cratered == std::wstring_view(L"Venus\0cratered", 14) );
68 #endif
69 VERIFY( u8planet_cratered == u8string_view(u8"Mars\0cratered", 13) );
70 VERIFY( u16planet_cratered == std::u16string_view(u"Jupiter\0cratered", 16) );
71 VERIFY( u32planet_cratered == std::u32string_view(U"Saturn\0cratered", 15) );
72 }
73
74 int
75 main()
76 {
77 test01();
78 test02();
79 }