(self)
| 161 | self.assertEqual('aa'.replace('a', 'b', 3), 'aa'.replace('a', 'b', count=3)) |
| 162 | |
| 163 | def test_find(self): |
| 164 | self.checkequal(0, 'abcdefghiabc', 'find', 'abc') |
| 165 | self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1) |
| 166 | self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4) |
| 167 | |
| 168 | self.checkequal(0, 'abc', 'find', '', 0) |
| 169 | self.checkequal(3, 'abc', 'find', '', 3) |
| 170 | self.checkequal(-1, 'abc', 'find', '', 4) |
| 171 | |
| 172 | # to check the ability to pass None as defaults |
| 173 | self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a') |
| 174 | self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4) |
| 175 | self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6) |
| 176 | self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None) |
| 177 | self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6) |
| 178 | |
| 179 | self.checkraises(TypeError, 'hello', 'find') |
| 180 | |
| 181 | if self.contains_bytes: |
| 182 | self.checkequal(-1, 'hello', 'find', 42) |
| 183 | else: |
| 184 | self.checkraises(TypeError, 'hello', 'find', 42) |
| 185 | |
| 186 | self.checkequal(0, '', 'find', '') |
| 187 | self.checkequal(-1, '', 'find', '', 1, 1) |
| 188 | self.checkequal(-1, '', 'find', '', sys.maxsize, 0) |
| 189 | |
| 190 | self.checkequal(-1, '', 'find', 'xx') |
| 191 | self.checkequal(-1, '', 'find', 'xx', 1, 1) |
| 192 | self.checkequal(-1, '', 'find', 'xx', sys.maxsize, 0) |
| 193 | |
| 194 | # issue 7458 |
| 195 | self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0) |
| 196 | |
| 197 | # For a variety of combinations, |
| 198 | # verify that str.find() matches __contains__ |
| 199 | # and that the found substring is really at that location |
| 200 | charset = ['', 'a', 'b', 'c'] |
| 201 | digits = 5 |
| 202 | base = len(charset) |
| 203 | teststrings = set() |
| 204 | for i in range(base ** digits): |
| 205 | entry = [] |
| 206 | for j in range(digits): |
| 207 | i, m = divmod(i, base) |
| 208 | entry.append(charset[m]) |
| 209 | teststrings.add(''.join(entry)) |
| 210 | teststrings = [self.fixtype(ts) for ts in teststrings] |
| 211 | for i in teststrings: |
| 212 | for j in teststrings: |
| 213 | loc = i.find(j) |
| 214 | r1 = (loc != -1) |
| 215 | r2 = j in i |
| 216 | self.assertEqual(r1, r2) |
| 217 | if loc != -1: |
| 218 | self.assertEqual(i[loc:loc+len(j)], j) |
| 219 | |
| 220 | def test_rfind(self): |
nothing calls this directly
no test coverage detected