mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Closes issue #12546: Allow \x00 as a fill character for builtin type __format__ methods.
This commit is contained in:
commit
280c458f9e
3 changed files with 32 additions and 11 deletions
|
@ -874,6 +874,27 @@ class UnicodeTest(string_tests.CommonTest,
|
|||
self.assertEqual('{0:10000}'.format(''), ' ' * 10000)
|
||||
self.assertEqual('{0:10000000}'.format(''), ' ' * 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('{0:abc}'.format(C()), 'abc')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue