diff options
| author | Jeff Epler <jepler@unpythonic.net> | 2025-09-17 10:29:54 -0500 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-10-06 15:07:34 +1100 |
| commit | 5552fbe17240aedcada2ce3a5fbb5136a3087f65 (patch) | |
| tree | 1d1ea7bb74b63388d9d46a6f7fc9af2f278c8bde /tests/basics/string_format_sep.py | |
| parent | 01a11ea45efe8e5fe7d2049902f7d6e6818d3ec1 (diff) | |
py/mpprint: Correctly format leading zeros with separators.
Correctly format integers when there are leading zeros with a grouping
character, such as "{:04,d}".format(0x100) -> "0,256".
The new padding patterns for commas-and-zeroes and underscores-and-zeroes
are smooshed together into the existing pad_zeroes to save space.
Only the two combinations of (decimal + commas) and (other bases +
underscores) are properly supported.
Also add a test for it.
Fixes issue #18082.
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
Diffstat (limited to 'tests/basics/string_format_sep.py')
| -rw-r--r-- | tests/basics/string_format_sep.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/basics/string_format_sep.py b/tests/basics/string_format_sep.py new file mode 100644 index 000000000..de131fdaf --- /dev/null +++ b/tests/basics/string_format_sep.py @@ -0,0 +1,9 @@ +try: + "%d" % 1 +except TypeError: + print("SKIP") + raise SystemExit + +for v in (0, 0x10, 0x1000, -0x10, -0x1000): + for sz in range(1, 12): print(("{:0%d,d}" % sz).format(v)) + for sz in range(1, 12): print(("{:0%d_x}" % sz).format(v)) |
