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

Function TestParseDiffText_Rename

internal/diff/parser_test.go:54–88  ·  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

52// the parser reads content at the NEW path instead of warning about the old
53// path ("cannot read file ... exit status 128").
54func TestParseDiffText_Rename(t *testing.T) {
55 diffText := `diff --git a/pkg/old name.go b/pkg/new name.go
56similarity index 95%
57rename from pkg/old name.go
58rename to pkg/new name.go
59index 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.

Callers

nothing calls this directly

Calls 1

ParseDiffTextFunction · 0.85

Tested by

no test coverage detected