Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(248872)

Unified Diff: Lib/test/test_unicode.py

Issue 28822: Fix indices handling in PyUnicode_FindChar
Patch Set: Created 2 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Modules/_testcapimodule.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_unicode.py Tue Nov 29 09:56:07 2016 +0200
+++ b/Lib/test/test_unicode.py Tue Nov 29 23:46:20 2016 +0800
@@ -2728,6 +2728,29 @@
self.assertEqual(unicode_asucs4(s, len(s), 1), s+'\0')
self.assertEqual(unicode_asucs4(s, len(s), 0), s+'\uffff')
+ # Test PyUnicode_FindChar()
haypo 2016/11/29 18:13:50 Put the comment in the function body.
xiang.zhang 2016/11/29 18:27:46 Hmm it's here because most other cpython unicode t
haypo 2016/11/29 18:31:04 Oh, you're right. This file is not consistent :-)
+ @support.cpython_only
+ def test_findchar(self):
+ from _testcapi import unicode_findchar
haypo 2016/11/29 18:13:50 Put the comment here, before "from ...".
+
+ 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):
« no previous file with comments | « no previous file | Modules/_testcapimodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+