diff options
author | Eric V. Smith <eric@trueblade.com> | 2014-04-14 15:55:10 (GMT) |
---|---|---|
committer | Eric V. Smith <eric@trueblade.com> | 2014-04-14 15:55:10 (GMT) |
commit | 2ea9712ee91e6b6a6c1b10d9c21b219bc4fbe54b (patch) | |
tree | 236cd53e05426767821a0473f31097e54fdf2032 /Lib/test/test_unicode.py | |
parent | 70d92a96ab47e0b8b9cb78d437b3761296f815ed (diff) | |
download | cpython-2ea9712ee91e6b6a6c1b10d9c21b219bc4fbe54b.zip cpython-2ea9712ee91e6b6a6c1b10d9c21b219bc4fbe54b.tar.gz cpython-2ea9712ee91e6b6a6c1b10d9c21b219bc4fbe54b.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.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 7e70918..9ae31d1 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -845,6 +845,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') |