MCPcopy Index your code
hub / github.com/python/cpython / test_find

Method test_find

Lib/test/test_str.py:270–313  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

268 self.checkequal(3, MyStr('aaa'), 'count', 'a')
269
270 def test_find(self):
271 string_tests.StringLikeTest.test_find(self)
272 # test implementation details of the memchr fast path
273 self.checkequal(100, 'a' * 100 + '\u0102', 'find', '\u0102')
274 self.checkequal(-1, 'a' * 100 + '\u0102', 'find', '\u0201')
275 self.checkequal(-1, 'a' * 100 + '\u0102', 'find', '\u0120')
276 self.checkequal(-1, 'a' * 100 + '\u0102', 'find', '\u0220')
277 self.checkequal(100, 'a' * 100 + '\U00100304', 'find', '\U00100304')
278 self.checkequal(-1, 'a' * 100 + '\U00100304', 'find', '\U00100204')
279 self.checkequal(-1, 'a' * 100 + '\U00100304', 'find', '\U00102004')
280 # check mixed argument types
281 self.checkequalnofix(0, 'abcdefghiabc', 'find', 'abc')
282 self.checkequalnofix(9, 'abcdefghiabc', 'find', 'abc', 1)
283 self.checkequalnofix(-1, 'abcdefghiabc', 'find', 'def', 4)
284
285 # test utf-8 non-ascii char
286 self.checkequal(0, 'тест', 'find', 'т')
287 self.checkequal(3, 'тест', 'find', 'т', 1)
288 self.checkequal(-1, 'тест', 'find', 'т', 1, 3)
289 self.checkequal(-1, 'тест', 'find', 'e') # english `e`
290 # test utf-8 non-ascii slice
291 self.checkequal(1, 'тест тест', 'find', 'ес')
292 self.checkequal(1, 'тест тест', 'find', 'ес', 1)
293 self.checkequal(1, 'тест тест', 'find', 'ес', 1, 3)
294 self.checkequal(6, 'тест тест', 'find', 'ес', 2)
295 self.checkequal(-1, 'тест тест', 'find', 'ес', 6, 7)
296 self.checkequal(-1, 'тест тест', 'find', 'ес', 7)
297 self.checkequal(-1, 'тест тест', 'find', 'ec') # english `ec`
298
299 self.assertRaises(TypeError, 'hello'.find)
300 self.assertRaises(TypeError, 'hello'.find, 42)
301 # test mixed kinds
302 self.checkequal(100, '\u0102' * 100 + 'a', 'find', 'a')
303 self.checkequal(100, '\U00100304' * 100 + 'a', 'find', 'a')
304 self.checkequal(100, '\U00100304' * 100 + '\u0102', 'find', '\u0102')
305 self.checkequal(-1, 'a' * 100, 'find', '\u0102')
306 self.checkequal(-1, 'a' * 100, 'find', '\U00100304')
307 self.checkequal(-1, '\u0102' * 100, 'find', '\U00100304')
308 self.checkequal(100, '\u0102' * 100 + 'a_', 'find', 'a_')
309 self.checkequal(100, '\U00100304' * 100 + 'a_', 'find', 'a_')
310 self.checkequal(100, '\U00100304' * 100 + '\u0102_', 'find', '\u0102_')
311 self.checkequal(-1, 'a' * 100, 'find', 'a\u0102')
312 self.checkequal(-1, 'a' * 100, 'find', 'a\U00100304')
313 self.checkequal(-1, '\u0102' * 100, 'find', '\u0102\U00100304')
314
315 def test_rfind(self):
316 string_tests.StringLikeTest.test_rfind(self)

Callers

nothing calls this directly

Calls 3

checkequalnofixMethod · 0.95
checkequalMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected