forked from coveord/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blame_test.go
73 lines (63 loc) · 1.68 KB
/
blame_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package git
import (
"reflect"
"testing"
)
func TestBlame(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
commitId1, _ := seedTestRepo(t, repo)
commitId2, _ := updateReadme(t, repo, "foo\nbar\nbaz\n")
opts := BlameOptions{
NewestCommit: commitId2,
OldestCommit: nil,
MinLine: 1,
MaxLine: 3,
}
blame, err := repo.BlameFile("README", &opts)
checkFatal(t, err)
defer blame.Free()
if blame.HunkCount() != 2 {
t.Errorf("got hunk count %d, want 2", blame.HunkCount())
}
wantHunk1 := BlameHunk{
LinesInHunk: 1,
FinalCommitId: commitId1,
FinalStartLineNumber: 1,
OrigCommitId: commitId1,
OrigPath: "README",
OrigStartLineNumber: 1,
Boundary: true,
}
wantHunk2 := BlameHunk{
LinesInHunk: 2,
FinalCommitId: commitId2,
FinalStartLineNumber: 2,
OrigCommitId: commitId2,
OrigPath: "README",
OrigStartLineNumber: 2,
Boundary: false,
}
hunk1, err := blame.HunkByIndex(0)
checkFatal(t, err)
checkHunk(t, "index 0", hunk1, wantHunk1)
hunk2, err := blame.HunkByIndex(1)
checkFatal(t, err)
checkHunk(t, "index 1", hunk2, wantHunk2)
hunkLine1, err := blame.HunkByLine(1)
checkFatal(t, err)
checkHunk(t, "line 1", hunkLine1, wantHunk1)
hunkLine2, err := blame.HunkByLine(3)
checkFatal(t, err)
checkHunk(t, "line 2", hunkLine2, wantHunk2)
}
func checkHunk(t *testing.T, label string, hunk, want BlameHunk) {
hunk.FinalSignature = nil
want.FinalSignature = nil
hunk.OrigSignature = nil
want.OrigSignature = nil
if !reflect.DeepEqual(hunk, want) {
t.Fatalf("%s: got hunk %+v, want %+v", label, hunk, want)
}
}