mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 18:54:59 +00:00
fix for issue #25
This commit is contained in:
parent
caad2af7e6
commit
e261963acd
2 changed files with 16 additions and 2 deletions
|
@ -67,7 +67,7 @@ def replace_part_with_missing_leading_whitespace(whole, part, replace):
|
||||||
# If all lines in the part start with whitespace, then honor it.
|
# If all lines in the part start with whitespace, then honor it.
|
||||||
# But GPT often outdents the part and replace blocks completely,
|
# But GPT often outdents the part and replace blocks completely,
|
||||||
# thereby discarding the actual leading whitespace in the file.
|
# thereby discarding the actual leading whitespace in the file.
|
||||||
if all((len(pline) > 0 and pline[0].isspace()) for pline in part_lines):
|
if all((not pline or pline[0].isspace()) for pline in part_lines):
|
||||||
return
|
return
|
||||||
|
|
||||||
for i in range(len(whole_lines) - len(part_lines) + 1):
|
for i in range(len(whole_lines) - len(part_lines) + 1):
|
||||||
|
|
|
@ -200,7 +200,6 @@ These changes replace the `subprocess.run` patches with `subprocess.check_output
|
||||||
self.assertEqual(edit_blocks[0][0], "tests/test_repomap.py")
|
self.assertEqual(edit_blocks[0][0], "tests/test_repomap.py")
|
||||||
self.assertEqual(edit_blocks[1][0], "tests/test_repomap.py")
|
self.assertEqual(edit_blocks[1][0], "tests/test_repomap.py")
|
||||||
|
|
||||||
|
|
||||||
def test_replace_part_with_missing_leading_whitespace(self):
|
def test_replace_part_with_missing_leading_whitespace(self):
|
||||||
whole = " line1\n line2\n line3\n"
|
whole = " line1\n line2\n line3\n"
|
||||||
part = "line1\nline2"
|
part = "line1\nline2"
|
||||||
|
@ -210,5 +209,20 @@ These changes replace the `subprocess.run` patches with `subprocess.check_output
|
||||||
result = utils.replace_part_with_missing_leading_whitespace(whole, part, replace)
|
result = utils.replace_part_with_missing_leading_whitespace(whole, part, replace)
|
||||||
self.assertEqual(result, expected_output)
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
|
def test_replace_part_with_missing_leading_whitespace_including_blank_lines(self):
|
||||||
|
"""
|
||||||
|
The part has leading whitespace on all lines, so should be ignored.
|
||||||
|
But it has a *blank* line with no whitespace at all, which was causing a
|
||||||
|
bug per issue #25. Test case to repro and confirm fix.
|
||||||
|
"""
|
||||||
|
whole = " line1\n line2\n line3\n"
|
||||||
|
part = "\n line1\n line2"
|
||||||
|
replace = "new_line1\nnew_line2"
|
||||||
|
expected_output = None
|
||||||
|
|
||||||
|
result = utils.replace_part_with_missing_leading_whitespace(whole, part, replace)
|
||||||
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue