MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestParseDiffText_Rename

Function TestParseDiffText_Rename

internal/diff/parser_test.go:57–91  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

ParseDiffTextFunction · 0.85

Tested by

no test coverage detected