make sure diffs display with newlines

This commit is contained in:
Paul Gauthier 2023-06-25 17:33:33 -07:00
parent 6b2024a58a
commit 3393f560fb
2 changed files with 12 additions and 2 deletions

View file

@ -44,7 +44,7 @@ class WholeFileCoder(Coder):
full_path = (Path(self.root) / fname).absolute()
if mode == "diff" and full_path.exists():
orig_lines = full_path.read_text().splitlines()
orig_lines = full_path.read_text().splitlines(keepends=True)
show_diff = diffs.diff_partial_update(
orig_lines,
@ -97,7 +97,7 @@ class WholeFileCoder(Coder):
full_path = (Path(self.root) / fname).absolute()
if mode == "diff" and full_path.exists():
orig_lines = full_path.read_text().splitlines()
orig_lines = full_path.read_text().splitlines(keepends=True)
show_diff = diffs.diff_partial_update(
orig_lines,

View file

@ -33,6 +33,13 @@ def create_progress_bar(percentage):
return bar
def assert_newlines(lines):
if not lines:
return
for line in lines:
assert line and line[-1] == "\n", line
def diff_partial_update(lines_orig, lines_updated, final=False, fname=None):
"""
Given only the first part of an updated file, show the diff while
@ -43,6 +50,9 @@ def diff_partial_update(lines_orig, lines_updated, final=False, fname=None):
# dump(lines_orig)
# dump(lines_updated)
assert_newlines(lines_orig)
assert_newlines(lines_orig)
num_orig_lines = len(lines_orig)
if final: