mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
* Add tests for PyUnicode_EncodeDecimal() and PyUnicode_TransformDecimalToASCII() * Remove the unused "e" variable in replace()
This commit is contained in:
parent
58fcf9f801
commit
ab1d16b456
3 changed files with 89 additions and 8 deletions
|
@ -1767,6 +1767,42 @@ class StringModuleTest(unittest.TestCase):
|
|||
]])
|
||||
self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
|
||||
|
||||
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')
|
||||
self.assertEqual(unicode_encodedecimal("123\u20ac\N{EM SPACE}", "replace"),
|
||||
b'123? ')
|
||||
self.assertEqual(unicode_encodedecimal("123\u20ac\u20ac", "replace"),
|
||||
b'123??')
|
||||
self.assertEqual(unicode_encodedecimal("123\u20ac\u0660", "replace"),
|
||||
b'123?0')
|
||||
|
||||
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')
|
||||
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(__name__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue