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

Function TestBlame

blame_test.go:8–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestBlame(t *testing.T) {
9 t.Parallel()
10 repo := createTestRepo(t)
11 defer cleanupTestRepo(t, repo)
12
13 commitId1, _ := seedTestRepo(t, repo)
14 commitId2, _ := updateReadme(t, repo, "foo\nbar\nbaz\n")
15
16 opts := BlameOptions{
17 NewestCommit: commitId2,
18 OldestCommit: nil,
19 MinLine: 1,
20 MaxLine: 3,
21 }
22 blame, err := repo.BlameFile("README", &opts)
23 checkFatal(t, err)
24 defer blame.Free()
25 if blame.HunkCount() != 2 {
26 t.Errorf("got hunk count %d, want 2", blame.HunkCount())
27 }
28
29 wantHunk1 := BlameHunk{
30 LinesInHunk: 1,
31 FinalCommitId: commitId1,
32 FinalStartLineNumber: 1,
33 OrigCommitId: commitId1,
34 OrigPath: "README",
35 OrigStartLineNumber: 1,
36 Boundary: true,
37 }
38 wantHunk2 := BlameHunk{
39 LinesInHunk: 2,
40 FinalCommitId: commitId2,
41 FinalStartLineNumber: 2,
42 OrigCommitId: commitId2,
43 OrigPath: "README",
44 OrigStartLineNumber: 2,
45 Boundary: false,
46 }
47
48 hunk1, err := blame.HunkByIndex(0)
49 checkFatal(t, err)
50 checkHunk(t, "index 0", hunk1, wantHunk1)
51
52 hunk2, err := blame.HunkByIndex(1)
53 checkFatal(t, err)
54 checkHunk(t, "index 1", hunk2, wantHunk2)
55
56 hunkLine1, err := blame.HunkByLine(1)
57 checkFatal(t, err)
58 checkHunk(t, "line 1", hunkLine1, wantHunk1)
59
60 hunkLine2, err := blame.HunkByLine(3)
61 checkFatal(t, err)
62 checkHunk(t, "line 2", hunkLine2, wantHunk2)
63}
64
65func checkHunk(t *testing.T, label string, hunk, want BlameHunk) {

Callers

nothing calls this directly

Calls 11

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
seedTestRepoFunction · 0.85
updateReadmeFunction · 0.85
checkFatalFunction · 0.85
checkHunkFunction · 0.85
BlameFileMethod · 0.80
HunkCountMethod · 0.80
HunkByIndexMethod · 0.80
HunkByLineMethod · 0.80
FreeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…