]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/rfind.cc
varasm.c (assemble_constructor): Take a symbol_ref and a priority instead of a bare...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / rfind.cc
CommitLineData
913c27bf
BV
1// 2000-06-22 -=dbv=- (shamelessy copied from bkoz' find.cc)
2
3// Copyright (C) 2000 Free Software Foundation, Inc.
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 2, 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 COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21#include <string>
22#include <stdexcept>
aa1b2f7d 23#include <debug_assert.h>
913c27bf
BV
24
25// 21.3.6.2 basic_string rfind
26bool test01(void)
27{
28 bool test = true;
29 typedef std::string::size_type csize_type;
30 typedef std::string::const_reference cref;
31 typedef std::string::reference ref;
32 csize_type npos = std::string::npos;
33 csize_type csz01, csz02;
34
35 const char str_lit01[] = "mave";
36 const std::string str01("mavericks, santa cruz");
37 std::string str02(str_lit01);
38 std::string str03("s, s");
39 std::string str04;
40
41 // size_type rfind(const string&, size_type pos = 0) const;
42 csz01 = str01.rfind(str01);
aa1b2f7d 43 VERIFY( csz01 == 0 );
913c27bf 44 csz01 = str01.rfind(str01, 4);
aa1b2f7d 45 VERIFY( csz01 == 0 );
913c27bf 46 csz01 = str01.rfind(str02,3);
aa1b2f7d 47 VERIFY( csz01 == 0 );
913c27bf 48 csz01 = str01.rfind(str02);
aa1b2f7d 49 VERIFY( csz01 == 0 );
913c27bf 50 csz01 = str01.rfind(str03);
aa1b2f7d 51 VERIFY( csz01 == 8 );
913c27bf 52 csz01 = str01.rfind(str03, 3);
aa1b2f7d 53 VERIFY( csz01 == npos );
913c27bf 54 csz01 = str01.rfind(str03, 12);
aa1b2f7d 55 VERIFY( csz01 == 8 );
913c27bf
BV
56
57 // An empty string consists of no characters
58 // therefore it should be found at every point in a string,
59 // except beyond the end
60 csz01 = str01.rfind(str04, 0);
aa1b2f7d 61 VERIFY( csz01 == 0 );
913c27bf 62 csz01 = str01.rfind(str04, 5);
aa1b2f7d 63 VERIFY( csz01 == 5 );
913c27bf 64 csz01 = str01.rfind(str04, str01.size());
aa1b2f7d 65 VERIFY( csz01 == str01.size() );
913c27bf 66 csz01 = str01.rfind(str04, str01.size()+1);
aa1b2f7d 67 VERIFY( csz01 == str01.size() );
913c27bf
BV
68
69 // size_type rfind(const char* s, size_type pos, size_type n) const;
70 csz01 = str01.rfind(str_lit01, 0, 3);
aa1b2f7d 71 VERIFY( csz01 == 0 );
913c27bf 72 csz01 = str01.rfind(str_lit01, 3, 0);
aa1b2f7d 73 VERIFY( csz01 == 3 );
913c27bf
BV
74
75 // size_type rfind(const char* s, size_type pos = 0) const;
76 csz01 = str01.rfind(str_lit01);
aa1b2f7d 77 VERIFY( csz01 == 0 );
913c27bf 78 csz01 = str01.rfind(str_lit01, 3);
aa1b2f7d 79 VERIFY( csz01 == 0 );
913c27bf
BV
80
81 // size_type rfind(char c, size_type pos = 0) const;
82 csz01 = str01.rfind('z');
83 csz02 = str01.size() - 1;
aa1b2f7d 84 VERIFY( csz01 == csz02 );
913c27bf 85 csz01 = str01.rfind('/');
aa1b2f7d 86 VERIFY( csz01 == npos );
913c27bf
BV
87
88#ifdef DEBUG_ASSERT
89 assert(test);
90#endif
91 return test;
92}
93
94// 21.3.6.4 basic_string::find_last_of
95bool test02()
96{
97 bool test = true;
98
99 // test find_last_of
100
101#ifdef DEBUG_ASSERT
102 assert(test);
103#endif
104 return test;
105}
106
107// 21.3.6.6 basic_string::find_last_not_of
108bool test03()
109{
110 bool test = true;
111
112 // test find_last_not_of
113
114#ifdef DEBUG_ASSERT
115 assert(test);
116#endif
117 return test;
118}
119int main()
120{
121 test01();
122 test02();
123 test03();
04d930e6 124 return 0;
913c27bf 125}