(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func 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 | |
| 65 | func checkHunk(t *testing.T, label string, hunk, want BlameHunk) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…