diff options
author | Edward Thomson <ethomson@github.com> | 2016-04-25 16:47:48 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2016-06-25 23:08:04 -0400 |
commit | e774d5af764c521f3a5740f8c0f7b859ebb109c8 (patch) | |
tree | 9577efa758999bb6478d633e3f5abdd28705f44b /tests/diff/diff_helpers.c | |
parent | 853e585fb13475073c7000d74934f6c96c1e1a47 (diff) | |
download | libgit2-e774d5af764c521f3a5740f8c0f7b859ebb109c8.tar.gz |
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.
Diffstat (limited to 'tests/diff/diff_helpers.c')
-rw-r--r-- | tests/diff/diff_helpers.c | 36 |
1 files changed, 36 insertions, 0 deletions
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); + } +} + |