TestParseDiffText_Rename guards against issue #99: a renamed file must be recognized via the "rename from"/"rename to" extended header lines so that the parser reads content at the NEW path instead of warning about the old path ("cannot read file ... exit status 128").
(t *testing.T)
| 10 | // the parser reads content at the NEW path instead of warning about the old |
| 11 | // path ("cannot read file ... exit status 128"). |
| 12 | func TestParseDiffText_Rename(t *testing.T) { |
| 13 | diffText := `diff --git a/pkg/old name.go b/pkg/new name.go |
| 14 | similarity index 95% |
| 15 | rename from pkg/old name.go |
| 16 | rename to pkg/new name.go |
| 17 | index 1234567..89abcde 100644 |
| 18 | --- a/pkg/old name.go |
| 19 | +++ b/pkg/new name.go |
| 20 | @@ -1,3 +1,3 @@ |
| 21 | line1 |
| 22 | -line2 |
| 23 | +line2 changed |
| 24 | line3 |
| 25 | ` |
| 26 | diffs, err := ParseDiffText(context.Background(), diffText, t.TempDir(), "", nil) |
| 27 | if err != nil { |
| 28 | t.Fatalf("ParseDiffText: %v", err) |
| 29 | } |
| 30 | if len(diffs) != 1 { |
| 31 | t.Fatalf("expected 1 diff, got %d", len(diffs)) |
| 32 | } |
| 33 | d := diffs[0] |
| 34 | if !d.IsRenamed { |
| 35 | t.Errorf("IsRenamed = false, want true") |
| 36 | } |
| 37 | if d.OldPath != "pkg/old name.go" { |
| 38 | t.Errorf("OldPath = %q, want %q", d.OldPath, "pkg/old name.go") |
| 39 | } |
| 40 | if d.NewPath != "pkg/new name.go" { |
| 41 | t.Errorf("NewPath = %q, want %q", d.NewPath, "pkg/new name.go") |
| 42 | } |
| 43 | if d.IsNew || d.IsDeleted { |
| 44 | t.Errorf("IsNew/IsDeleted = %v/%v, want false/false", d.IsNew, d.IsDeleted) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // TestParseDiffText_PureRename covers a 100% similarity rename, which carries |
| 49 | // no hunks and no ---/+++ lines at all. |
nothing calls this directly
no test coverage detected