(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestEditTool_SimpleEdit(t *testing.T) { |
| 76 | if testing.Short() { |
| 77 | t.Skip("Skipping file modification test in short mode") |
| 78 | } |
| 79 | |
| 80 | tool, err := NewEditTool(nil) |
| 81 | if err != nil { |
| 82 | t.Fatalf("Failed to create Edit tool: %v", err) |
| 83 | } |
| 84 | |
| 85 | // 创建测试文件 |
| 86 | helper := NewTestHelper(t) |
| 87 | testFile := helper.CreateTempFile("test.txt", "Hello World\nThis is a test\nGoodbye") |
| 88 | defer helper.CleanupAll() |
| 89 | |
| 90 | input := map[string]any{ |
| 91 | "file_path": testFile, |
| 92 | "old_string": "Hello World", |
| 93 | "new_string": "Hello Universe", |
| 94 | } |
| 95 | |
| 96 | result := ExecuteToolWithRealFS(t, tool, input) |
| 97 | result = AssertToolSuccess(t, result) |
| 98 | |
| 99 | // 验证响应字段 |
| 100 | if success, exists := result["success"]; !exists || !success.(bool) { |
| 101 | t.Error("Edit operation should succeed") |
| 102 | } |
| 103 | |
| 104 | if changes, exists := result["changes_made"]; !exists || changes.(int) != 1 { |
| 105 | t.Error("Should indicate 1 change was made") |
| 106 | } |
| 107 | |
| 108 | // 验证文件内容确实被修改 |
| 109 | content := helper.ReadFile(testFile) |
| 110 | if !strings.Contains(content, "Hello Universe") { |
| 111 | t.Error("File should contain the new string") |
| 112 | } |
| 113 | if strings.Contains(content, "Hello World") { |
| 114 | t.Error("File should not contain the old string") |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | func TestEditTool_MultipleEdit(t *testing.T) { |
| 119 | if testing.Short() { |
nothing calls this directly
no test coverage detected