handle filenames above the triple quotes

This commit is contained in:
Paul Gauthier 2023-05-11 22:59:02 -07:00
parent 9ef50d8f3d
commit d45b7ae752
2 changed files with 23 additions and 2 deletions

View file

@ -174,9 +174,11 @@ def find_original_update_blocks(content):
processed.append(cur) # original_marker processed.append(cur) # original_marker
filename = processed[-2].splitlines()[-1] filename = processed[-2].splitlines()[-1].strip()
if not len(filename) or "`" in filename: if not len(filename) or "`" in filename:
raise ValueError(f"Bad/missing filename: {filename}") filename = processed[-2].splitlines()[-2].strip()
if not len(filename) or "`" in filename:
raise ValueError(f"Bad/missing filename. It should go right above {ORIGINAL}")
original_text = pieces.pop() original_text = pieces.pop()
processed.append(original_text) processed.append(original_text)

View file

@ -54,6 +54,25 @@ Tooooo
>>>>>>> UPDATED >>>>>>> UPDATED
``` ```
Hope you like it!
"""
edits = list(utils.find_original_update_blocks(edit))
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])
def test_find_original_update_blocks_quote_below_filename(self):
edit = """
Here's the change:
foo.txt
```text
<<<<<<< ORIGINAL
Two
=======
Tooooo
>>>>>>> UPDATED
```
Hope you like it! Hope you like it!
""" """