MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_rfind

Method test_rfind

Lib/test/string_tests.py:220–271  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

218 self.assertEqual(i[loc:loc+len(j)], j)
219
220 def test_rfind(self):
221 self.checkequal(9, 'abcdefghiabc', 'rfind', 'abc')
222 self.checkequal(12, 'abcdefghiabc', 'rfind', '')
223 self.checkequal(0, 'abcdefghiabc', 'rfind', 'abcd')
224 self.checkequal(-1, 'abcdefghiabc', 'rfind', 'abcz')
225
226 self.checkequal(3, 'abc', 'rfind', '', 0)
227 self.checkequal(3, 'abc', 'rfind', '', 3)
228 self.checkequal(-1, 'abc', 'rfind', '', 4)
229
230 # to check the ability to pass None as defaults
231 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a')
232 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4)
233 self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6)
234 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None)
235 self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6)
236
237 self.checkraises(TypeError, 'hello', 'rfind')
238
239 if self.contains_bytes:
240 self.checkequal(-1, 'hello', 'rfind', 42)
241 else:
242 self.checkraises(TypeError, 'hello', 'rfind', 42)
243
244 # For a variety of combinations,
245 # verify that str.rfind() matches __contains__
246 # and that the found substring is really at that location
247 charset = ['', 'a', 'b', 'c']
248 digits = 5
249 base = len(charset)
250 teststrings = set()
251 for i in range(base ** digits):
252 entry = []
253 for j in range(digits):
254 i, m = divmod(i, base)
255 entry.append(charset[m])
256 teststrings.add(''.join(entry))
257 teststrings = [self.fixtype(ts) for ts in teststrings]
258 for i in teststrings:
259 for j in teststrings:
260 loc = i.rfind(j)
261 r1 = (loc != -1)
262 r2 = j in i
263 self.assertEqual(r1, r2)
264 if loc != -1:
265 self.assertEqual(i[loc:loc+len(j)], j)
266
267 # issue 7458
268 self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0)
269
270 # issue #15534
271 self.checkequal(0, '<......\u043c...', "rfind", "<")
272
273 def test_index(self):
274 self.checkequal(0, 'abcdefghiabc', 'index', '')

Callers

nothing calls this directly

Calls 11

checkequalMethod · 0.95
checkraisesMethod · 0.95
fixtypeMethod · 0.95
lenFunction · 0.85
setFunction · 0.85
divmodFunction · 0.50
appendMethod · 0.45
addMethod · 0.45
joinMethod · 0.45
rfindMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected