| 💾 Saved. d722711 k33g 4h ago | 1 | package tools |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "mm/internal/fileedit" |
| 8 | ) |
| 9 | |
| 10 | // TestClip: a display line is scanned, not read. A hundred columns, one line — |
| 11 | // the same rule as the command recap, and the same reason: a multi-line old |
| 12 | // text printed whole would be longer than the diff it announces. |
| 13 | func TestClip(t *testing.T) { |
| 14 | if got := clip("📝 edit_file: a.go\n (2 edits)"); got != "📝 edit_file: a.go (2 edits)" { |
| 15 | t.Errorf("clip folded to %q", got) |
| 16 | } |
| 17 | long := clip("📄 read_file: " + strings.Repeat("x", 200)) |
| 18 | if r := []rune(long); len(r) != maxDisplayWidth || r[len(r)-1] != '…' { |
| 19 | t.Errorf("clip = %d runes ending %q, want %d ending …", len(r), string(r[len(r)-1]), maxDisplayWidth) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // TestEditKeyTellsRetriesApart: the loop detector must see a corrected edit as |
| 24 | // a NEW action. Keying on the path alone made "same path, different old text" |
| 25 | // look like a repeat, and the detector fired on a model that was fixing itself. |
| 26 | func TestEditKeyTellsRetriesApart(t *testing.T) { |
| 27 | a := editKey(editFileInput{Path: "f.go", Edits: []fileedit.Edit{{Old: "x", New: "y"}}}) |
| 28 | b := editKey(editFileInput{Path: "f.go", Edits: []fileedit.Edit{{Old: "x2", New: "y"}}}) |
| 29 | same := editKey(editFileInput{Path: "f.go", Edits: []fileedit.Edit{{Old: "x", New: "y"}}}) |
| 30 | if a == b || a != same { |
| 31 | t.Errorf("editKey: a=%q b=%q same=%q", a, b, same) |
| 32 | } |
| 33 | } |