summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unicode.py
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2014-04-14 15:22:33 (GMT)
committerEric V. Smith <eric@trueblade.com>2014-04-14 15:22:33 (GMT)
commit9a55cd885746f03a2df38e84a7698cb3348c6be0 (patch)
tree304d42c7443391bfdd744de62e2fe48460ad4c50 /Lib/test/test_unicode.py
parent6c939cb6f6dfbd273609577b0022542d31ae2802 (diff)
downloadcpython-9a55cd885746f03a2df38e84a7698cb3348c6be0.zip
cpython-9a55cd885746f03a2df38e84a7698cb3348c6be0.tar.gz
cpython-9a55cd885746f03a2df38e84a7698cb3348c6be0.tar.bz2
Issue #12546: Allow \x00 as a fill character for builtin type __format__ methods.
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r--Lib/test/test_unicode.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index da176b8..f068ca6 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1463,6 +1463,27 @@ class UnicodeTest(
self.assertEqual(u'{0:10000}'.format(u''), u' ' * 10000)
self.assertEqual(u'{0:10000000}'.format(u''), u' ' * 10000000)
+ # issue 12546: use \x00 as a fill character
+ self.assertEqual('{0:\x00<6s}'.format('foo'), 'foo\x00\x00\x00')
+ self.assertEqual('{0:\x01<6s}'.format('foo'), 'foo\x01\x01\x01')
+ self.assertEqual('{0:\x00^6s}'.format('foo'), '\x00foo\x00\x00')
+ self.assertEqual('{0:^6s}'.format('foo'), ' foo ')
+
+ self.assertEqual('{0:\x00<6}'.format(3), '3\x00\x00\x00\x00\x00')
+ self.assertEqual('{0:\x01<6}'.format(3), '3\x01\x01\x01\x01\x01')
+ self.assertEqual('{0:\x00^6}'.format(3), '\x00\x003\x00\x00\x00')
+ self.assertEqual('{0:<6}'.format(3), '3 ')
+
+ self.assertEqual('{0:\x00<6}'.format(3.14), '3.14\x00\x00')
+ self.assertEqual('{0:\x01<6}'.format(3.14), '3.14\x01\x01')
+ self.assertEqual('{0:\x00^6}'.format(3.14), '\x003.14\x00')
+ self.assertEqual('{0:^6}'.format(3.14), ' 3.14 ')
+
+ self.assertEqual('{0:\x00<12}'.format(3+2.0j), '(3+2j)\x00\x00\x00\x00\x00\x00')
+ self.assertEqual('{0:\x01<12}'.format(3+2.0j), '(3+2j)\x01\x01\x01\x01\x01\x01')
+ self.assertEqual('{0:\x00^12}'.format(3+2.0j), '\x00\x00\x00(3+2j)\x00\x00\x00')
+ self.assertEqual('{0:^12}'.format(3+2.0j), ' (3+2j) ')
+
# format specifiers for user defined type
self.assertEqual(u'{0:abc}'.format(C()), u'abc')