From e774d5af764c521f3a5740f8c0f7b859ebb109c8 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 25 Apr 2016 16:47:48 -0400 Subject: diff::parse tests: test parsing a diff Test that we can create a diff file, then parse the results and that the two are identical in-memory. --- tests/diff/diff_helpers.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/diff/diff_helpers.c') diff --git a/tests/diff/diff_helpers.c b/tests/diff/diff_helpers.c index c6cdf803f..8fa8e3eb5 100644 --- a/tests/diff/diff_helpers.c +++ b/tests/diff/diff_helpers.c @@ -241,3 +241,39 @@ void diff_print_raw(FILE *fp, git_diff *diff) git_diff_print(diff, GIT_DIFF_FORMAT_RAW, git_diff_print_callback__to_file_handle, fp ? fp : stderr)); } + +void diff_assert_equal(git_diff *a, git_diff *b) +{ + const git_diff_delta *ad, *bd; + size_t i; + + assert(a && b); + + cl_assert_equal_i(git_diff_num_deltas(a), git_diff_num_deltas(b)); + + for (i = 0; i < git_diff_num_deltas(a); i++) { + ad = git_diff_get_delta(a, i); + bd = git_diff_get_delta(b, i); + + cl_assert_equal_i(ad->status, bd->status); + cl_assert_equal_i(ad->flags, bd->flags); + cl_assert_equal_i(ad->similarity, bd->similarity); + cl_assert_equal_i(ad->nfiles, bd->nfiles); + + /* Don't examine the size or the flags of the deltas; + * computed deltas have sizes (parsed deltas do not) and + * computed deltas will have flags of `VALID_ID` and + * `EXISTS` (parsed deltas will not query the ODB.) + */ + cl_assert_equal_oid(&ad->old_file.id, &bd->old_file.id); + cl_assert_equal_i(ad->old_file.id_abbrev, bd->old_file.id_abbrev); + cl_assert_equal_s(ad->old_file.path, bd->old_file.path); + cl_assert_equal_i(ad->old_file.mode, bd->old_file.mode); + + cl_assert_equal_oid(&ad->new_file.id, &bd->new_file.id); + cl_assert_equal_i(ad->new_file.id_abbrev, bd->new_file.id_abbrev); + cl_assert_equal_s(ad->new_file.path, bd->new_file.path); + cl_assert_equal_i(ad->new_file.mode, bd->new_file.mode); + } +} + -- cgit v1.2.1