Fix issues with error correction / newline correction.

This commit is contained in:
Dave Halter
2015-01-27 12:24:54 +01:00
parent 62e45aa42b
commit 5e8f8f7a8d
4 changed files with 40 additions and 13 deletions

View File

@@ -163,3 +163,19 @@ def test_newline_positions():
new_line = endmarker.get_previous()
assert new_line.start_pos == (1, 1)
assert new_line.end_pos == (2, 0)
def test_end_pos_error_correction():
"""
Source code without ending newline are given one, because the Python
grammar needs it. However, they are removed again. We still want the right
end_pos, even if something breaks in the parser (error correction).
"""
s = 'def x():\n .'
m = Parser(load_grammar(), s).module
func = m.children[0]
assert func.type == 'funcdef'
# This is not exactly correct, but ok, because it doesn't make a difference
# at all. We just want to make sure that the module end_pos is correct!
assert func.end_pos == (3, 0)
assert m.end_pos == (2, 2)