返回 DeepSeek-Reasonix
delete_range_samedge_test.go
根目录 / internal / tool / builtin / delete_range_samedge_test.go
1 package builtin
2
3 import (
4 "context"
5 "encoding/json"
6 "os"
7 "path/filepath"
8 "strings"
9 "testing"
10 )
11
12 // TestDeleteRangeSameAnchorNonInclusiveNoDup probes the degenerate but valid
13 // call where start_anchor == end_anchor (one unique line) with inclusive=false.
14 // "delete nothing between a line and itself" must not corrupt the file; the
15 // overlap in the keep slices would otherwise duplicate that line.
16 func TestDeleteRangeSameAnchorNonInclusiveNoDup(t *testing.T) {
17 dir := t.TempDir()
18 path := filepath.Join(dir, "f.txt")
19 if err := os.WriteFile(path, []byte("A\nB\nC\n"), 0o644); err != nil {
20 t.Fatal(err)
21 }
22 args, _ := json.Marshal(map[string]any{
23 "path": path,
24 "start_anchor": "B",
25 "end_anchor": "B",
26 "inclusive": false,
27 })
28 _, err := deleteRange{}.Execute(context.Background(), args)
29 got, _ := os.ReadFile(path)
30 if strings.Count(string(got), "B") > 1 {
31 t.Fatalf("line B was duplicated — file corrupted: %q (err=%v)", string(got), err)
32 }
33 }
34
34 lines GO