(self)
| 200 | self.assertEqual('aa'.replace('a', 'b', 3), 'aa'.replace('a', 'b', count=3)) |
| 201 | |
| 202 | def test_find(self): |
| 203 | self.checkequal(0, 'abcdefghiabc', 'find', 'abc') |
| 204 | self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1) |
| 205 | self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4) |
| 206 | |
| 207 | self.checkequal(0, 'abc', 'find', '', 0) |
| 208 | self.checkequal(3, 'abc', 'find', '', 3) |
| 209 | self.checkequal(-1, 'abc', 'find', '', 4) |
| 210 | |
| 211 | # to check the ability to pass None as defaults |
| 212 | self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a') |
| 213 | self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4) |
| 214 | self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6) |
| 215 | self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None) |
| 216 | self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6) |
| 217 | |
| 218 | self.checkraises(TypeError, 'hello', 'find') |
| 219 | |
| 220 | if self.contains_bytes: |
| 221 | self.checkequal(-1, 'hello', 'find', 42) |
| 222 | else: |
| 223 | self.checkraises(TypeError, 'hello', 'find', 42) |
| 224 | |
| 225 | self.checkequal(0, '', 'find', '') |
| 226 | self.checkequal(-1, '', 'find', '', 1, 1) |
| 227 | self.checkequal(-1, '', 'find', '', sys.maxsize, 0) |
| 228 | |
| 229 | self.checkequal(-1, '', 'find', 'xx') |
| 230 | self.checkequal(-1, '', 'find', 'xx', 1, 1) |
| 231 | self.checkequal(-1, '', 'find', 'xx', sys.maxsize, 0) |
| 232 | |
| 233 | # issue 7458 |
| 234 | self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0) |
| 235 | |
| 236 | # For a variety of combinations, |
| 237 | # verify that str.find() matches __contains__ |
| 238 | # and that the found substring is really at that location |
| 239 | teststrings = self._get_teststrings(['', 'a', 'b', 'c'], 5) |
| 240 | for i in teststrings: |
| 241 | for j in teststrings: |
| 242 | loc = i.find(j) |
| 243 | r1 = (loc != -1) |
| 244 | r2 = j in i |
| 245 | self.assertEqual(r1, r2) |
| 246 | if loc != -1: |
| 247 | self.assertEqual(i[loc:loc+len(j)], j) |
| 248 | |
| 249 | def test_rfind(self): |
| 250 | self.checkequal(9, 'abcdefghiabc', 'rfind', 'abc') |
nothing calls this directly
no test coverage detected