Diff fuzzer: Create a check to see if the errors make sense.

This commit is contained in:
Dave Halter
2019-01-17 22:07:59 +01:00
parent 52d01685ba
commit 32321a74b1

View File

@@ -30,6 +30,7 @@ import pickle
import parso
from parso.utils import split_lines
from test.test_diff_parser import _check_error_leaves_nodes
_latest_grammar = parso.load_grammar(version='3.8')
_python_reserved_strings = tuple(
@@ -62,6 +63,11 @@ def _print_copyable_lines(lines):
print(line, end='')
def _get_first_error_start_pos_or_none(module):
error_leaf = _check_error_leaves_nodes(module)
return None if error_leaf is None else error_leaf.start_pos
class LineReplacement:
def __init__(self, line_nr, new_line):
self._line_nr = line_nr
@@ -159,10 +165,13 @@ class FileModification:
_print_copyable_lines(modified_lines)
print()
grammar.parse(code, diff_cache=True)
grammar.parse(modified_code, diff_cache=True)
m = grammar.parse(code, diff_cache=True)
start1 = _get_first_error_start_pos_or_none(m)
m = grammar.parse(modified_code, diff_cache=True)
# Also check if it's possible to "revert" the changes.
grammar.parse(code, diff_cache=True)
m = grammar.parse(code, diff_cache=True)
start2 = _get_first_error_start_pos_or_none(m)
assert start1 == start2, (start1, start2)
class FileTests: