@@ -322,21 +322,19 @@ def test_position(self):
322322 # An absolutely minimal test of position information. Better
323323 # tests would be a big project.
324324 code = "def f(x):\n return x + 1"
325- st1 = parser .suite (code )
326- st2 = st1 .totuple (line_info = 1 , col_info = 1 )
325+ st = parser .suite (code )
327326
328327 def walk (tree ):
329328 node_type = tree [0 ]
330329 next = tree [1 ]
331- if isinstance (next , tuple ):
330+ if isinstance (next , ( tuple , list ) ):
332331 for elt in tree [1 :]:
333332 for x in walk (elt ):
334333 yield x
335334 else :
336335 yield tree
337336
338- terminals = list (walk (st2 ))
339- self .assertEqual ([
337+ expected = [
340338 (1 , 'def' , 1 , 0 ),
341339 (1 , 'f' , 1 , 4 ),
342340 (7 , '(' , 1 , 5 ),
@@ -352,8 +350,25 @@ def walk(tree):
352350 (4 , '' , 2 , 16 ),
353351 (6 , '' , 2 , - 1 ),
354352 (4 , '' , 2 , - 1 ),
355- (0 , '' , 2 , - 1 )],
356- terminals )
353+ (0 , '' , 2 , - 1 ),
354+ ]
355+
356+ self .assertEqual (list (walk (st .totuple (line_info = True , col_info = True ))),
357+ expected )
358+ self .assertEqual (list (walk (st .totuple ())),
359+ [(t , n ) for t , n , l , c in expected ])
360+ self .assertEqual (list (walk (st .totuple (line_info = True ))),
361+ [(t , n , l ) for t , n , l , c in expected ])
362+ self .assertEqual (list (walk (st .totuple (col_info = True ))),
363+ [(t , n , c ) for t , n , l , c in expected ])
364+ self .assertEqual (list (walk (st .tolist (line_info = True , col_info = True ))),
365+ [list (x ) for x in expected ])
366+ self .assertEqual (list (walk (parser .st2tuple (st , line_info = True ,
367+ col_info = True ))),
368+ expected )
369+ self .assertEqual (list (walk (parser .st2list (st , line_info = True ,
370+ col_info = True ))),
371+ [list (x ) for x in expected ])
357372
358373 def test_extended_unpacking (self ):
359374 self .check_suite ("*a = y" )
0 commit comments