diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-10-12 16:27:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-12 16:27:53 (GMT) |
commit | ccab67ba7901a3012ad66f0ffafac4ea925a1ff0 (patch) | |
tree | 75fe289a6b89e1ab5cdb59326dc6255ea74b732c /Lib/test | |
parent | e9569ec43e2376aa77240cd630db4be07e8720f3 (diff) | |
download | cpython-ccab67ba7901a3012ad66f0ffafac4ea925a1ff0.zip cpython-ccab67ba7901a3012ad66f0ffafac4ea925a1ff0.tar.gz cpython-ccab67ba7901a3012ad66f0ffafac4ea925a1ff0.tar.bz2 |
gh-97982: Factorize PyUnicode_Count() and unicode_count() code (#98025)
Add unicode_count_impl() to factorize PyUnicode_Count()
and unicode_count() code.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_unicode.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 5b81657..15244cb 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -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') |