summaryrefslogtreecommitdiffstats
path: root/Lib/test/json_tests/test_indent.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/json_tests/test_indent.py')
-rw-r--r--Lib/test/json_tests/test_indent.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/json_tests/test_indent.py b/Lib/test/json_tests/test_indent.py
index d8030aa..692a494 100644
--- a/Lib/test/json_tests/test_indent.py
+++ b/Lib/test/json_tests/test_indent.py
@@ -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}')