@@ -263,21 +263,19 @@ def test_position(self):
263263 # An absolutely minimal test of position information. Better
264264 # tests would be a big project.
265265 code = "def f(x):\n return x + 1"
266- st1 = parser .suite (code )
267- st2 = st1 .totuple (line_info = 1 , col_info = 1 )
266+ st = parser .suite (code )
268267
269268 def walk (tree ):
270269 node_type = tree [0 ]
271270 next = tree [1 ]
272- if isinstance (next , tuple ):
271+ if isinstance (next , ( tuple , list ) ):
273272 for elt in tree [1 :]:
274273 for x in walk (elt ):
275274 yield x
276275 else :
277276 yield tree
278277
279- terminals = list (walk (st2 ))
280- self .assertEqual ([
278+ expected = [
281279 (1 , 'def' , 1 , 0 ),
282280 (1 , 'f' , 1 , 4 ),
283281 (7 , '(' , 1 , 5 ),
@@ -293,8 +291,25 @@ def walk(tree):
293291 (4 , '' , 2 , 16 ),
294292 (6 , '' , 2 , - 1 ),
295293 (4 , '' , 2 , - 1 ),
296- (0 , '' , 2 , - 1 )],
297- terminals )
294+ (0 , '' , 2 , - 1 ),
295+ ]
296+
297+ self .assertEqual (list (walk (st .totuple (line_info = True , col_info = True ))),
298+ expected )
299+ self .assertEqual (list (walk (st .totuple ())),
300+ [(t , n ) for t , n , l , c in expected ])
301+ self .assertEqual (list (walk (st .totuple (line_info = True ))),
302+ [(t , n , l ) for t , n , l , c in expected ])
303+ self .assertEqual (list (walk (st .totuple (col_info = True ))),
304+ [(t , n , c ) for t , n , l , c in expected ])
305+ self .assertEqual (list (walk (st .tolist (line_info = True , col_info = True ))),
306+ [list (x ) for x in expected ])
307+ self .assertEqual (list (walk (parser .st2tuple (st , line_info = True ,
308+ col_info = True ))),
309+ expected )
310+ self .assertEqual (list (walk (parser .st2list (st , line_info = True ,
311+ col_info = True ))),
312+ [list (x ) for x in expected ])
298313
299314
300315#
0 commit comments