summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorHye-Shik Chang <hyeshik@gmail.com>2004-08-04 07:38:35 (GMT)
committerHye-Shik Chang <hyeshik@gmail.com>2004-08-04 07:38:35 (GMT)
commite9ddfbb41207328d5c89061067f3431e00711fda (patch)
tree54093161fe6808de7d6fcc3304eb32241231f010 /Lib/test
parentb5047fd01948ab108edcc1b3c2c901d915814cfd (diff)
downloadcpython-e9ddfbb41207328d5c89061067f3431e00711fda.zip
cpython-e9ddfbb41207328d5c89061067f3431e00711fda.tar.gz
cpython-e9ddfbb41207328d5c89061067f3431e00711fda.tar.bz2
SF #989185: Drop unicode.iswide() and unicode.width() and add
unicodedata.east_asian_width(). You can still implement your own simple width() function using it like this: def width(u): w = 0 for c in unicodedata.normalize('NFC', u): cwidth = unicodedata.east_asian_width(c) if cwidth in ('W', 'F'): w += 2 else: w += 1 return w
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/string_tests.py25
-rw-r--r--Lib/test/test_unicode.py3
-rw-r--r--Lib/test/test_unicodedata.py11
-rwxr-xr-xLib/test/test_userstring.py3
4 files changed, 13 insertions, 29 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index edccb8f..860c1f2 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -695,28 +695,3 @@ class MixinStrUserStringTest:
self.checkraises(TypeError, 'xyz', 'decode', 42)
self.checkraises(TypeError, 'xyz', 'encode', 42)
-
-
-class MixinUnicodeUserStringTest:
- # Additional tests that only work with
- # unicode compatible object, i.e. unicode and UserString
-
- def test_iswide(self):
- self.checkequal(False, u'', 'iswide')
- self.checkequal(False, u'\x1f', 'iswide') # Neutral
- self.checkequal(False, u'\x20', 'iswide') # Narrow
- self.checkequal(True, u'\u2329', 'iswide') # Wide
- self.checkequal(False, u'\uff64', 'iswide') # Half
- self.checkequal(True, u'\u3000', 'iswide') # Full
- self.checkequal(False, u'\u2460', 'iswide') # Ambiguous
- self.checkequal(True, u'\ud55c\uae00', 'iswide')
- self.checkequal(False, u'\ud55c\u2606\uae00', 'iswide')
-
- def test_width(self):
- self.checkequal(0, u'', 'width')
- self.checkequal(4, u'abcd', 'width')
- self.checkequal(2, u'\u0187\u01c9', 'width')
- self.checkequal(3, u'\u2460\u2329', 'width')
- self.checkequal(3, u'\u2329\u2460', 'width')
- self.checkequal(4, u'\ud55c\uae00', 'width')
- self.checkequal(5, u'\ud55c\u2606\uae00', 'width')
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 17c82ab..215c968 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -11,8 +11,7 @@ from test import test_support, string_tests
class UnicodeTest(
string_tests.CommonTest,
- string_tests.MixinStrUnicodeUserStringTest,
- string_tests.MixinUnicodeUserStringTest
+ string_tests.MixinStrUnicodeUserStringTest
):
type2test = unicode
diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py
index 8157fb3..0bbabb1 100644
--- a/Lib/test/test_unicodedata.py
+++ b/Lib/test/test_unicodedata.py
@@ -174,6 +174,17 @@ class UnicodeFunctionsTest(UnicodeDatabaseTest):
# The rest can be found in test_normalization.py
# which requires an external file.
+ def test_east_asian_width(self):
+ eaw = self.db.east_asian_width
+ self.assertRaises(TypeError, eaw, 'a')
+ self.assertRaises(TypeError, eaw, u'')
+ self.assertRaises(TypeError, eaw, u'ra')
+ self.assertEqual(eaw(u'\x1e'), 'N')
+ self.assertEqual(eaw(u'\x20'), 'Na')
+ self.assertEqual(eaw(u'\uC894'), 'W')
+ self.assertEqual(eaw(u'\uFF66'), 'H')
+ self.assertEqual(eaw(u'\uFF1F'), 'F')
+ self.assertEqual(eaw(u'\u2010'), 'A')
class UnicodeMiscTest(UnicodeDatabaseTest):
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py
index b70081f..990199e 100755
--- a/Lib/test/test_userstring.py
+++ b/Lib/test/test_userstring.py
@@ -11,8 +11,7 @@ class UserStringTest(
string_tests.CommonTest,
string_tests.MixinStrUnicodeUserStringTest,
string_tests.MixinStrStringUserStringTest,
- string_tests.MixinStrUserStringTest,
- string_tests.MixinUnicodeUserStringTest
+ string_tests.MixinStrUserStringTest
):
type2test = UserString