(t *testing.T)
| 116 | } |
| 117 | |
| 118 | func TestEditTool_MultipleEdit(t *testing.T) { |
| 119 | if testing.Short() { |
| 120 | t.Skip("Skipping file modification test in short mode") |
| 121 | } |
| 122 | |
| 123 | tool, err := NewEditTool(nil) |
| 124 | if err != nil { |
| 125 | t.Fatalf("Failed to create Edit tool: %v", err) |
| 126 | } |
| 127 | |
| 128 | // 创建测试文件 |
| 129 | helper := NewTestHelper(t) |
| 130 | testFile := helper.CreateTempFile("test.txt", "Hello World\nHello World\nHello World") |
| 131 | defer helper.CleanupAll() |
| 132 | |
| 133 | input := map[string]any{ |
| 134 | "file_path": testFile, |
| 135 | "old_string": "Hello World", |
| 136 | "new_string": "Hello Universe", |
| 137 | "replace_all": true, |
| 138 | } |
| 139 | |
| 140 | result := ExecuteToolWithRealFS(t, tool, input) |
| 141 | result = AssertToolSuccess(t, result) |
| 142 | |
| 143 | // 验证多个修改 |
| 144 | if changes, exists := result["changes_made"]; !exists || changes.(int) != 3 { |
| 145 | t.Errorf("Should indicate 3 changes were made, got %v", result["changes_made"]) |
| 146 | } |
| 147 | |
| 148 | // 验证所有实例都被替换 |
| 149 | content := helper.ReadFile(testFile) |
| 150 | if strings.Count(content, "Hello Universe") != 3 { |
| 151 | t.Error("All instances should be replaced") |
| 152 | } |
| 153 | if strings.Contains(content, "Hello World") { |
| 154 | t.Error("No old strings should remain") |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | func TestEditTool_MissingString(t *testing.T) { |
| 159 | tool, err := NewEditTool(nil) |
nothing calls this directly
no test coverage detected