mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
Make sure to only copy nodes that have the same indentation in diff parser
This commit is contained in:
@@ -636,8 +636,9 @@ class _NodesTree(object):
|
||||
# lines above there was an invalid indent.
|
||||
indentation = _get_indentation(tree_nodes[0])
|
||||
for i, c in enumerate(tree_nodes):
|
||||
if c.start_pos[1] < indentation:
|
||||
if c.start_pos[1] != indentation:
|
||||
tree_nodes = tree_nodes[:i]
|
||||
break
|
||||
|
||||
old_working_stack = list(self._working_stack)
|
||||
old_prefix = self.prefix
|
||||
|
||||
@@ -1408,7 +1408,7 @@ def test_error_dedent_in_function(differ):
|
||||
differ.parse(code2, parsers=ANY, copies=ANY, expect_error_leaves=True)
|
||||
|
||||
|
||||
def test_x(differ):
|
||||
def test_with_formfeed(differ):
|
||||
code1 = dedent('''\
|
||||
@bla
|
||||
async def foo():
|
||||
@@ -1427,3 +1427,28 @@ def test_x(differ):
|
||||
''')
|
||||
differ.initialize(code1)
|
||||
differ.parse(code2, parsers=ANY, copies=ANY, expect_error_leaves=True)
|
||||
|
||||
|
||||
def test_x(differ):
|
||||
code1 = dedent('''\
|
||||
def foo():
|
||||
return
|
||||
|
||||
@bla
|
||||
a
|
||||
def foo():
|
||||
a
|
||||
b
|
||||
c
|
||||
''')
|
||||
code2 = dedent('''\
|
||||
def foo():
|
||||
return
|
||||
|
||||
@bla
|
||||
a
|
||||
b
|
||||
c
|
||||
''')
|
||||
differ.initialize(code1)
|
||||
differ.parse(code2, parsers=ANY, copies=ANY, expect_error_leaves=True)
|
||||
|
||||
Reference in New Issue
Block a user