mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Merge #10019: Fix regression relative to 2.6: add newlines if indent=0
Patch by Amaury Forgeot d'Arc, updated by Sando Tosi.
This commit is contained in:
commit
d5315482e9
4 changed files with 24 additions and 5 deletions
|
|
@ -2,6 +2,7 @@ from unittest import TestCase
|
|||
|
||||
import json
|
||||
import textwrap
|
||||
from io import StringIO
|
||||
|
||||
class TestIndent(TestCase):
|
||||
def test_indent(self):
|
||||
|
|
@ -43,3 +44,18 @@ class TestIndent(TestCase):
|
|||
self.assertEqual(h3, h)
|
||||
self.assertEqual(d2, expect.expandtabs(2))
|
||||
self.assertEqual(d3, expect)
|
||||
|
||||
def test_indent0(self):
|
||||
h = {3: 1}
|
||||
def check(indent, expected):
|
||||
d1 = json.dumps(h, indent=indent)
|
||||
self.assertEqual(d1, expected)
|
||||
|
||||
sio = StringIO()
|
||||
json.dump(h, sio, indent=indent)
|
||||
self.assertEqual(sio.getvalue(), expected)
|
||||
|
||||
# indent=0 should emit newlines
|
||||
check(0, '{\n"3": 1\n}')
|
||||
# indent=None is more compact
|
||||
check(None, '{"3": 1}')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue