(self)
| 247 | self.assertEqual(i[loc:loc+len(j)], j) |
| 248 | |
| 249 | def test_rfind(self): |
| 250 | self.checkequal(9, 'abcdefghiabc', 'rfind', 'abc') |
| 251 | self.checkequal(12, 'abcdefghiabc', 'rfind', '') |
| 252 | self.checkequal(0, 'abcdefghiabc', 'rfind', 'abcd') |
| 253 | self.checkequal(-1, 'abcdefghiabc', 'rfind', 'abcz') |
| 254 | |
| 255 | self.checkequal(3, 'abc', 'rfind', '', 0) |
| 256 | self.checkequal(3, 'abc', 'rfind', '', 3) |
| 257 | self.checkequal(-1, 'abc', 'rfind', '', 4) |
| 258 | |
| 259 | # to check the ability to pass None as defaults |
| 260 | self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a') |
| 261 | self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4) |
| 262 | self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6) |
| 263 | self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None) |
| 264 | self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6) |
| 265 | |
| 266 | self.checkraises(TypeError, 'hello', 'rfind') |
| 267 | |
| 268 | if self.contains_bytes: |
| 269 | self.checkequal(-1, 'hello', 'rfind', 42) |
| 270 | else: |
| 271 | self.checkraises(TypeError, 'hello', 'rfind', 42) |
| 272 | |
| 273 | # For a variety of combinations, |
| 274 | # verify that str.rfind() matches __contains__ |
| 275 | # and that the found substring is really at that location |
| 276 | teststrings = self._get_teststrings(['', 'a', 'b', 'c'], 5) |
| 277 | for i in teststrings: |
| 278 | for j in teststrings: |
| 279 | loc = i.rfind(j) |
| 280 | r1 = (loc != -1) |
| 281 | r2 = j in i |
| 282 | self.assertEqual(r1, r2) |
| 283 | if loc != -1: |
| 284 | self.assertEqual(i[loc:loc+len(j)], j) |
| 285 | |
| 286 | # issue 7458 |
| 287 | self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0) |
| 288 | |
| 289 | # issue #15534 |
| 290 | self.checkequal(0, '<......\u043c...', "rfind", "<") |
| 291 | |
| 292 | def test_index(self): |
| 293 | self.checkequal(0, 'abcdefghiabc', 'index', '') |
nothing calls this directly
no test coverage detected