]> git.proxmox.com Git - libgit2.git/blame - tests-clar/diff/blob.c
Replace diff delta binary with flags
[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;
1956693f 5static diff_expects expected;
4f806761 6static git_diff_options opts;
28ef7f9b 7static git_blob *d, *alien;
3a437590
RB
8
9void test_diff_blob__initialize(void)
10{
28ef7f9b 11 git_oid oid;
4f806761 12
854eccbb 13 g_repo = cl_git_sandbox_init("attr");
4f806761 14
0ab3a2ab 15 GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION);
4f806761 16 opts.context_lines = 1;
29f9186d 17 opts.interhunk_lines = 0;
4f806761 18
1956693f 19 memset(&expected, 0, sizeof(expected));
4f806761 20
21 /* tests/resources/attr/root_test4.txt */
29f9186d 22 cl_git_pass(git_oid_fromstrn(&oid, "a0f7217a", 8));
23 cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 4));
28ef7f9b 24
25 /* alien.png */
26 cl_git_pass(git_oid_fromstrn(&oid, "edf3dcee", 8));
27 cl_git_pass(git_blob_lookup_prefix(&alien, g_repo, &oid, 4));
3a437590
RB
28}
29
30void test_diff_blob__cleanup(void)
31{
4f806761 32 git_blob_free(d);
9094d30b
SC
33 d = NULL;
34
28ef7f9b 35 git_blob_free(alien);
9094d30b 36 alien = NULL;
4f806761 37
854eccbb 38 cl_git_sandbox_cleanup();
3a437590
RB
39}
40
245c5eae 41void test_diff_blob__can_compare_text_blobs(void)
3a437590 42{
4f806761 43 git_blob *a, *b, *c;
44 git_oid a_oid, b_oid, c_oid;
3a437590
RB
45
46 /* tests/resources/attr/root_test1 */
47 cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8));
48 cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4));
49
50 /* tests/resources/attr/root_test2 */
51 cl_git_pass(git_oid_fromstrn(&b_oid, "4d713dc4", 8));
52 cl_git_pass(git_blob_lookup_prefix(&b, g_repo, &b_oid, 4));
53
54 /* tests/resources/attr/root_test3 */
55 cl_git_pass(git_oid_fromstrn(&c_oid, "c96bbb2c2557a832", 16));
56 cl_git_pass(git_blob_lookup_prefix(&c, g_repo, &c_oid, 8));
57
3a437590
RB
58 /* Doing the equivalent of a `git diff -U1` on these files */
59
29f9186d 60 /* diff on tests/resources/attr/root_test1 */
3a437590 61 cl_git_pass(git_diff_blobs(
793c4385 62 a, b, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 63
f335ecd6 64 cl_assert_equal_i(1, expected.files);
b4f5bb07
RB
65 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
66 cl_assert_equal_i(0, expected.files_binary);
3a437590 67
f335ecd6
RB
68 cl_assert_equal_i(1, expected.hunks);
69 cl_assert_equal_i(6, expected.lines);
70 cl_assert_equal_i(1, expected.line_ctxt);
71 cl_assert_equal_i(5, expected.line_adds);
72 cl_assert_equal_i(0, expected.line_dels);
3a437590 73
29f9186d 74 /* diff on tests/resources/attr/root_test2 */
1956693f 75 memset(&expected, 0, sizeof(expected));
3a437590 76 cl_git_pass(git_diff_blobs(
793c4385 77 b, c, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 78
f335ecd6 79 cl_assert_equal_i(1, expected.files);
b4f5bb07
RB
80 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
81 cl_assert_equal_i(0, expected.files_binary);
3a437590 82
f335ecd6
RB
83 cl_assert_equal_i(1, expected.hunks);
84 cl_assert_equal_i(15, expected.lines);
85 cl_assert_equal_i(3, expected.line_ctxt);
86 cl_assert_equal_i(9, expected.line_adds);
87 cl_assert_equal_i(3, expected.line_dels);
3a437590 88
29f9186d 89 /* diff on tests/resources/attr/root_test3 */
1956693f 90 memset(&expected, 0, sizeof(expected));
3a437590 91 cl_git_pass(git_diff_blobs(
793c4385 92 a, c, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 93
f335ecd6 94 cl_assert_equal_i(1, expected.files);
b4f5bb07
RB
95 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
96 cl_assert_equal_i(0, expected.files_binary);
3a437590 97
f335ecd6
RB
98 cl_assert_equal_i(1, expected.hunks);
99 cl_assert_equal_i(13, expected.lines);
100 cl_assert_equal_i(0, expected.line_ctxt);
101 cl_assert_equal_i(12, expected.line_adds);
102 cl_assert_equal_i(1, expected.line_dels);
3a437590 103
1956693f 104 memset(&expected, 0, sizeof(expected));
3a437590 105 cl_git_pass(git_diff_blobs(
793c4385 106 c, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 107
f335ecd6 108 cl_assert_equal_i(1, expected.files);
b4f5bb07
RB
109 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
110 cl_assert_equal_i(0, expected.files_binary);
3a437590 111
f335ecd6
RB
112 cl_assert_equal_i(2, expected.hunks);
113 cl_assert_equal_i(14, expected.lines);
114 cl_assert_equal_i(4, expected.line_ctxt);
115 cl_assert_equal_i(6, expected.line_adds);
116 cl_assert_equal_i(4, expected.line_dels);
3a437590
RB
117
118 git_blob_free(a);
119 git_blob_free(b);
120 git_blob_free(c);
3a437590
RB
121}
122
4f806761 123void test_diff_blob__can_compare_against_null_blobs(void)
124{
125 git_blob *e = NULL;
126
127 cl_git_pass(git_diff_blobs(
793c4385 128 d, e, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 129
f335ecd6 130 cl_assert_equal_i(1, expected.files);
b4f5bb07
RB
131 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_DELETED]);
132 cl_assert_equal_i(0, expected.files_binary);
4f806761 133
f335ecd6
RB
134 cl_assert_equal_i(1, expected.hunks);
135 cl_assert_equal_i(14, expected.hunk_old_lines);
136 cl_assert_equal_i(14, expected.lines);
137 cl_assert_equal_i(14, expected.line_dels);
4f806761 138
139 opts.flags |= GIT_DIFF_REVERSE;
1956693f 140 memset(&expected, 0, sizeof(expected));
4f806761 141
142 cl_git_pass(git_diff_blobs(
793c4385 143 d, e, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 144
f335ecd6 145 cl_assert_equal_i(1, expected.files);
b4f5bb07
RB
146 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_ADDED]);
147 cl_assert_equal_i(0, expected.files_binary);
4f806761 148
f335ecd6
RB
149 cl_assert_equal_i(1, expected.hunks);
150 cl_assert_equal_i(14, expected.hunk_new_lines);
151 cl_assert_equal_i(14, expected.lines);
152 cl_assert_equal_i(14, expected.line_adds);
28ef7f9b 153
154 opts.flags ^= GIT_DIFF_REVERSE;
1956693f 155 memset(&expected, 0, sizeof(expected));
28ef7f9b 156
157 cl_git_pass(git_diff_blobs(
793c4385 158 alien, NULL, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 159
f335ecd6 160 cl_assert_equal_i(1, expected.files);
b4f5bb07
RB
161 cl_assert_equal_i(1, expected.files_binary);
162 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_DELETED]);
f335ecd6
RB
163 cl_assert_equal_i(0, expected.hunks);
164 cl_assert_equal_i(0, expected.lines);
28ef7f9b 165
1956693f 166 memset(&expected, 0, sizeof(expected));
28ef7f9b 167
168 cl_git_pass(git_diff_blobs(
793c4385 169 NULL, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 170
f335ecd6 171 cl_assert_equal_i(1, expected.files);
b4f5bb07
RB
172 cl_assert_equal_i(1, expected.files_binary);
173 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_ADDED]);
f335ecd6
RB
174 cl_assert_equal_i(0, expected.hunks);
175 cl_assert_equal_i(0, expected.lines);
28ef7f9b 176}
177
b4f5bb07 178static void assert_identical_blobs_comparison(diff_expects *expected)
9a29f8d5 179{
b4f5bb07
RB
180 cl_assert_equal_i(1, expected->files);
181 cl_assert_equal_i(1, expected->file_status[GIT_DELTA_UNMODIFIED]);
182 cl_assert_equal_i(0, expected->hunks);
183 cl_assert_equal_i(0, expected->lines);
9a29f8d5 184}
185
186void test_diff_blob__can_compare_identical_blobs(void)
187{
188 cl_git_pass(git_diff_blobs(
793c4385 189 d, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
9a29f8d5 190
b4f5bb07
RB
191 cl_assert_equal_i(0, expected.files_binary);
192 assert_identical_blobs_comparison(&expected);
9a29f8d5 193
1956693f 194 memset(&expected, 0, sizeof(expected));
9a29f8d5 195 cl_git_pass(git_diff_blobs(
793c4385 196 NULL, NULL, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
9a29f8d5 197
b4f5bb07
RB
198 cl_assert_equal_i(0, expected.files_binary);
199 assert_identical_blobs_comparison(&expected);
9a29f8d5 200
1956693f 201 memset(&expected, 0, sizeof(expected));
9a29f8d5 202 cl_git_pass(git_diff_blobs(
793c4385 203 alien, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
9a29f8d5 204
b4f5bb07
RB
205 cl_assert(expected.files_binary > 0);
206 assert_identical_blobs_comparison(&expected);
9a29f8d5 207}
208
b4f5bb07 209static void assert_binary_blobs_comparison(diff_expects *expected)
28ef7f9b 210{
b4f5bb07 211 cl_assert(expected->files_binary > 0);
28ef7f9b 212
b4f5bb07
RB
213 cl_assert_equal_i(1, expected->files);
214 cl_assert_equal_i(1, expected->file_status[GIT_DELTA_MODIFIED]);
215 cl_assert_equal_i(0, expected->hunks);
216 cl_assert_equal_i(0, expected->lines);
28ef7f9b 217}
218
219void test_diff_blob__can_compare_two_binary_blobs(void)
220{
221 git_blob *heart;
222 git_oid h_oid;
223
224 /* heart.png */
225 cl_git_pass(git_oid_fromstrn(&h_oid, "de863bff", 8));
226 cl_git_pass(git_blob_lookup_prefix(&heart, g_repo, &h_oid, 4));
227
228 cl_git_pass(git_diff_blobs(
793c4385 229 alien, heart, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 230
b4f5bb07 231 assert_binary_blobs_comparison(&expected);
28ef7f9b 232
1956693f 233 memset(&expected, 0, sizeof(expected));
28ef7f9b 234
235 cl_git_pass(git_diff_blobs(
793c4385 236 heart, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 237
b4f5bb07 238 assert_binary_blobs_comparison(&expected);
28ef7f9b 239
240 git_blob_free(heart);
241}
242
243void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void)
244{
245 cl_git_pass(git_diff_blobs(
793c4385 246 alien, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 247
b4f5bb07 248 assert_binary_blobs_comparison(&expected);
28ef7f9b 249
1956693f 250 memset(&expected, 0, sizeof(expected));
28ef7f9b 251
252 cl_git_pass(git_diff_blobs(
793c4385 253 d, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
28ef7f9b 254
b4f5bb07 255 assert_binary_blobs_comparison(&expected);
4f806761 256}
29f9186d 257
258/*
259 * $ git diff fe773770 a0f7217
260 * diff --git a/fe773770 b/a0f7217
261 * index fe77377..a0f7217 100644
262 * --- a/fe773770
263 * +++ b/a0f7217
264 * @@ -1,6 +1,6 @@
265 * Here is some stuff at the start
266 *
267 * -This should go in one hunk
268 * +This should go in one hunk (first)
269 *
270 * Some additional lines
271 *
272 * @@ -8,7 +8,7 @@ Down here below the other lines
273 *
274 * With even more at the end
275 *
276 * -Followed by a second hunk of stuff
277 * +Followed by a second hunk of stuff (second)
278 *
279 * That happens down here
280 */
281void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void)
282{
283 git_blob *old_d;
284 git_oid old_d_oid;
285
286 opts.context_lines = 3;
287
288 /* tests/resources/attr/root_test1 from commit f5b0af1 */
289 cl_git_pass(git_oid_fromstrn(&old_d_oid, "fe773770", 8));
290 cl_git_pass(git_blob_lookup_prefix(&old_d, g_repo, &old_d_oid, 4));
291
292 /* Test with default inter-hunk-context (not set) => default is 0 */
293 cl_git_pass(git_diff_blobs(
793c4385 294 old_d, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
29f9186d 295
f335ecd6 296 cl_assert_equal_i(2, expected.hunks);
29f9186d 297
298 /* Test with inter-hunk-context explicitly set to 0 */
299 opts.interhunk_lines = 0;
300 memset(&expected, 0, sizeof(expected));
301 cl_git_pass(git_diff_blobs(
793c4385 302 old_d, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
29f9186d 303
f335ecd6 304 cl_assert_equal_i(2, expected.hunks);
29f9186d 305
306 /* Test with inter-hunk-context explicitly set to 1 */
307 opts.interhunk_lines = 1;
308 memset(&expected, 0, sizeof(expected));
309 cl_git_pass(git_diff_blobs(
793c4385 310 old_d, d, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
29f9186d 311
f335ecd6 312 cl_assert_equal_i(1, expected.hunks);
29f9186d 313
314 git_blob_free(old_d);
315}
2f8d30be
BS
316
317void test_diff_blob__checks_options_version_too_low(void)
318{
319 const git_error *err;
320
321 opts.version = 0;
322 cl_git_fail(git_diff_blobs(
323 d, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
324 err = giterr_last();
325 cl_assert_equal_i(GITERR_INVALID, err->klass);
326}
327
328void test_diff_blob__checks_options_version_too_high(void)
329{
330 const git_error *err;
331
332 opts.version = 1024;
333 cl_git_fail(git_diff_blobs(
334 d, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
335 err = giterr_last();
336 cl_assert_equal_i(GITERR_INVALID, err->klass);
337}
a3337f10 338
339void test_diff_blob__can_correctly_detect_a_binary_blob_as_binary(void)
340{
341 /* alien.png */
342 cl_assert_equal_i(true, git_blob_is_binary(alien));
343}
344
345void test_diff_blob__can_correctly_detect_a_textual_blob_as_non_binary(void)
346{
347 /* tests/resources/attr/root_test4.txt */
348 cl_assert_equal_i(false, git_blob_is_binary(d));
349}
f2b7f7a6
RB
350
351/*
352 * git_diff_blob_to_buffer tests
353 */
354
c2c0874d
RB
355static void assert_changed_single_one_line_file(
356 diff_expects *expected, git_delta_t mod)
357{
358 cl_assert_equal_i(1, expected->files);
359 cl_assert_equal_i(1, expected->file_status[mod]);
360 cl_assert_equal_i(1, expected->hunks);
361 cl_assert_equal_i(1, expected->lines);
362
363 if (mod == GIT_DELTA_ADDED)
364 cl_assert_equal_i(1, expected->line_adds);
365 else if (mod == GIT_DELTA_DELETED)
366 cl_assert_equal_i(1, expected->line_dels);
367}
368
f2b7f7a6
RB
369void test_diff_blob__can_compare_blob_to_buffer(void)
370{
371 git_blob *a;
372 git_oid a_oid;
373 const char *a_content = "Hello from the root\n";
374 const char *b_content = "Hello from the root\n\nSome additional lines\n\nDown here below\n\n";
375
376 /* tests/resources/attr/root_test1 */
377 cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8));
378 cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4));
379
380 /* diff from blob a to content of b */
381 cl_git_pass(git_diff_blob_to_buffer(
382 a, b_content, strlen(b_content),
383 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
384
385 cl_assert_equal_i(1, expected.files);
386 cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
387 cl_assert_equal_i(0, expected.files_binary);
388 cl_assert_equal_i(1, expected.hunks);
389 cl_assert_equal_i(6, expected.lines);
390 cl_assert_equal_i(1, expected.line_ctxt);
391 cl_assert_equal_i(5, expected.line_adds);
392 cl_assert_equal_i(0, expected.line_dels);
393
394 /* diff from blob a to content of a */
395 memset(&expected, 0, sizeof(expected));
396 cl_git_pass(git_diff_blob_to_buffer(
397 a, a_content, strlen(a_content),
398 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
399
400 assert_identical_blobs_comparison(&expected);
401
402 /* diff from NULL blob to content of b */
403 memset(&expected, 0, sizeof(expected));
404 cl_git_pass(git_diff_blob_to_buffer(
405 NULL, a_content, strlen(a_content),
406 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
407
c2c0874d 408 assert_changed_single_one_line_file(&expected, GIT_DELTA_ADDED);
f2b7f7a6
RB
409
410 /* diff from blob a to NULL buffer */
411 memset(&expected, 0, sizeof(expected));
412 cl_git_pass(git_diff_blob_to_buffer(
413 a, NULL, 0,
414 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
415
c2c0874d 416 assert_changed_single_one_line_file(&expected, GIT_DELTA_DELETED);
f2b7f7a6
RB
417
418 /* diff with reverse */
419 opts.flags ^= GIT_DIFF_REVERSE;
420
421 memset(&expected, 0, sizeof(expected));
422 cl_git_pass(git_diff_blob_to_buffer(
423 a, NULL, 0,
424 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
425
c2c0874d 426 assert_changed_single_one_line_file(&expected, GIT_DELTA_ADDED);
f2b7f7a6
RB
427
428 git_blob_free(a);
429}
c2c0874d
RB
430
431
432static void assert_one_modified_with_lines(diff_expects *expected, int lines)
433{
434 cl_assert_equal_i(1, expected->files);
435 cl_assert_equal_i(1, expected->file_status[GIT_DELTA_MODIFIED]);
436 cl_assert_equal_i(0, expected->files_binary);
437 cl_assert_equal_i(lines, expected->lines);
438}
439
440void test_diff_blob__binary_data_comparisons(void)
441{
442 git_blob *bin, *nonbin;
443 git_oid oid;
444 const char *nonbin_content = "Hello from the root\n";
445 size_t nonbin_len = 20;
446 const char *bin_content = "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n";
447 size_t bin_len = 33;
448
449 cl_git_pass(git_oid_fromstrn(&oid, "45141a79", 8));
450 cl_git_pass(git_blob_lookup_prefix(&nonbin, g_repo, &oid, 4));
451
452 cl_git_pass(git_oid_fromstrn(&oid, "b435cd56", 8));
453 cl_git_pass(git_blob_lookup_prefix(&bin, g_repo, &oid, 4));
454
455 /* non-binary to reference content */
456
457 memset(&expected, 0, sizeof(expected));
458 cl_git_pass(git_diff_blob_to_buffer(
459 nonbin, nonbin_content, nonbin_len,
460 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
461 assert_identical_blobs_comparison(&expected);
462 cl_assert_equal_i(0, expected.files_binary);
463
464 /* binary to reference content */
465
466 memset(&expected, 0, sizeof(expected));
467 cl_git_pass(git_diff_blob_to_buffer(
468 bin, bin_content, bin_len,
469 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
470 assert_identical_blobs_comparison(&expected);
471
472 cl_assert_equal_i(1, expected.files_binary);
473
474 /* non-binary to binary content */
475
476 memset(&expected, 0, sizeof(expected));
477 cl_git_pass(git_diff_blob_to_buffer(
478 nonbin, bin_content, bin_len,
479 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
480 assert_binary_blobs_comparison(&expected);
481
482 /* binary to non-binary content */
483
484 memset(&expected, 0, sizeof(expected));
485 cl_git_pass(git_diff_blob_to_buffer(
486 bin, nonbin_content, nonbin_len,
487 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
488 assert_binary_blobs_comparison(&expected);
489
490 /* non-binary to binary blob */
491
492 memset(&expected, 0, sizeof(expected));
493 cl_git_pass(git_diff_blobs(
494 bin, nonbin, &opts,
495 diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
496 assert_binary_blobs_comparison(&expected);
497
498 /*
499 * repeat with FORCE_TEXT
500 */
501
502 opts.flags |= GIT_DIFF_FORCE_TEXT;
503
504 memset(&expected, 0, sizeof(expected));
505 cl_git_pass(git_diff_blob_to_buffer(
506 bin, bin_content, bin_len,
507 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
508 assert_identical_blobs_comparison(&expected);
509
510 memset(&expected, 0, sizeof(expected));
511 cl_git_pass(git_diff_blob_to_buffer(
512 nonbin, bin_content, bin_len,
513 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
514 assert_one_modified_with_lines(&expected, 4);
515
516 memset(&expected, 0, sizeof(expected));
517 cl_git_pass(git_diff_blob_to_buffer(
518 bin, nonbin_content, nonbin_len,
519 &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
520 assert_one_modified_with_lines(&expected, 4);
521
522 memset(&expected, 0, sizeof(expected));
523 cl_git_pass(git_diff_blobs(
524 bin, nonbin, &opts,
525 diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
526 assert_one_modified_with_lines(&expected, 4);
527
528 /* cleanup */
529 git_blob_free(bin);
530 git_blob_free(nonbin);
531}