mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 06:44:59 +00:00
fix: Handle filenames starting with fences or triple backticks correctly
This commit is contained in:
parent
c6ce871700
commit
5e210c700d
2 changed files with 16 additions and 37 deletions
|
@ -414,11 +414,15 @@ def strip_filename(filename, fence):
|
|||
start_fence = fence[0]
|
||||
if filename.startswith(start_fence):
|
||||
candidate = filename[len(start_fence) :]
|
||||
if candidate and "." in candidate:
|
||||
if candidate and ("." in candidate or "/" in candidate):
|
||||
return candidate
|
||||
return
|
||||
|
||||
if filename.startswith(triple_backticks):
|
||||
filename = filename[len(triple_backticks) :]
|
||||
candidate = filename[len(triple_backticks) :]
|
||||
if candidate and ("." in candidate or "/" in candidate):
|
||||
return candidate
|
||||
return
|
||||
|
||||
filename = filename.rstrip(":")
|
||||
filename = filename.lstrip("#")
|
||||
|
|
|
@ -108,29 +108,6 @@ Hope you like it!
|
|||
edits = list(eb.find_original_update_blocks(edit))
|
||||
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])
|
||||
|
||||
def test_find_original_update_blocks_mangled_filename_w_source_tag(self):
|
||||
source = "source"
|
||||
|
||||
edit = """
|
||||
Here's the change:
|
||||
|
||||
<%s>foo.txt
|
||||
<<<<<<< SEARCH
|
||||
One
|
||||
=======
|
||||
Two
|
||||
>>>>>>> REPLACE
|
||||
</%s>
|
||||
|
||||
Hope you like it!
|
||||
""" % (source, source)
|
||||
|
||||
fence = ("<%s>" % source, "</%s>" % source)
|
||||
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
_edits = list(eb.find_original_update_blocks(edit, fence))
|
||||
self.assertIn("missing filename", str(cm.exception))
|
||||
|
||||
def test_find_original_update_blocks_quote_below_filename(self):
|
||||
edit = """
|
||||
Here's the change:
|
||||
|
@ -181,10 +158,11 @@ Tooooo
|
|||
|
||||
|
||||
oops!
|
||||
>>>>>>> REPLACE
|
||||
"""
|
||||
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
list(eb.find_original_update_blocks(edit))
|
||||
_blocks = list(eb.find_original_update_blocks(edit))
|
||||
self.assertIn("filename", str(cm.exception))
|
||||
|
||||
def test_find_original_update_blocks_no_final_newline(self):
|
||||
|
@ -575,7 +553,7 @@ Hope you like it!
|
|||
edits = list(eb.find_original_update_blocks(edit, fence=quad_backticks))
|
||||
self.assertEqual(edits, [("foo.txt", "", "Tooooo\n")])
|
||||
|
||||
#Test for shell script blocks with sh language identifier (issue #3785)
|
||||
# Test for shell script blocks with sh language identifier (issue #3785)
|
||||
def test_find_original_update_blocks_with_sh_language_identifier(self):
|
||||
# https://github.com/Aider-AI/aider/issues/3785
|
||||
edit = """
|
||||
|
@ -609,13 +587,13 @@ exit 0
|
|||
# Check that the content contains the expected shell script elements
|
||||
result_content = edits[0][2]
|
||||
self.assertIn("#!/bin/bash", result_content)
|
||||
self.assertIn("if [ \"$#\" -ne 1 ];", result_content)
|
||||
self.assertIn("echo \"Usage: $0 <argument>\"", result_content)
|
||||
self.assertIn('if [ "$#" -ne 1 ];', result_content)
|
||||
self.assertIn('echo "Usage: $0 <argument>"', result_content)
|
||||
self.assertIn("exit 1", result_content)
|
||||
self.assertIn("echo \"$1\"", result_content)
|
||||
self.assertIn('echo "$1"', result_content)
|
||||
self.assertIn("exit 0", result_content)
|
||||
|
||||
#Test for C# code blocks with csharp language identifier
|
||||
# Test for C# code blocks with csharp language identifier
|
||||
def test_find_original_update_blocks_with_csharp_language_identifier(self):
|
||||
edit = """
|
||||
Here's a C# code change:
|
||||
|
@ -631,12 +609,9 @@ Console.WriteLine("Hello, C# World!");
|
|||
"""
|
||||
|
||||
edits = list(eb.find_original_update_blocks(edit))
|
||||
search_text = "Console.WriteLine(\"Hello World!\");\n"
|
||||
replace_text = "Console.WriteLine(\"Hello, C# World!\");\n"
|
||||
self.assertEqual(
|
||||
edits,
|
||||
[("Program.cs", search_text, replace_text)]
|
||||
)
|
||||
search_text = 'Console.WriteLine("Hello World!");\n'
|
||||
replace_text = 'Console.WriteLine("Hello, C# World!");\n'
|
||||
self.assertEqual(edits, [("Program.cs", search_text, replace_text)])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue