@@ -125,8 +125,8 @@ def test_truncated_input(self):
125125 ]
126126 for data , msg , idx in test_cases :
127127 self .assertRaisesRegex (ValueError ,
128- r'^{0}: line 1 column {1} \(char {1 }\)' .format (
129- re .escape (msg ), idx ),
128+ r'^{0}: line 1 column {1} \(char {2 }\)' .format (
129+ re .escape (msg ), idx + 1 , idx ),
130130 self .loads , data )
131131
132132 def test_unexpected_data (self ):
@@ -155,8 +155,8 @@ def test_unexpected_data(self):
155155 ]
156156 for data , msg , idx in test_cases :
157157 self .assertRaisesRegex (ValueError ,
158- r'^{0}: line 1 column {1} \(char {1 }\)' .format (
159- re .escape (msg ), idx ),
158+ r'^{0}: line 1 column {1} \(char {2 }\)' .format (
159+ re .escape (msg ), idx + 1 , idx ),
160160 self .loads , data )
161161
162162 def test_extra_data (self ):
@@ -173,10 +173,22 @@ def test_extra_data(self):
173173 for data , msg , idx in test_cases :
174174 self .assertRaisesRegex (ValueError ,
175175 r'^{0}: line 1 column {1} - line 1 column {2}'
176- r' \(char {1 } - {2 }\)' .format (
177- re .escape (msg ), idx , len (data )),
176+ r' \(char {3 } - {4 }\)' .format (
177+ re .escape (msg ), idx + 1 , len ( data ) + 1 , idx , len (data )),
178178 self .loads , data )
179179
180+ def test_linecol (self ):
181+ test_cases = [
182+ ('!' , 1 , 1 , 0 ),
183+ (' !' , 1 , 2 , 1 ),
184+ ('\n !' , 2 , 1 , 1 ),
185+ ('\n \n \n !' , 4 , 6 , 10 ),
186+ ]
187+ for data , line , col , idx in test_cases :
188+ self .assertRaisesRegex (ValueError ,
189+ r'^Expecting value: line {0} column {1}'
190+ r' \(char {2}\)$' .format (line , col , idx ),
191+ self .loads , data )
180192
181193class TestPyFail (TestFail , PyTest ): pass
182194class TestCFail (TestFail , CTest ): pass
0 commit comments