diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-11-21 21:52:58 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-11-21 21:52:58 (GMT) |
commit | 42bf77537e612737c7e7e2495c3c481e92391a42 (patch) | |
tree | 860ee37c9a22144d4f9712d8f4b8f2d9288304d9 /Lib | |
parent | 6dd381eb62278f75de7ba01626813de84cd248e7 (diff) | |
download | cpython-42bf77537e612737c7e7e2495c3c481e92391a42.zip cpython-42bf77537e612737c7e7e2495c3c481e92391a42.tar.gz cpython-42bf77537e612737c7e7e2495c3c481e92391a42.tar.bz2 |
Rewrite PyUnicode_EncodeDecimal() to use the new Unicode API
Add tests for PyUnicode_EncodeDecimal() and
PyUnicode_TransformDecimalToASCII().
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unicode.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index a669f8e..1ed2058 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1806,6 +1806,36 @@ class UnicodeTest(string_tests.CommonTest, s += "4" self.assertEqual(s, "3") + def test_encode_decimal(self): + from _testcapi import unicode_encodedecimal + self.assertEqual(unicode_encodedecimal('123'), + b'123') + self.assertEqual(unicode_encodedecimal('\u0663.\u0661\u0664'), + b'3.14') + self.assertEqual(unicode_encodedecimal("\N{EM SPACE}3.14\N{EN SPACE}"), + b' 3.14 ') + self.assertRaises(UnicodeEncodeError, + unicode_encodedecimal, "123\u20ac", "strict") + self.assertEqual(unicode_encodedecimal("123\u20ac", "replace"), + b'123?') + self.assertEqual(unicode_encodedecimal("123\u20ac", "ignore"), + b'123') + self.assertEqual(unicode_encodedecimal("123\u20ac", "xmlcharrefreplace"), + b'123€') + self.assertEqual(unicode_encodedecimal("123\u20ac", "backslashreplace"), + b'123\\u20ac') + + def test_transform_decimal(self): + from _testcapi import unicode_transformdecimaltoascii as transform_decimal + self.assertEqual(transform_decimal('123'), + '123') + self.assertEqual(transform_decimal('\u0663.\u0661\u0664'), + '3.14') + self.assertEqual(transform_decimal("\N{EM SPACE}3.14\N{EN SPACE}"), + "\N{EM SPACE}3.14\N{EN SPACE}") + self.assertEqual(transform_decimal('123\u20ac'), + '123\u20ac') + class StringModuleTest(unittest.TestCase): def test_formatter_parser(self): |