values.cc 2.3 KB

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