def test_end_newlines():
 def test(source, end_pos):
  module = ParserWithRecovery(load_grammar(), u(source)).module
  assert (module.get_code() == source)
  assert (module.end_pos == end_pos)
 test('a', (1, 1))
 test('a\n', (2, 0))
 test('a\nb', (2, 1))
 test('a\n#comment\n', (3, 0))
 test('a\n#comment', (2, 8))
 test('a#comment', (1, 9))
 test('def a():\n pass', (2, 5))
 test('def a(', (1, 6))

def test_end_newlines ( ) : def test ( source , end_pos ) : module = ParserWithRecovery ( load_grammar ( ) , u ( source ) ) . module assert ( module . get_code ( ) == source ) assert ( module . end_pos == end_pos ) test ( 'a' , ( 1 , 1 ) ) test ( 'a\n' , ( 2 , 0 ) ) test ( 'a\nb' , ( 2 , 1 ) ) test ( 'a\n#comment\n' , ( 3 , 0 ) ) test ( 'a\n#comment' , ( 2 , 8 ) ) test ( 'a#comment' , ( 1 , 9 ) ) test ( 'def a():\n pass' , ( 2 , 5 ) ) test ( 'def a(' , ( 1 , 6 ) )
the python grammar explicitly needs a newline at the end .