@@ -190,3 +190,25 @@ def test_compact(self):
190190 json_stdout , err = proc .communicate (json_stdin )
191191 self .assertEqual (expect .splitlines (), json_stdout .splitlines ())
192192 self .assertEqual (err , b'' )
193+
194+ def test_no_ensure_ascii_flag (self ):
195+ infile = self ._create_infile ('{"key":"💩"}' )
196+ outfile = support .TESTFN + '.out'
197+ self .addCleanup (os .remove , outfile )
198+ assert_python_ok ('-m' , 'json.tool' , '--no-ensure-ascii' , infile , outfile )
199+ with open (outfile , "rb" ) as f :
200+ lines = f .read ().splitlines ()
201+ # asserting utf-8 encoded output file
202+ expected = [b'{' , b' "key": "\xf0 \x9f \x92 \xa9 "' , b"}" ]
203+ self .assertEqual (lines , expected )
204+
205+ def test_ensure_ascii_default (self ):
206+ infile = self ._create_infile ('{"key":"💩"}' )
207+ outfile = support .TESTFN + '.out'
208+ self .addCleanup (os .remove , outfile )
209+ assert_python_ok ('-m' , 'json.tool' , infile , outfile )
210+ with open (outfile , "rb" ) as f :
211+ lines = f .read ().splitlines ()
212+ # asserting an ascii encoded output file
213+ expected = [b'{' , rb' "key": "\ud83d\udca9"' , b"}" ]
214+ self .assertEqual (lines , expected )
0 commit comments