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)
| 52 | // the parser reads content at the NEW path instead of warning about the old |
| 53 | // path ("cannot read file ... exit status 128"). |
| 54 | func TestParseDiffText_Rename(t *testing.T) { |
| 55 | diffText := `diff --git a/pkg/old name.go b/pkg/new name.go |
| 56 | similarity index 95% |
| 57 | rename from pkg/old name.go |
| 58 | rename to pkg/new name.go |
| 59 | index 1234567..89abcde 100644 |
| 60 | --- a/pkg/old name.go |
| 61 | +++ b/pkg/new name.go |
| 62 | @@ -1,3 +1,3 @@ |
| 63 | line1 |
| 64 | -line2 |
| 65 | +line2 changed |
| 66 | line3 |
| 67 | ` |
| 68 | diffs, err := ParseDiffText(context.Background(), diffText, t.TempDir(), "", nil) |
| 69 | if err != nil { |
| 70 | t.Fatalf("ParseDiffText: %v", err) |
| 71 | } |
| 72 | if len(diffs) != 1 { |
| 73 | t.Fatalf("expected 1 diff, got %d", len(diffs)) |
| 74 | } |
| 75 | d := diffs[0] |
| 76 | if !d.IsRenamed { |
| 77 | t.Errorf("IsRenamed = false, want true") |
| 78 | } |
| 79 | if d.OldPath != "pkg/old name.go" { |
| 80 | t.Errorf("OldPath = %q, want %q", d.OldPath, "pkg/old name.go") |
| 81 | } |
| 82 | if d.NewPath != "pkg/new name.go" { |
| 83 | t.Errorf("NewPath = %q, want %q", d.NewPath, "pkg/new name.go") |
| 84 | } |
| 85 | if d.IsNew || d.IsDeleted { |
| 86 | t.Errorf("IsNew/IsDeleted = %v/%v, want false/false", d.IsNew, d.IsDeleted) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // TestParseDiffText_PureRename covers a 100% similarity rename, which carries |
| 91 | // no hunks and no ---/+++ lines at all. |
nothing calls this directly
no test coverage detected