diff options
author | Xiang Zhang <angwerzx@126.com> | 2016-12-20 14:52:33 (GMT) |
---|---|---|
committer | Xiang Zhang <angwerzx@126.com> | 2016-12-20 14:52:33 (GMT) |
commit | b211068f5c8e2535ab2dd7f4c43325bbf5b30fad (patch) | |
tree | d18683bf67a43286f7184b39a8e3b49f036cc466 /Lib/test/test_unicode.py | |
parent | 38f225dd486ab69779eab3cae4fa2375f6c2d8d6 (diff) | |
download | cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.zip cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.tar.gz cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.tar.bz2 |
Issue #28822: Adjust indices handling of PyUnicode_FindChar().
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r-- | Lib/test/test_unicode.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 883c362..fb77ffb 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -2728,6 +2728,29 @@ class CAPITest(unittest.TestCase): self.assertEqual(unicode_asucs4(s, len(s), 1), s+'\0') self.assertEqual(unicode_asucs4(s, len(s), 0), s+'\uffff') + # Test PyUnicode_FindChar() + @support.cpython_only + def test_findchar(self): + from _testcapi import unicode_findchar + + for str in "\xa1", "\u8000\u8080", "\ud800\udc02", "\U0001f100\U0001f1f1": + for i, ch in enumerate(str): + self.assertEqual(unicode_findchar(str, ord(ch), 0, len(str), 1), i) + self.assertEqual(unicode_findchar(str, ord(ch), 0, len(str), -1), i) + + str = "!>_<!" + self.assertEqual(unicode_findchar(str, 0x110000, 0, len(str), 1), -1) + self.assertEqual(unicode_findchar(str, 0x110000, 0, len(str), -1), -1) + # start < end + self.assertEqual(unicode_findchar(str, ord('!'), 1, len(str)+1, 1), 4) + self.assertEqual(unicode_findchar(str, ord('!'), 1, len(str)+1, -1), 4) + # start >= end + self.assertEqual(unicode_findchar(str, ord('!'), 0, 0, 1), -1) + self.assertEqual(unicode_findchar(str, ord('!'), len(str), 0, 1), -1) + # negative + self.assertEqual(unicode_findchar(str, ord('!'), -len(str), -1, 1), 0) + self.assertEqual(unicode_findchar(str, ord('!'), -len(str), -1, -1), 0) + # Test PyUnicode_CopyCharacters() @support.cpython_only def test_copycharacters(self): |