MCPcopy Create free account
hub / github.com/libgit2/git2go / TestDiffBlobs

Function TestDiffBlobs

diff_test.go:195–241  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

193}
194
195func TestDiffBlobs(t *testing.T) {
196 t.Parallel()
197 repo := createTestRepo(t)
198 defer cleanupTestRepo(t, repo)
199
200 odb, err := repo.Odb()
201 checkFatal(t, err)
202
203 id1, err := odb.Write([]byte("hello\nhello\n"), ObjectBlob)
204 checkFatal(t, err)
205
206 id2, err := odb.Write([]byte("hallo\nhallo\n"), ObjectBlob)
207 checkFatal(t, err)
208
209 blob1, err := repo.LookupBlob(id1)
210 checkFatal(t, err)
211
212 blob2, err := repo.LookupBlob(id2)
213 checkFatal(t, err)
214
215 var files, hunks, lines int
216 err = DiffBlobs(blob1, "hi", blob2, "hi", nil,
217 func(delta DiffDelta, progress float64) (DiffForEachHunkCallback, error) {
218 files++
219 return func(hunk DiffHunk) (DiffForEachLineCallback, error) {
220 hunks++
221 return func(line DiffLine) error {
222 lines++
223 return nil
224 }, nil
225 }, nil
226 },
227 DiffDetailLines)
228
229 if files != 1 {
230 t.Fatal("Bad number of files iterated")
231 }
232
233 if hunks != 1 {
234 t.Fatal("Bad number of hunks iterated")
235 }
236
237 // two removals, two additions
238 if lines != 4 {
239 t.Fatalf("Bad number of lines iterated")
240 }
241}
242
243func TestApplyDiffAddfile(t *testing.T) {
244 repo := createTestRepo(t)

Callers

nothing calls this directly

Calls 7

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
checkFatalFunction · 0.85
DiffBlobsFunction · 0.85
OdbMethod · 0.80
LookupBlobMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…