@@ -134,3 +134,44 @@ def test_sort_keys_flag(self):
134134 self .assertEqual (out .splitlines (),
135135 self .expect_without_sort_keys .encode ().splitlines ())
136136 self .assertEqual (err , b'' )
137+
138+ def test_indent (self ):
139+ json_stdin = b'[1, 2]'
140+ expect = textwrap .dedent ('''\
141+ [
142+ 1,
143+ 2
144+ ]
145+ ''' ).encode ()
146+ args = sys .executable , '-m' , 'json.tool' , '--indent' , '2'
147+ with Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) as proc :
148+ json_stdout , err = proc .communicate (json_stdin )
149+ self .assertEqual (expect .splitlines (), json_stdout .splitlines ())
150+ self .assertEqual (err , b'' )
151+
152+ def test_no_indent (self ):
153+ json_stdin = b'[1,\n 2]'
154+ expect = b'[1, 2]'
155+ args = sys .executable , '-m' , 'json.tool' , '--no-indent'
156+ with Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) as proc :
157+ json_stdout , err = proc .communicate (json_stdin )
158+ self .assertEqual (expect .splitlines (), json_stdout .splitlines ())
159+ self .assertEqual (err , b'' )
160+
161+ def test_tab (self ):
162+ json_stdin = b'[1, 2]'
163+ expect = b'[\n \t 1,\n \t 2\n ]\n '
164+ args = sys .executable , '-m' , 'json.tool' , '--tab'
165+ with Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) as proc :
166+ json_stdout , err = proc .communicate (json_stdin )
167+ self .assertEqual (expect .splitlines (), json_stdout .splitlines ())
168+ self .assertEqual (err , b'' )
169+
170+ def test_compact (self ):
171+ json_stdin = b'[ 1 ,\n 2]'
172+ expect = b'[1,2]'
173+ args = sys .executable , '-m' , 'json.tool' , '--compact'
174+ with Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) as proc :
175+ json_stdout , err = proc .communicate (json_stdin )
176+ self .assertEqual (expect .splitlines (), json_stdout .splitlines ())
177+ self .assertEqual (err , b'' )
0 commit comments