]> git.proxmox.com Git - libgit2.git/blame - tests/libgit2/blame/getters.c
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / libgit2 / blame / getters.c
CommitLineData
ceab4e26
BS
1#include "clar_libgit2.h"
2
3#include "blame.h"
4
5git_blame *g_blame;
6
7void test_blame_getters__initialize(void)
8{
9 size_t i;
10 git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
11
12 git_blame_hunk hunks[] = {
4fd847bb
BS
13 { 3, {{0}}, 1, NULL, {{0}}, "a", 0},
14 { 3, {{0}}, 4, NULL, {{0}}, "b", 0},
15 { 3, {{0}}, 7, NULL, {{0}}, "c", 0},
16 { 3, {{0}}, 10, NULL, {{0}}, "d", 0},
17 { 3, {{0}}, 13, NULL, {{0}}, "e", 0},
ceab4e26
BS
18 };
19
20 g_blame = git_blame__alloc(NULL, opts, "");
21
22 for (i=0; i<5; i++) {
ef03d040 23 git_blame_hunk *h = git__calloc(1, sizeof(git_blame_hunk));
ceab4e26
BS
24 h->final_start_line_number = hunks[i].final_start_line_number;
25 h->orig_path = git__strdup(hunks[i].orig_path);
26 h->lines_in_hunk = hunks[i].lines_in_hunk;
27
28 git_vector_insert(&g_blame->hunks, h);
29 }
30}
31
32void test_blame_getters__cleanup(void)
33{
34 git_blame_free(g_blame);
35}
36
37
38void test_blame_getters__byindex(void)
39{
40 const git_blame_hunk *h = git_blame_get_hunk_byindex(g_blame, 2);
41 cl_assert(h);
42 cl_assert_equal_s(h->orig_path, "c");
43
44 h = git_blame_get_hunk_byindex(g_blame, 95);
45 cl_assert_equal_p(h, NULL);
46}
47
48void test_blame_getters__byline(void)
49{
50 const git_blame_hunk *h = git_blame_get_hunk_byline(g_blame, 5);
51 cl_assert(h);
52 cl_assert_equal_s(h->orig_path, "b");
53
54 h = git_blame_get_hunk_byline(g_blame, 95);
55 cl_assert_equal_p(h, NULL);
56}