summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-04-29 19:42:51 +0200
committernulltoken <emeric.fermas@gmail.com>2012-04-30 07:12:26 +0200
commit1d2dd864add4835c49744a566c226a1c7da04e99 (patch)
tree6314a29891ef1e652203052aba3bc523793abe2c /tests-clar
parentda3c187d5e3f8dae63014a4dab0dd2c72baed2d5 (diff)
downloadlibgit2-1d2dd864add4835c49744a566c226a1c7da04e99.tar.gz
diff: provide more context to the consumer of the callbacks
Update the callback to provide some information related to the file change being processed and the range of the hunk, when applicable.
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/diff/diff_helpers.c2
-rw-r--r--tests-clar/diff/diff_helpers.h1
-rw-r--r--tests-clar/diff/patch.c44
3 files changed, 40 insertions, 7 deletions
diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c
index c9a633cd..85dd5260 100644
--- a/tests-clar/diff/diff_helpers.c
+++ b/tests-clar/diff/diff_helpers.c
@@ -60,12 +60,14 @@ int diff_hunk_fn(
int diff_line_fn(
void *cb_data,
git_diff_delta *delta,
+ git_diff_range *range,
char line_origin,
const char *content,
size_t content_len)
{
diff_expects *e = cb_data;
(void)delta;
+ (void)range;
(void)content;
(void)content_len;
e->lines++;
diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h
index 010d156f..ca8c4017 100644
--- a/tests-clar/diff/diff_helpers.h
+++ b/tests-clar/diff/diff_helpers.h
@@ -37,6 +37,7 @@ extern int diff_hunk_fn(
extern int diff_line_fn(
void *cb_data,
git_diff_delta *delta,
+ git_diff_range *range,
char line_origin,
const char *content,
size_t content_len);
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c
index e2576277..3da9ce82 100644
--- a/tests-clar/diff/patch.c
+++ b/tests-clar/diff/patch.c
@@ -13,26 +13,56 @@ void test_diff_patch__cleanup(void)
cl_git_sandbox_cleanup();
}
-#define EXPECTED_OUTPUT "diff --git a/subdir.txt b/subdir.txt\n" \
+#define EXPECTED_HEADER "diff --git a/subdir.txt b/subdir.txt\n" \
"deleted file mode 100644\n" \
"index e8ee89e..0000000\n" \
"--- a/subdir.txt\n" \
"+++ /dev/null\n"
+#define EXPECTED_HUNK "@@ -1,2 +0,0 @@\n"
+
static int check_removal_cb(
void *cb_data,
+ git_diff_delta *delta,
+ git_diff_range *range,
char line_origin,
- const char *formatted_output)
+ const char *formatted_output,
+ size_t output_len)
{
GIT_UNUSED(cb_data);
- if (line_origin != 'F')
- return 0;
+ switch (line_origin) {
+ case GIT_DIFF_LINE_FILE_HDR:
+ cl_assert_equal_s(EXPECTED_HEADER, formatted_output);
+ cl_assert(range == NULL);
+ goto check_delta;
+
+ case GIT_DIFF_LINE_HUNK_HDR:
+ cl_assert_equal_s(EXPECTED_HUNK, formatted_output);
+ /* Fall through */
+
+ case GIT_DIFF_LINE_CONTEXT:
+ case GIT_DIFF_LINE_DELETION:
+ goto check_range;
+
+ default:
+ /* unexpected code path */
+ return -1;
+ }
+
+check_range:
+ cl_assert(range != NULL);
+ cl_assert_equal_i(1, range->old_start);
+ cl_assert_equal_i(2, range->old_lines);
+ cl_assert_equal_i(0, range->new_start);
+ cl_assert_equal_i(0, range->new_lines);
- if (strcmp(EXPECTED_OUTPUT, formatted_output) == 0)
- return 0;
+check_delta:
+ cl_assert_equal_s("subdir.txt", delta->old.path);
+ cl_assert_equal_s("subdir.txt", delta->new.path);
+ cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
- return -1;
+ return 0;
}
void test_diff_patch__can_properly_display_the_removal_of_a_file(void)