Fix panic from test_int__format__locale

fix #4588
This commit is contained in:
minhrongcon2000 authored and Jeong YunWon committed 2023-03-23 15:48:51 +09:00
1 parent 6a4ce0a620
commit d39b44c4d3
3 files changed
+13 -4

No files matched your search

+3 -1
View File
@@ -403,7 +403,6 @@ class TypesTests(unittest.TestCase):
self.assertEqual(locale.format_string('%g', x, grouping=True), format(x, 'n'))
self.assertEqual(locale.format_string('%.10g', x, grouping=True), format(x, '.10n'))
@unittest.skip("TODO: RustPython format code n is not integrated with locale")
@run_with_locale('LC_NUMERIC', 'en_US.UTF8')
def test_int__format__locale(self):
# test locale support for __format__ code 'n' for integers
@@ -422,6 +421,9 @@ class TypesTests(unittest.TestCase):
self.assertEqual(len(format(0, rfmt)), len(format(x, rfmt)))
self.assertEqual(len(format(0, lfmt)), len(format(x, lfmt)))
self.assertEqual(len(format(0, cfmt)), len(format(x, cfmt)))
if sys.platform != "darwin":
test_int__format__locale = unittest.expectedFailure(test_int__format__locale)
def test_float__format__(self):
def test(f, format_spec, result):
+4 -3
View File
@@ -335,10 +335,11 @@ impl FormatSpec {
let offset = (disp_digit_cnt % (inter + 1) == 0) as i32;
let disp_digit_cnt = disp_digit_cnt + offset;
let pad_cnt = disp_digit_cnt - magnitude_len;
if pad_cnt > 0 {
let sep_cnt = disp_digit_cnt / (inter + 1);
let diff = pad_cnt - sep_cnt;
if pad_cnt > 0 && diff > 0 {
// separate with 0 padding
let sep_cnt = disp_digit_cnt / (inter + 1);
let padding = "0".repeat((pad_cnt - sep_cnt) as usize);
let padding = "0".repeat(diff as usize);
let padded_num = format!("{padding}{magnitude_str}");
FormatSpec::insert_separator(padded_num, inter, sep, sep_cnt)
} else {
+6
View File
@@ -133,3 +133,9 @@ assert f"{3.1415:#.1}" == "3.e+00"
assert f"{3.1415:#.2}" == "3.1"
assert f"{3.1415:#.3}" == "3.14"
assert f"{3.1415:#.4}" == "3.142"
# test issue 4558
x = 123456789012345678901234567890
for i in range(0, 30):
format(x, ',')
x = x // 10