@@ -11,6 +11,28 @@ def editor():
11
11
return TextEditor ()
12
12
13
13
14
+ @pytest .mark .asyncio
15
+ async def test_edit_file_with_edit_patch_object (editor , tmp_path ):
16
+ """Test editing a file using EditPatch object."""
17
+ test_file = tmp_path / "test.txt"
18
+ test_file .write_text ("line1\n line2\n line3\n " )
19
+ file_hash = editor .calculate_hash (test_file .read_text ())
20
+ first_line_content = "line1\n "
21
+
22
+ # Create an EditPatch object
23
+ patch = EditPatch (
24
+ line_start = 1 ,
25
+ line_end = 1 ,
26
+ contents = "new line\n " ,
27
+ range_hash = editor .calculate_hash (first_line_content ),
28
+ )
29
+
30
+ result = await editor .edit_file_contents (str (test_file ), file_hash , [patch ])
31
+
32
+ assert result ["result" ] == "ok"
33
+ assert test_file .read_text () == "new line\n line2\n line3\n "
34
+
35
+
14
36
@pytest .fixture
15
37
def test_file (tmp_path ):
16
38
"""Create a temporary test file."""
@@ -795,3 +817,27 @@ async def test_dict_patch_with_defaults(editor: TextEditor, tmp_path):
795
817
assert result ["result" ] == "ok"
796
818
# Should replace line 1 when range_hash is provided
797
819
assert test_file .read_text () == "new line\n line2\n line3\n "
820
+
821
+
822
+ @pytest .mark .asyncio
823
+ async def test_edit_file_without_line_end (editor , tmp_path ):
824
+ """Test editing a file using dictionary patch without line_end."""
825
+ test_file = tmp_path / "test.txt"
826
+ content = "line1\n line2\n line3\n "
827
+ test_file .write_text (content )
828
+
829
+ # Create a patch with minimal fields
830
+ patch = EditPatch (
831
+ contents = "new line\n " ,
832
+ line_start = 1 ,
833
+ line_end = 1 , # 明示的にline_endを設定
834
+ range_hash = editor .calculate_hash ("line1\n " ),
835
+ )
836
+
837
+ # Calculate file hash from original content
838
+ file_hash = editor .calculate_hash (content )
839
+
840
+ result = await editor .edit_file_contents (str (test_file ), file_hash , [patch ])
841
+
842
+ assert result ["result" ] == "ok"
843
+ assert test_file .read_text () == "new line\n line2\n line3\n "
0 commit comments