mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
just like string codecs.
This commit is contained in:
parent
e3547fd2f7
commit
835b243c71
3 changed files with 20 additions and 13 deletions
|
@ -615,20 +615,24 @@ class UnicodeTest(
|
|||
self.assertEqual(u'hello'.encode('latin-1'), 'hello')
|
||||
|
||||
# Roundtrip safety for BMP (just the first 1024 chars)
|
||||
u = u''.join(map(unichr, xrange(1024)))
|
||||
for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
|
||||
'raw_unicode_escape', 'unicode_escape', 'unicode_internal'):
|
||||
self.assertEqual(unicode(u.encode(encoding),encoding), u)
|
||||
for c in xrange(1024):
|
||||
u = unichr(c)
|
||||
for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le',
|
||||
'utf-16-be', 'raw_unicode_escape',
|
||||
'unicode_escape', 'unicode_internal'):
|
||||
self.assertEqual(unicode(u.encode(encoding),encoding), u)
|
||||
|
||||
# Roundtrip safety for BMP (just the first 256 chars)
|
||||
u = u''.join(map(unichr, xrange(256)))
|
||||
for encoding in ('latin-1',):
|
||||
self.assertEqual(unicode(u.encode(encoding),encoding), u)
|
||||
for c in xrange(256):
|
||||
u = unichr(c)
|
||||
for encoding in ('latin-1',):
|
||||
self.assertEqual(unicode(u.encode(encoding),encoding), u)
|
||||
|
||||
# Roundtrip safety for BMP (just the first 128 chars)
|
||||
u = u''.join(map(unichr, xrange(128)))
|
||||
for encoding in ('ascii',):
|
||||
self.assertEqual(unicode(u.encode(encoding),encoding), u)
|
||||
for c in xrange(128):
|
||||
u = unichr(c)
|
||||
for encoding in ('ascii',):
|
||||
self.assertEqual(unicode(u.encode(encoding),encoding), u)
|
||||
|
||||
# Roundtrip safety for non-BMP (just a few chars)
|
||||
u = u'\U00010001\U00020002\U00030003\U00040004\U00050005'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue