diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-02-28 16:14:47 -0800 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-02 15:49:29 -0800 |
commit | 74fa4bfae37e9d7c9e35550c881b114d7a83c4fa (patch) | |
tree | 98184643a8c42b1402e4b33f835eac424fe88768 /tests-clar/diff/tree.c | |
parent | 760db29c456ef2029a81d577d95a3fafb37ce5c6 (diff) | |
download | libgit2-74fa4bfae37e9d7c9e35550c881b114d7a83c4fa.tar.gz |
Update diff to use iterators
This is a major reorganization of the diff code. This changes
the diff functions to use the iterators for traversing the
content. This allowed a lot of code to be simplified. Also,
this moved the functions relating to outputting a diff into a
new file (diff_output.c).
This includes a number of other changes - adding utility
functions, extending iterators, etc. plus more tests for the
diff code. This also takes the example diff.c program much
further in terms of emulating git-diff command line options.
Diffstat (limited to 'tests-clar/diff/tree.c')
-rw-r--r-- | tests-clar/diff/tree.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index eb4092af..f5fdfba1 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -100,7 +100,7 @@ void test_diff_tree__options(void) git_diff_options opts = {0}; git_diff_list *diff = NULL; - diff_expects exp; + diff_expects actual; int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 }; git_diff_options test_options[] = { /* a vs b tests */ @@ -123,25 +123,26 @@ void test_diff_tree__options(void) */ diff_expects test_expects[] = { /* a vs b tests */ - { 5, 3, 0, 2, 4, 0, 0, 51, 2, 46, 3 }, - { 5, 3, 0, 2, 4, 0, 0, 53, 4, 46, 3 }, - { 5, 0, 3, 2, 4, 0, 0, 52, 3, 3, 46 }, - { 5, 3, 0, 2, 5, 0, 0, 54, 3, 48, 3 }, + { 5, 3, 0, 2, 0, 0, 4, 0, 0, 51, 2, 46, 3 }, + { 5, 3, 0, 2, 0, 0, 4, 0, 0, 53, 4, 46, 3 }, + { 5, 0, 3, 2, 0, 0, 4, 0, 0, 52, 3, 3, 46 }, + { 5, 3, 0, 2, 0, 0, 5, 0, 0, 54, 3, 48, 3 }, /* c vs d tests */ - { 1, 0, 0, 1, 1, 0, 0, 22, 9, 10, 3 }, - { 1, 0, 0, 1, 1, 0, 0, 19, 12, 7, 0 }, - { 1, 0, 0, 1, 1, 0, 0, 20, 11, 8, 1 }, - { 1, 0, 0, 1, 1, 0, 0, 20, 11, 8, 1 }, - { 1, 0, 0, 1, 1, 0, 0, 18, 11, 0, 7 }, + { 1, 0, 0, 1, 0, 0, 1, 0, 0, 22, 9, 10, 3 }, + { 1, 0, 0, 1, 0, 0, 1, 0, 0, 19, 12, 7, 0 }, + { 1, 0, 0, 1, 0, 0, 1, 0, 0, 20, 11, 8, 1 }, + { 1, 0, 0, 1, 0, 0, 1, 0, 0, 20, 11, 8, 1 }, + { 1, 0, 0, 1, 0, 0, 1, 0, 0, 18, 11, 0, 7 }, { 0 }, }; + diff_expects *expected; int i; cl_assert(a); cl_assert(b); for (i = 0; test_expects[i].files > 0; i++) { - memset(&exp, 0, sizeof(exp)); /* clear accumulator */ + memset(&actual, 0, sizeof(actual)); /* clear accumulator */ opts = test_options[i]; if (test_ab_or_cd[i] == 0) @@ -150,17 +151,18 @@ void test_diff_tree__options(void) cl_git_pass(git_diff_tree_to_tree(g_repo, &opts, c, d, &diff)); cl_git_pass(git_diff_foreach( - diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); - - cl_assert(exp.files == test_expects[i].files); - cl_assert(exp.file_adds == test_expects[i].file_adds); - cl_assert(exp.file_dels == test_expects[i].file_dels); - cl_assert(exp.file_mods == test_expects[i].file_mods); - cl_assert(exp.hunks == test_expects[i].hunks); - cl_assert(exp.lines == test_expects[i].lines); - cl_assert(exp.line_ctxt == test_expects[i].line_ctxt); - cl_assert(exp.line_adds == test_expects[i].line_adds); - cl_assert(exp.line_dels == test_expects[i].line_dels); + diff, &actual, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + expected = &test_expects[i]; + cl_assert_intequal(actual.files, expected->files); + cl_assert_intequal(actual.file_adds, expected->file_adds); + cl_assert_intequal(actual.file_dels, expected->file_dels); + cl_assert_intequal(actual.file_mods, expected->file_mods); + cl_assert_intequal(actual.hunks, expected->hunks); + cl_assert_intequal(actual.lines, expected->lines); + cl_assert_intequal(actual.line_ctxt, expected->line_ctxt); + cl_assert_intequal(actual.line_adds, expected->line_adds); + cl_assert_intequal(actual.line_dels, expected->line_dels); git_diff_list_free(diff); diff = NULL; |