]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string_view / operations / rfind / wchar_t / 1.cc
CommitLineData
ca8f2cb1 1// { dg-options "-std=gnu++17" }
6458742a 2// { dg-do run { target c++17 } }
ca8f2cb1 3
99dee823 4// Copyright (C) 2013-2021 Free Software Foundation, Inc.
ca8f2cb1
VV
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// basic_string_view rfind
25
118c8424 26void
ca8f2cb1
VV
27test01()
28{
ca8f2cb1
VV
29 typedef std::wstring_view::size_type csize_type;
30 typedef std::wstring_view::const_reference cref;
31 typedef std::wstring_view::reference ref;
32 csize_type npos = std::wstring_view::npos;
33 csize_type csz01, csz02;
34
35 const wchar_t str_lit01[] = L"mave";
36 const std::wstring_view str01(L"mavericks, santa cruz");
37 std::wstring_view str02(str_lit01);
38 std::wstring_view str03(L"s, s");
39 std::wstring_view str04;
40
41 // size_type rfind(const wstring_view&, size_type pos = 0) const;
42 csz01 = str01.rfind(str01);
43 VERIFY( csz01 == 0 );
44 csz01 = str01.rfind(str01, 4);
45 VERIFY( csz01 == 0 );
46 csz01 = str01.rfind(str02,3);
47 VERIFY( csz01 == 0 );
48 csz01 = str01.rfind(str02);
49 VERIFY( csz01 == 0 );
50 csz01 = str01.rfind(str03);
51 VERIFY( csz01 == 8 );
52 csz01 = str01.rfind(str03, 3);
53 VERIFY( csz01 == npos );
54 csz01 = str01.rfind(str03, 12);
55 VERIFY( csz01 == 8 );
56
57 // An empty string_view consists of no characters
58 // therefore it should be found at every point in a string_view,
59 // except beyond the end
60 csz01 = str01.rfind(str04, 0);
61 VERIFY( csz01 == 0 );
62 csz01 = str01.rfind(str04, 5);
63 VERIFY( csz01 == 5 );
64 csz01 = str01.rfind(str04, str01.size());
65 VERIFY( csz01 == str01.size() );
66 csz01 = str01.rfind(str04, str01.size()+1);
67 VERIFY( csz01 == str01.size() );
68
69 // size_type rfind(const wchar_t* s, size_type pos, size_type n) const;
70 csz01 = str01.rfind(str_lit01, 0, 3);
71 VERIFY( csz01 == 0 );
72 csz01 = str01.rfind(str_lit01, 3, 0);
73 VERIFY( csz01 == 3 );
74
75 // size_type rfind(const wchar_t* s, size_type pos = 0) const;
76 csz01 = str01.rfind(str_lit01);
77 VERIFY( csz01 == 0 );
78 csz01 = str01.rfind(str_lit01, 3);
79 VERIFY( csz01 == 0 );
80
81 // size_type rfind(wchar_t c, size_type pos = 0) const;
82 csz01 = str01.rfind(L'z');
83 csz02 = str01.size() - 1;
84 VERIFY( csz01 == csz02 );
85 csz01 = str01.rfind(L'/');
86 VERIFY( csz01 == npos );
ca8f2cb1
VV
87}
88
89int
90main()
91{
92 test01();
93
94 return 0;
95}