@@ -124,6 +124,34 @@ def test_incomplete_string_diagnostics(self, symbol, prefix):
124124 self .assertEqual (cm .exception .args , (
125125 'incomplete input' , ('<input>' , 2 , 9 , text , 2 , - 1 )))
126126
127+ @subTests ('compiler' , COMPILERS )
128+ @subTests ('newline' , ('\n ' , '\r ' , '\r \n ' ))
129+ def test_unterminated_trailing_line (self , compiler , newline ):
130+ for head , symbol in (('1' , 'eval' ), ('if 1: pass' , 'single' ),
131+ ('if 1:\n pass' , 'single' )):
132+ for tail in (' ' , '\t ' , '\f ' , '\n ' ):
133+ source = head + newline + tail
134+ with self .subTest (source = source , symbol = symbol ):
135+ if compiler in RAW_COMPILERS :
136+ with self .assertRaises (_IncompleteInputError ):
137+ compiler (source , '<input>' , symbol )
138+ else :
139+ self .assertIsNone (compiler (source , '<input>' , symbol ))
140+ self .assertValid (source + '\n ' , symbol , compiler = compiler )
141+ for tail in ('\f ' , ' \f ' , '\n \f ' ):
142+ with self .subTest (head = head , tail = tail , symbol = symbol ):
143+ self .assertValid (head + newline + tail , symbol ,
144+ compiler = compiler )
145+
146+ for tail in ('# comment' , ' # comment' ):
147+ self .assertValid ('if 1: pass' + newline + tail , compiler = compiler )
148+ self .assertValid ('1' + newline + tail , 'eval' , compiler = compiler )
149+
150+ for head in ('1' , 'if 1: pass' , 'if 1:\n pass' ):
151+ for tail in (' ' , '\t ' , '\f ' , '# comment' ):
152+ self .assertValid (head + newline + tail , 'exec' ,
153+ compiler = compiler )
154+
127155 @subTests ('symbol' , ('single' , 'exec' , 'eval' ))
128156 def test_unfinished_token_in_invalid_position (self , symbol ):
129157 for source in ('a b' , '(a b' , '1 """' , '(1 """' ,
0 commit comments