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

Function TestParseDiffText_Rename

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

10// the parser reads content at the NEW path instead of warning about the old
11// path ("cannot read file ... exit status 128").
12func TestParseDiffText_Rename(t *testing.T) {
13 diffText := `diff --git a/pkg/old name.go b/pkg/new name.go
14similarity index 95%
15rename from pkg/old name.go
16rename to pkg/new name.go
17index 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.

Callers

nothing calls this directly

Calls 1

ParseDiffTextFunction · 0.85

Tested by

no test coverage detected