(t *testing.T)
| 79 | } |
| 80 | |
| 81 | func TestEditFileOldNotUnique(t *testing.T) { |
| 82 | dir := t.TempDir() |
| 83 | path := filepath.Join(dir, "f.txt") |
| 84 | if err := os.WriteFile(path, []byte("foo bar foo"), 0o644); err != nil { |
| 85 | t.Fatal(err) |
| 86 | } |
| 87 | s := EditFile(path, "foo", "qux") |
| 88 | if !strings.Contains(s, "appears") || !strings.Contains(s, "2") { |
| 89 | t.Fatalf("bad: %q", s) |
| 90 | } |
| 91 | got, _ := os.ReadFile(path) |
| 92 | if string(got) != "foo bar foo" { |
| 93 | t.Fatalf("file modified on ambiguity: %q", got) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // TestEditFileOverlappingOldString: strings.Count sees only one |
| 98 | // non-overlapping "==" in "a === b", but it matches at two positions with |
nothing calls this directly
no test coverage detected