go for the full line match first

This commit is contained in:
Paul Gauthier 2023-08-03 14:59:59 -03:00
parent 004c0529c6
commit e60a332fda
2 changed files with 7 additions and 6 deletions

View file

@ -151,13 +151,14 @@ def replace_most_similar_chunk(whole, part, replace):
part_lines = part.splitlines(keepends=True)
replace_lines = replace.splitlines(keepends=True)
if part_lines in whole_lines:
updated_lines = whole_lines.replace(part_lines, replace_lines)
return updated_lines
res = replace_part_with_missing_leading_whitespace(whole_lines, part_lines, replace_lines)
if res:
return res
if part in whole:
return whole.replace(part, replace)
try:
res = try_dotdotdots(whole, part, replace)
except ValueError:

View file

@ -23,9 +23,9 @@ class TestUtils(unittest.TestCase):
def test_replace_most_similar_chunk(self):
whole = "This is a sample text.\nAnother line of text.\nYet another line.\n"
part = "This is a sample text"
replace = "This is a replaced text."
expected_output = "This is a replaced text..\nAnother line of text.\nYet another line.\n"
part = "This is a sample text\n"
replace = "This is a replaced text.\n"
expected_output = "This is a replaced text.\nAnother line of text.\nYet another line.\n"
result = eb.replace_most_similar_chunk(whole, part, replace)
self.assertEqual(result, expected_output)