@@ -322,21 +322,19 @@ def test_position(self):
322
322
# An absolutely minimal test of position information. Better
323
323
# tests would be a big project.
324
324
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 )
327
326
328
327
def walk (tree ):
329
328
node_type = tree [0 ]
330
329
next = tree [1 ]
331
- if isinstance (next , tuple ):
330
+ if isinstance (next , ( tuple , list ) ):
332
331
for elt in tree [1 :]:
333
332
for x in walk (elt ):
334
333
yield x
335
334
else :
336
335
yield tree
337
336
338
- terminals = list (walk (st2 ))
339
- self .assertEqual ([
337
+ expected = [
340
338
(1 , 'def' , 1 , 0 ),
341
339
(1 , 'f' , 1 , 4 ),
342
340
(7 , '(' , 1 , 5 ),
@@ -352,8 +350,25 @@ def walk(tree):
352
350
(4 , '' , 2 , 16 ),
353
351
(6 , '' , 2 , - 1 ),
354
352
(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 ])
357
372
358
373
def test_extended_unpacking (self ):
359
374
self .check_suite ("*a = y" )
0 commit comments