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

Function TestParseDiffText_NewFile

internal/diff/parser_test.go:145–173  ·  view source on GitHub ↗

TestParseDiffText_NewFile covers "--- /dev/null" (no a/ prefix).

(t *testing.T)

Source from the content-addressed store, hash-verified

143
144// TestParseDiffText_NewFile covers "--- /dev/null" (no a/ prefix).
145func TestParseDiffText_NewFile(t *testing.T) {
146 diffText := `diff --git a/fresh.go b/fresh.go
147new file mode 100644
148index 0000000..1234567
149--- /dev/null
150+++ b/fresh.go
151@@ -0,0 +1,2 @@
152+line1
153+line2
154`
155 repo := t.TempDir()
156 diffs, err := ParseDiffText(context.Background(), diffText, repo, "", nil)
157 if err != nil {
158 t.Fatalf("ParseDiffText: %v", err)
159 }
160 if len(diffs) != 1 {
161 t.Fatalf("expected 1 diff, got %d", len(diffs))
162 }
163 d := diffs[0]
164 if !d.IsNew {
165 t.Errorf("IsNew = false, want true")
166 }
167 if d.IsDeleted {
168 t.Errorf("IsDeleted = true, want false")
169 }
170 if d.Insertions != 2 {
171 t.Errorf("Insertions = %d, want 2", d.Insertions)
172 }
173}
174
175// TestParseDiffText_BinaryMarkerAnchored guards two binary-detection cases:
176// a text file whose CONTENT mentions "Binary files " must not be classified

Callers

nothing calls this directly

Calls 1

ParseDiffTextFunction · 0.85

Tested by

no test coverage detected