]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string_view/operations/rfind/char/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string_view / operations / rfind / char / 1.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do run { target c++17 } }
3
4 // Copyright (C) 2013-2021 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 // basic_string_view rfind
25
26 void
27 test01()
28 {
29 typedef std::string_view::size_type csize_type;
30 typedef std::string_view::const_reference cref;
31 typedef std::string_view::reference ref;
32 csize_type npos = std::string_view::npos;
33 csize_type csz01, csz02;
34
35 const char str_lit01[] = "mave";
36 const std::string_view str01("mavericks, santa cruz");
37 std::string_view str02(str_lit01);
38 std::string_view str03("s, s");
39 std::string_view str04;
40
41 // size_type rfind(const string_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 char* 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 char* 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(char c, size_type pos = 0) const;
82 csz01 = str01.rfind('z');
83 csz02 = str01.size() - 1;
84 VERIFY( csz01 == csz02 );
85 csz01 = str01.rfind('/');
86 VERIFY( csz01 == npos );
87 }
88
89 int
90 main()
91 {
92 test01();
93
94 return 0;
95 }