@@ -411,6 +411,50 @@ def test_ast_line_numbers_with_parentheses(self):
411
411
412
412
expr = """
413
413
x = (
414
+ u'wat',
415
+ u"wat",
416
+ b'wat',
417
+ b"wat",
418
+ f'wat',
419
+ f"wat",
420
+ )
421
+
422
+ y = (
423
+ u'''wat''',
424
+ u\" \" \" wat\" \" \" ,
425
+ b'''wat''',
426
+ b\" \" \" wat\" \" \" ,
427
+ f'''wat''',
428
+ f\" \" \" wat\" \" \" ,
429
+ )
430
+ """
431
+ t = ast .parse (expr )
432
+ self .assertEqual (type (t ), ast .Module )
433
+ self .assertEqual (len (t .body ), 2 )
434
+ x , y = t .body
435
+
436
+ # Check the single quoted string offsets first.
437
+ offsets = [
438
+ (elt .col_offset , elt .end_col_offset )
439
+ for elt in x .value .elts
440
+ ]
441
+ self .assertTrue (all (
442
+ offset == (4 , 10 )
443
+ for offset in offsets
444
+ ))
445
+
446
+ # Check the triple quoted string offsets.
447
+ offsets = [
448
+ (elt .col_offset , elt .end_col_offset )
449
+ for elt in y .value .elts
450
+ ]
451
+ self .assertTrue (all (
452
+ offset == (4 , 14 )
453
+ for offset in offsets
454
+ ))
455
+
456
+ expr = """
457
+ x = (
414
458
'PERL_MM_OPT', (
415
459
f'wat'
416
460
f'some_string={f(x)} '
@@ -444,7 +488,11 @@ def test_ast_line_numbers_with_parentheses(self):
444
488
self .assertEqual (wat2 .lineno , 5 )
445
489
self .assertEqual (wat2 .end_lineno , 6 )
446
490
self .assertEqual (wat2 .col_offset , 32 )
447
- self .assertEqual (wat2 .end_col_offset , 18 )
491
+ # wat ends at the offset 17, but the whole f-string
492
+ # ends at the offset 18 (since the quote is part of the
493
+ # f-string but not the wat string)
494
+ self .assertEqual (wat2 .end_col_offset , 17 )
495
+ self .assertEqual (fstring .end_col_offset , 18 )
448
496
449
497
def test_docstring (self ):
450
498
def f ():
0 commit comments