]>
Commit | Line | Data |
---|---|---|
ceab4e26 BS |
1 | #include "blame_helpers.h" |
2 | ||
3 | void hunk_message(size_t idx, const git_blame_hunk *hunk, const char *fmt, ...) | |
4 | { | |
5 | va_list arglist; | |
6 | ||
cb1cb24c | 7 | printf("Hunk %"PRIuZ" (line %"PRIuZ" +%"PRIuZ"): ", idx, |
ceab4e26 BS |
8 | hunk->final_start_line_number, hunk->lines_in_hunk-1); |
9 | ||
10 | va_start(arglist, fmt); | |
11 | vprintf(fmt, arglist); | |
12 | va_end(arglist); | |
13 | ||
14 | printf("\n"); | |
15 | } | |
16 | ||
17 | void check_blame_hunk_index(git_repository *repo, git_blame *blame, int idx, | |
cb1cb24c | 18 | size_t start_line, size_t len, char boundary, const char *commit_id, const char *orig_path) |
ceab4e26 | 19 | { |
3b2cb2c9 | 20 | char expected[GIT_OID_HEXSZ+1] = {0}, actual[GIT_OID_HEXSZ+1] = {0}; |
ceab4e26 BS |
21 | const git_blame_hunk *hunk = git_blame_get_hunk_byindex(blame, idx); |
22 | cl_assert(hunk); | |
23 | ||
24 | if (!strncmp(commit_id, "0000", 4)) { | |
25 | strcpy(expected, "0000000000000000000000000000000000000000"); | |
26 | } else { | |
27 | git_object *obj; | |
28 | cl_git_pass(git_revparse_single(&obj, repo, commit_id)); | |
29 | git_oid_fmt(expected, git_object_id(obj)); | |
30 | git_object_free(obj); | |
31 | } | |
32 | ||
33 | if (hunk->final_start_line_number != start_line) { | |
66a70851 | 34 | hunk_message(idx, hunk, "mismatched start line number: expected %"PRIuZ", got %"PRIuZ, |
ceab4e26 BS |
35 | start_line, hunk->final_start_line_number); |
36 | } | |
37 | cl_assert_equal_i(hunk->final_start_line_number, start_line); | |
38 | ||
39 | if (hunk->lines_in_hunk != len) { | |
66a70851 | 40 | hunk_message(idx, hunk, "mismatched line count: expected %"PRIuZ", got %"PRIuZ, |
ceab4e26 BS |
41 | len, hunk->lines_in_hunk); |
42 | } | |
43 | cl_assert_equal_i(hunk->lines_in_hunk, len); | |
44 | ||
45 | git_oid_fmt(actual, &hunk->final_commit_id); | |
46 | if (strcmp(expected, actual)) { | |
47 | hunk_message(idx, hunk, "has mismatched original id (got %s, expected %s)\n", | |
48 | actual, expected); | |
49 | } | |
50 | cl_assert_equal_s(actual, expected); | |
0cee70eb | 51 | cl_assert_equal_oid(&hunk->final_commit_id, &hunk->orig_commit_id); |
b92b434f X |
52 | |
53 | ||
ceab4e26 BS |
54 | if (strcmp(hunk->orig_path, orig_path)) { |
55 | hunk_message(idx, hunk, "has mismatched original path (got '%s', expected '%s')\n", | |
56 | hunk->orig_path, orig_path); | |
57 | } | |
58 | cl_assert_equal_s(hunk->orig_path, orig_path); | |
25c47aae BS |
59 | |
60 | if (hunk->boundary != boundary) { | |
61 | hunk_message(idx, hunk, "doesn't match boundary flag (got %d, expected %d)\n", | |
62 | hunk->boundary, boundary); | |
63 | } | |
64 | cl_assert_equal_i(boundary, hunk->boundary); | |
ceab4e26 BS |
65 | } |
66 | ||
67 |