Skip to content

Commit a89ab67

Browse files
author
Yoshihiro Takahara
committed
Add test case for dictionary patch with defaults
1 parent 31dbc50 commit a89ab67

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_text_editor.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,30 @@ async def test_append_mode(editor, tmp_path):
768768

769769
assert result["result"] == "ok"
770770
assert test_file.read_text() == original_content + append_content
771+
772+
773+
@pytest.mark.asyncio
774+
async def test_dict_patch_with_defaults(editor: TextEditor, tmp_path):
775+
"""Test dictionary patch with default values."""
776+
test_file = tmp_path / "test.txt"
777+
original_content = "line1\nline2\nline3\n"
778+
test_file.write_text(original_content)
779+
780+
# Get first line content and calculate hashes
781+
first_line_content, _, _, _, _, _ = await editor.read_file_contents(
782+
str(test_file), line_start=1, line_end=1
783+
)
784+
file_hash = editor.calculate_hash(original_content)
785+
786+
# Edit using dict patch with missing optional fields
787+
patch = {
788+
"contents": "new line\n", # Add newline to maintain file structure
789+
"line_start": 1,
790+
"line_end": 1, # Explicitly specify line_end
791+
"range_hash": editor.calculate_hash(first_line_content),
792+
}
793+
result = await editor.edit_file_contents(str(test_file), file_hash, [patch])
794+
795+
assert result["result"] == "ok"
796+
# Should replace line 1 when range_hash is provided
797+
assert test_file.read_text() == "new line\nline2\nline3\n"

0 commit comments

Comments
 (0)