mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-97982: Factorize PyUnicode_Count() and unicode_count() code (#98025)
Add unicode_count_impl() to factorize PyUnicode_Count() and unicode_count() code.
This commit is contained in:
parent
e9569ec43e
commit
ccab67ba79
2 changed files with 36 additions and 60 deletions
|
@ -241,6 +241,10 @@ class UnicodeTest(string_tests.CommonTest,
|
|||
self.checkequal(0, 'a' * 10, 'count', 'a\u0102')
|
||||
self.checkequal(0, 'a' * 10, 'count', 'a\U00100304')
|
||||
self.checkequal(0, '\u0102' * 10, 'count', '\u0102\U00100304')
|
||||
# test subclass
|
||||
class MyStr(str):
|
||||
pass
|
||||
self.checkequal(3, MyStr('aaa'), 'count', 'a')
|
||||
|
||||
def test_find(self):
|
||||
string_tests.CommonTest.test_find(self)
|
||||
|
@ -3002,6 +3006,12 @@ class CAPITest(unittest.TestCase):
|
|||
self.assertEqual(unicode_count(uni, ch, 0, len(uni)), 1)
|
||||
self.assertEqual(unicode_count(st, ch, 0, len(st)), 0)
|
||||
|
||||
# subclasses should still work
|
||||
class MyStr(str):
|
||||
pass
|
||||
|
||||
self.assertEqual(unicode_count(MyStr('aab'), 'a', 0, 3), 2)
|
||||
|
||||
# Test PyUnicode_FindChar()
|
||||
@support.cpython_only
|
||||
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue