mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 13:45:01 +08:00
Fix graph asserting for error indents
This commit is contained in:
@@ -29,6 +29,16 @@ def _assert_valid_graph(node):
|
||||
except AttributeError:
|
||||
previous_leaf = node.get_previous_leaf()
|
||||
|
||||
# Ignore INDENT is necessary, because indent/dedent tokens don't
|
||||
# contain value/prefix and are just around, because of the tokenizer.
|
||||
if node.type == 'error_leaf' and node.token_type == 'INDENT':
|
||||
return
|
||||
while previous_leaf and previous_leaf.type == 'error_leaf' \
|
||||
and previous_leaf.token_type == 'INDENT':
|
||||
assert previous_leaf.end_pos <= node.start_pos, \
|
||||
(previous_leaf, node)
|
||||
previous_leaf = previous_leaf.get_previous_leaf()
|
||||
|
||||
# Calculate the content between two start positions.
|
||||
if previous_leaf is None:
|
||||
content = node.prefix
|
||||
|
||||
@@ -59,11 +59,11 @@ class Differ(object):
|
||||
new_module = diff_parser.update(self.lines, lines)
|
||||
self.lines = lines
|
||||
assert code == new_module.get_code()
|
||||
_assert_valid_graph(new_module)
|
||||
assert diff_parser._copy_count == copies
|
||||
assert diff_parser._parser_count == parsers
|
||||
|
||||
assert expect_error_leaves == _check_error_leaves_nodes(new_module)
|
||||
_assert_valid_graph(new_module)
|
||||
return new_module
|
||||
|
||||
|
||||
@@ -573,3 +573,9 @@ def test_if_removal_and_reappearence(differ):
|
||||
differ.parse(code2, parsers=1, copies=4, expect_error_leaves=True)
|
||||
differ.parse(code1, parsers=1, copies=1)
|
||||
differ.parse(code3, parsers=1, copies=1)
|
||||
|
||||
|
||||
def test_add_error_indentation(differ):
|
||||
code = 'if x:\n 1\n'
|
||||
differ.initialize(code)
|
||||
differ.parse(code + ' 2\n', parsers=1, copies=0, expect_error_leaves=True)
|
||||
|
||||
Reference in New Issue
Block a user