diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-09 20:30:23 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-09 20:30:23 (GMT) |
commit | e4a189274f3d88d64d5238bf340cec96eff4e5e0 (patch) | |
tree | 5ead5f4f2fe3799a34155f2e41a04518adb995b1 /Lib/test/test_builtin.py | |
parent | ea99c5c94985c21d8a64c9a3d753bde7f801c14a (diff) | |
download | cpython-e4a189274f3d88d64d5238bf340cec96eff4e5e0.zip cpython-e4a189274f3d88d64d5238bf340cec96eff4e5e0.tar.gz cpython-e4a189274f3d88d64d5238bf340cec96eff4e5e0.tar.bz2 |
Issue #9804: ascii() now always represents unicode surrogate pairs as
a single `\UXXXXXXXX`, regardless of whether the character is printable
or not. Also, the "backslashreplace" error handler now joins surrogate
pairs into a single character on UCS-2 builds.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r-- | Lib/test/test_builtin.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 4e09ca5..35b652b 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -179,6 +179,28 @@ class BuiltinTest(unittest.TestCase): a = {} a[0] = a self.assertEqual(ascii(a), '{0: {...}}') + # Advanced checks for unicode strings + def _check_uni(s): + self.assertEqual(ascii(s), repr(s)) + _check_uni("'") + _check_uni('"') + _check_uni('"\'') + _check_uni('\0') + _check_uni('\r\n\t .') + # Unprintable non-ASCII characters + _check_uni('\x85') + _check_uni('\u1fff') + _check_uni('\U00012fff') + # Lone surrogates + _check_uni('\ud800') + _check_uni('\udfff') + # Issue #9804: surrogates should be joined even for printable + # wide characters (UCS-2 builds). + self.assertEqual(ascii('\U0001d121'), "'\\U0001d121'") + # All together + s = "'\0\"\n\r\t abcd\x85é\U00012fff\uD800\U0001D121xxx." + self.assertEqual(ascii(s), + r"""'\'\x00"\n\r\t abcd\x85\xe9\U00012fff\ud800\U0001d121xxx.'""") def test_neg(self): x = -sys.maxsize-1 |