MCPcopy Create free account
hub / github.com/astercloud/aster / TestEditTool_MultipleEdit

Function TestEditTool_MultipleEdit

pkg/tools/builtin/edit_test.go:118–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

116}
117
118func 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
158func TestEditTool_MissingString(t *testing.T) {
159 tool, err := NewEditTool(nil)

Callers

nothing calls this directly

Calls 9

CreateTempFileMethod · 0.95
CleanupAllMethod · 0.95
ReadFileMethod · 0.95
NewEditToolFunction · 0.85
NewTestHelperFunction · 0.85
ExecuteToolWithRealFSFunction · 0.85
AssertToolSuccessFunction · 0.85
CountMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected