@@ -209,25 +209,34 @@ def test_zero_padding():
209209# u16::MAX; output is zero-padded past that boundary to match CPython
210210# byte-identically.
211211
212- # Boundary values around the internal cap (u16::MAX = 65535). Output must
213- # match what CPython would produce.
212+ # Three precision points per format type — below the cap (uncapped
213+ # path), exactly at the cap (boundary), and one past the cap (the
214+ # unhappy case, where internal clamping plus zero-padding has to
215+ # reconstruct CPython's output). All must byte-match CPython.
216+
214217# f-format pads with trailing zeros up to the requested precision.
215- assert "{:.65534f}" .format (1.5 ) == "1." + "5" + "0" * 65533
216- assert "{:.65535f}" .format (1.5 ) == "1." + "5" + "0" * 65534
217- assert "{:.65536f}" .format (1.5 ) == "1." + "5" + "0" * 65535
218+ assert "{:.65534f}" .format (1.5 ) == "1." + "5" + "0" * 65533 # below cap
219+ assert "{:.65535f}" .format (1.5 ) == "1." + "5" + "0" * 65534 # at cap
220+ assert "{:.65536f}" .format (1.5 ) == "1." + "5" + "0" * 65535 # past cap → padding
218221# e-format emits a fixed mantissa width + 'e+00'.
219- assert "{:.65534e}" .format (1.5 ) == "1." + "5" + "0" * 65533 + "e+00"
220- assert "{:.65535e}" .format (1.5 ) == "1." + "5" + "0" * 65534 + "e+00"
221- assert "{:.65536e}" .format (1.5 ) == "1." + "5" + "0" * 65535 + "e+00"
222+ assert "{:.65534e}" .format (1.5 ) == "1." + "5" + "0" * 65533 + "e+00" # below
223+ assert "{:.65535e}" .format (1.5 ) == "1." + "5" + "0" * 65534 + "e+00" # at cap
224+ assert "{:.65536e}" .format (1.5 ) == "1." + "5" + "0" * 65535 + "e+00" # past cap → padding
222225# %-format multiplies by 100 then applies f-format.
223- assert "{:.65534%}" .format (1.5 ) == "150." + "0" * 65534 + "%"
224- assert "{:.65535%}" .format (1.5 ) == "150." + "0" * 65535 + "%"
225- assert "{:.65536%}" .format (1.5 ) == "150." + "0" * 65536 + "%"
226+ assert "{:.65534%}" .format (1.5 ) == "150." + "0" * 65534 + "%" # below
227+ assert "{:.65535%}" .format (1.5 ) == "150." + "0" * 65535 + "%" # at cap
228+ assert "{:.65536%}" .format (1.5 ) == "150." + "0" * 65536 + "%" # past cap → padding
226229# g-format strips trailing zeros, so the short form is the natural
227230# representation regardless of precision.
228231for p in (65534 , 65535 , 65536 , 1_000_000 ):
229232 assert ("{:." + str (p ) + "g}" ).format (1.5 ) == "1.5"
230233
234+ # Far past the cap — verifies the pad path handles arbitrary precision,
235+ # not just one-off values near the boundary.
236+ assert len ("{:.1000000f}" .format (1.5 )) == 1_000_002 # "1." + 1M zeros
237+ assert len ("{:.1000000e}" .format (1.5 )) == 1_000_006 # + "e+00"
238+ assert len ("{:.1000000%}" .format (1.5 )) == 1_000_005 # "150." + 1M zeros + "%"
239+
231240# Percent overflow: finite input whose *100 is +inf produces "inf%"
232241# rather than crashing. CPython does the same.
233242assert "{:.100000%}" .format (1.7976931348623157e308 ) == "inf%"
0 commit comments