diff options
Diffstat (limited to 'diff_test.go')
| -rw-r--r-- | diff_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/diff_test.go b/diff_test.go index 464fae6..850ed8e 100644 --- a/diff_test.go +++ b/diff_test.go @@ -187,3 +187,50 @@ func createTestTrees(t *testing.T, repo *Repository) (originalTree *Tree, newTre return originalTree, newTree } + +func TestDiffBlobs(t *testing.T) { + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + odb, err := repo.Odb() + checkFatal(t, err) + + id1, err := odb.Write([]byte("hello\nhello\n"), ObjectBlob) + checkFatal(t, err) + + id2, err := odb.Write([]byte("hallo\nhallo\n"), ObjectBlob) + checkFatal(t, err) + + blob1, err := repo.LookupBlob(id1) + checkFatal(t, err) + + blob2, err := repo.LookupBlob(id2) + checkFatal(t, err) + + var files, hunks, lines int + err = DiffBlobs(blob1, "hi", blob2, "hi", nil, + func(delta DiffDelta, progress float64) (DiffForEachHunkCallback, error) { + files++ + return func(hunk DiffHunk) (DiffForEachLineCallback, error) { + hunks++ + return func(line DiffLine) error { + lines++ + return nil + }, nil + }, nil + }, + DiffDetailLines) + + if files != 1 { + t.Fatal("Bad number of files iterated") + } + + if hunks != 1 { + t.Fatal("Bad number of hunks iterated") + } + + // two removals, two additions + if lines != 4 { + t.Fatalf("Bad number of lines iterated") + } +} |
