]> git.proxmox.com Git - libgit2.git/blame - tests-clar/diff/blob.c
diff: remove unused parameter
[libgit2.git] / tests-clar / diff / blob.c
CommitLineData
3a437590
RB
1#include "clar_libgit2.h"
2#include "diff_helpers.h"
3
4static git_repository *g_repo = NULL;
5
6void test_diff_blob__initialize(void)
7{
854eccbb 8 g_repo = cl_git_sandbox_init("attr");
3a437590
RB
9}
10
11void test_diff_blob__cleanup(void)
12{
854eccbb 13 cl_git_sandbox_cleanup();
3a437590
RB
14}
15
16void test_diff_blob__0(void)
17{
18 git_blob *a, *b, *c, *d;
19 git_oid a_oid, b_oid, c_oid, d_oid;
a2e895be 20 git_diff_options opts = {0};
3a437590
RB
21 diff_expects exp;
22
23 /* tests/resources/attr/root_test1 */
24 cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8));
25 cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4));
26
27 /* tests/resources/attr/root_test2 */
28 cl_git_pass(git_oid_fromstrn(&b_oid, "4d713dc4", 8));
29 cl_git_pass(git_blob_lookup_prefix(&b, g_repo, &b_oid, 4));
30
31 /* tests/resources/attr/root_test3 */
32 cl_git_pass(git_oid_fromstrn(&c_oid, "c96bbb2c2557a832", 16));
33 cl_git_pass(git_blob_lookup_prefix(&c, g_repo, &c_oid, 8));
34
35 /* tests/resources/attr/root_test4.txt */
36 cl_git_pass(git_oid_fromstrn(&d_oid, "fe773770c5a6", 12));
37 cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &d_oid, 6));
38
39 /* Doing the equivalent of a `git diff -U1` on these files */
40
41 opts.context_lines = 1;
a2e895be 42 opts.interhunk_lines = 1;
3a437590
RB
43
44 memset(&exp, 0, sizeof(exp));
45 cl_git_pass(git_diff_blobs(
7826d577 46 a, b, &opts, &exp, diff_hunk_fn, diff_line_fn));
3a437590
RB
47
48 cl_assert(exp.hunks == 1);
49 cl_assert(exp.lines == 6);
50 cl_assert(exp.line_ctxt == 1);
51 cl_assert(exp.line_adds == 5);
52 cl_assert(exp.line_dels == 0);
53
54 memset(&exp, 0, sizeof(exp));
55 cl_git_pass(git_diff_blobs(
7826d577 56 b, c, &opts, &exp, diff_hunk_fn, diff_line_fn));
3a437590
RB
57
58 cl_assert(exp.hunks == 1);
59 cl_assert(exp.lines == 15);
60 cl_assert(exp.line_ctxt == 3);
61 cl_assert(exp.line_adds == 9);
62 cl_assert(exp.line_dels == 3);
63
64 memset(&exp, 0, sizeof(exp));
65 cl_git_pass(git_diff_blobs(
7826d577 66 a, c, &opts, &exp, diff_hunk_fn, diff_line_fn));
3a437590
RB
67
68 cl_assert(exp.hunks == 1);
69 cl_assert(exp.lines == 13);
70 cl_assert(exp.line_ctxt == 0);
71 cl_assert(exp.line_adds == 12);
72 cl_assert(exp.line_dels == 1);
73
74 opts.context_lines = 1;
75
76 memset(&exp, 0, sizeof(exp));
77 cl_git_pass(git_diff_blobs(
7826d577 78 c, d, &opts, &exp, diff_hunk_fn, diff_line_fn));
3a437590
RB
79
80 cl_assert(exp.hunks == 2);
81 cl_assert(exp.lines == 14);
82 cl_assert(exp.line_ctxt == 4);
83 cl_assert(exp.line_adds == 6);
84 cl_assert(exp.line_dels == 4);
85
86 git_blob_free(a);
87 git_blob_free(b);
88 git_blob_free(c);
89 git_blob_free(d);
90}
91