Handle successive editblocks from same file w/o filename #267

This commit is contained in:
Paul Gauthier 2023-10-22 11:28:22 -07:00
parent ebbb5bd442
commit 3299d90317
2 changed files with 34 additions and 1 deletions

View file

@ -341,7 +341,7 @@ def find_original_update_blocks(content):
try:
if not len(filename) or "`" in filename:
filename = processed[-2].splitlines()[-2].strip()
if not len(filename) or "`" in filename:
if not len(filename) or "`" in filename or filename == "...":
if current_filename:
filename = current_filename
else:

View file

@ -345,6 +345,39 @@ new
content = Path(file1).read_text(encoding="utf-8")
self.assertEqual(content, orig_content)
def test_find_original_update_blocks_mupltiple_same_file(self):
edit = """
Here's the change:
```text
foo.txt
<<<<<<< HEAD
one
=======
two
>>>>>>> updated
...
<<<<<<< HEAD
three
=======
four
>>>>>>> updated
```
Hope you like it!
"""
edits = list(eb.find_original_update_blocks(edit))
self.assertEqual(
edits,
[
("foo.txt", "one\n", "two\n"),
("foo.txt", "three\n", "four\n"),
],
)
if __name__ == "__main__":
unittest.main()