mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Panic occurs when formatting with separator and some format specifier (#6213)
* Fix get_separator_interval * Add extra tests * Remove FormatType::Number from match arm
This commit is contained in:
2 files changed
+12
-1
No files matched your search
@@ -424,7 +424,13 @@ impl FormatSpec {
|
||||
const fn get_separator_interval(&self) -> usize {
|
||||
match self.format_type {
|
||||
Some(FormatType::Binary | FormatType::Octal | FormatType::Hex(_)) => 4,
|
||||
Some(FormatType::Decimal | FormatType::Number(_) | FormatType::FixedPoint(_)) => 3,
|
||||
Some(
|
||||
FormatType::Decimal
|
||||
| FormatType::FixedPoint(_)
|
||||
| FormatType::GeneralFormat(_)
|
||||
| FormatType::Exponent(_)
|
||||
| FormatType::Percentage,
|
||||
) => 3,
|
||||
None => 3,
|
||||
_ => panic!("Separators only valid for numbers!"),
|
||||
}
|
||||
|
||||
@@ -188,6 +188,11 @@ assert f"{12.34 + 5.6j:^30E}" == " 1.234000E+01+5.600000E+00j "
|
||||
assert f"{12345.6 + 7890.1j:,}" == "(12,345.6+7,890.1j)"
|
||||
assert f"{12345.6 + 7890.1j:_.3f}" == "12_345.600+7_890.100j"
|
||||
assert f"{12345.6 + 7890.1j:>+30,f}" == " +12,345.600000+7,890.100000j"
|
||||
assert f"{123456:,g}" == "123,456"
|
||||
assert f"{123456:,G}" == "123,456"
|
||||
assert f"{123456:,e}" == "1.234560e+05"
|
||||
assert f"{123456:,E}" == "1.234560E+05"
|
||||
assert f"{123456:,%}" == "12,345,600.000000%"
|
||||
|
||||
# test issue 4558
|
||||
x = 123456789012345678901234567890
|
||||
|
||||
Reference in new issue
Block a user