(self)
| 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', '') |
nothing calls this directly
no test coverage detected