[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / string.view / string.view.find / rfind_pointer_size.pass.cpp
blob691fab4d5d0b73a860d8bdb356f533a1cd758bfa
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <string_view>
10 // constexpr size_type rfind(const charT* s, size_type pos = npos) const;
12 #include <string_view>
13 #include <cassert>
15 #include "test_macros.h"
16 #include "constexpr_char_traits.h"
18 template <class S>
19 void
20 test(const S& s, const typename S::value_type* str, typename S::size_type pos,
21 typename S::size_type x)
23 assert(s.rfind(str, pos) == x);
24 if (x != S::npos)
26 typename S::size_type n = S::traits_type::length(str);
27 assert(x <= pos && x + n <= s.size());
31 template <class S>
32 void
33 test(const S& s, const typename S::value_type* str, typename S::size_type x)
35 assert(s.rfind(str) == x);
36 if (x != S::npos)
38 typename S::size_type pos = s.size();
39 typename S::size_type n = S::traits_type::length(str);
40 assert(x <= pos && x + n <= s.size());
44 template <class S>
45 void test0()
47 test(S(""), "", 0, 0);
48 test(S(""), "abcde", 0, S::npos);
49 test(S(""), "abcdeabcde", 0, S::npos);
50 test(S(""), "abcdeabcdeabcdeabcde", 0, S::npos);
51 test(S(""), "", 1, 0);
52 test(S(""), "abcde", 1, S::npos);
53 test(S(""), "abcdeabcde", 1, S::npos);
54 test(S(""), "abcdeabcdeabcdeabcde", 1, S::npos);
55 test(S("abcde"), "", 0, 0);
56 test(S("abcde"), "abcde", 0, 0);
57 test(S("abcde"), "abcdeabcde", 0, S::npos);
58 test(S("abcde"), "abcdeabcdeabcdeabcde", 0, S::npos);
59 test(S("abcde"), "", 1, 1);
60 test(S("abcde"), "abcde", 1, 0);
61 test(S("abcde"), "abcdeabcde", 1, S::npos);
62 test(S("abcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
63 test(S("abcde"), "", 2, 2);
64 test(S("abcde"), "abcde", 2, 0);
65 test(S("abcde"), "abcdeabcde", 2, S::npos);
66 test(S("abcde"), "abcdeabcdeabcdeabcde", 2, S::npos);
67 test(S("abcde"), "", 4, 4);
68 test(S("abcde"), "abcde", 4, 0);
69 test(S("abcde"), "abcdeabcde", 4, S::npos);
70 test(S("abcde"), "abcdeabcdeabcdeabcde", 4, S::npos);
71 test(S("abcde"), "", 5, 5);
72 test(S("abcde"), "abcde", 5, 0);
73 test(S("abcde"), "abcdeabcde", 5, S::npos);
74 test(S("abcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
75 test(S("abcde"), "", 6, 5);
76 test(S("abcde"), "abcde", 6, 0);
77 test(S("abcde"), "abcdeabcde", 6, S::npos);
78 test(S("abcde"), "abcdeabcdeabcdeabcde", 6, S::npos);
79 test(S("abcdeabcde"), "", 0, 0);
80 test(S("abcdeabcde"), "abcde", 0, 0);
81 test(S("abcdeabcde"), "abcdeabcde", 0, 0);
82 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, S::npos);
83 test(S("abcdeabcde"), "", 1, 1);
84 test(S("abcdeabcde"), "abcde", 1, 0);
85 test(S("abcdeabcde"), "abcdeabcde", 1, 0);
86 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
87 test(S("abcdeabcde"), "", 5, 5);
88 test(S("abcdeabcde"), "abcde", 5, 5);
89 test(S("abcdeabcde"), "abcdeabcde", 5, 0);
90 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
91 test(S("abcdeabcde"), "", 9, 9);
92 test(S("abcdeabcde"), "abcde", 9, 5);
93 test(S("abcdeabcde"), "abcdeabcde", 9, 0);
94 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, S::npos);
95 test(S("abcdeabcde"), "", 10, 10);
96 test(S("abcdeabcde"), "abcde", 10, 5);
97 test(S("abcdeabcde"), "abcdeabcde", 10, 0);
98 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, S::npos);
99 test(S("abcdeabcde"), "", 11, 10);
100 test(S("abcdeabcde"), "abcde", 11, 5);
101 test(S("abcdeabcde"), "abcdeabcde", 11, 0);
102 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, S::npos);
103 test(S("abcdeabcdeabcdeabcde"), "", 0, 0);
104 test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 0);
105 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 0);
106 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 0);
107 test(S("abcdeabcdeabcdeabcde"), "", 1, 1);
108 test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 0);
109 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 0);
110 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 0);
111 test(S("abcdeabcdeabcdeabcde"), "", 10, 10);
112 test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 10);
113 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 10);
114 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 0);
115 test(S("abcdeabcdeabcdeabcde"), "", 19, 19);
116 test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 15);
117 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 10);
118 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 0);
119 test(S("abcdeabcdeabcdeabcde"), "", 20, 20);
120 test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 15);
121 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10);
122 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0);
123 test(S("abcdeabcdeabcdeabcde"), "", 21, 20);
124 test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 15);
125 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 10);
126 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 0);
129 template <class S>
130 void test1()
132 test(S(""), "", 0);
133 test(S(""), "abcde", S::npos);
134 test(S(""), "abcdeabcde", S::npos);
135 test(S(""), "abcdeabcdeabcdeabcde", S::npos);
136 test(S("abcde"), "", 5);
137 test(S("abcde"), "abcde", 0);
138 test(S("abcde"), "abcdeabcde", S::npos);
139 test(S("abcde"), "abcdeabcdeabcdeabcde", S::npos);
140 test(S("abcdeabcde"), "", 10);
141 test(S("abcdeabcde"), "abcde", 5);
142 test(S("abcdeabcde"), "abcdeabcde", 0);
143 test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", S::npos);
144 test(S("abcdeabcdeabcdeabcde"), "", 20);
145 test(S("abcdeabcdeabcdeabcde"), "abcde", 15);
146 test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10);
147 test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0);
150 int main(int, char**)
153 typedef std::string_view S;
154 test0<S>();
155 test1<S>();
158 #if TEST_STD_VER > 11
160 typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
161 constexpr SV sv1;
162 constexpr SV sv2 { "abcde", 5 };
164 static_assert (sv1.rfind( "") == 0, "" );
165 static_assert (sv1.rfind( "abcde") == SV::npos, "" );
166 static_assert (sv2.rfind( "") == 5, "" );
167 static_assert (sv2.rfind( "abcde") == 0, "" );
168 static_assert (sv2.rfind( "abcde", 1) == 0, "" );
170 #endif
172 return 0;