mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
- SF #962502: Add two more methods for unicode type; width() and
iswide() for east asian width manipulation. (Inspired by David Goodger, Reviewed by Martin v. Loewis) - Move _PyUnicode_TypeRecord.flags to the end of the struct so that no padding is added for UCS-4 builds. (Suggested by Martin v. Loewis)
This commit is contained in:
parent
b6568b91fd
commit
974ed7cfa5
11 changed files with 683 additions and 459 deletions
|
@ -291,6 +291,26 @@ class UnicodeTest(
|
|||
|
||||
self.assertRaises(TypeError, u"abc".isnumeric, 42)
|
||||
|
||||
def test_iswide(self):
|
||||
self.checkequalnofix(False, u'', 'iswide')
|
||||
self.checkequalnofix(False, u'\x1f', 'iswide') # Neutral
|
||||
self.checkequalnofix(False, u'\x20', 'iswide') # Narrow
|
||||
self.checkequalnofix(True, u'\u2329', 'iswide') # Wide
|
||||
self.checkequalnofix(False, u'\uff64', 'iswide') # Half
|
||||
self.checkequalnofix(True, u'\u3000', 'iswide') # Full
|
||||
self.checkequalnofix(False, u'\u2460', 'iswide') # Ambiguous
|
||||
self.checkequalnofix(True, u'\ud55c\uae00', 'iswide')
|
||||
self.checkequalnofix(False, u'\ud55c\u2606\uae00', 'iswide')
|
||||
|
||||
def test_wide(self):
|
||||
self.assertEqual(u''.width(), 0)
|
||||
self.assertEqual(u'abcd'.width(), 4)
|
||||
self.assertEqual(u'\u0187\u01c9'.width(), 2)
|
||||
self.assertEqual(u'\u2460\u2329'.width(), 3)
|
||||
self.assertEqual(u'\u2329\u2460'.width(), 3)
|
||||
self.assertEqual(u'\ud55c\uae00'.width(), 4)
|
||||
self.assertEqual(u'\ud55c\u2606\uae00'.width(), 5)
|
||||
|
||||
def test_contains(self):
|
||||
# Testing Unicode contains method
|
||||
self.assert_('a' in u'abdb')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue