summaryrefslogtreecommitdiff
path: root/tests-clar/diff
diff options
context:
space:
mode:
authoryorah <yoram.harmelin@gmail.com>2012-07-02 11:18:01 +0200
committeryorah <yoram.harmelin@gmail.com>2012-07-02 17:27:49 +0200
commit29f9186d1b772994f65bb87ac88180d7d9d4141b (patch)
treeb9652b39ddd52bbf931c95b019a1c348c2a6bc25 /tests-clar/diff
parente560aa8ffa7cf143fbd34a5aec44741ae4c77271 (diff)
downloadlibgit2-29f9186d1b772994f65bb87ac88180d7d9d4141b.tar.gz
diff: make inter-hunk-context default value git-compliant
Default in git core is 0, not 3
Diffstat (limited to 'tests-clar/diff')
-rw-r--r--tests-clar/diff/blob.c70
-rw-r--r--tests-clar/diff/iterator.c4
2 files changed, 67 insertions, 7 deletions
diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c
index 6d7ad41d6..5d3ab8d56 100644
--- a/tests-clar/diff/blob.c
+++ b/tests-clar/diff/blob.c
@@ -14,13 +14,13 @@ void test_diff_blob__initialize(void)
memset(&opts, 0, sizeof(opts));
opts.context_lines = 1;
- opts.interhunk_lines = 1;
+ opts.interhunk_lines = 0;
memset(&expected, 0, sizeof(expected));
/* tests/resources/attr/root_test4.txt */
- cl_git_pass(git_oid_fromstrn(&oid, "fe773770c5a6", 12));
- cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 6));
+ cl_git_pass(git_oid_fromstrn(&oid, "a0f7217a", 8));
+ cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 4));
/* alien.png */
cl_git_pass(git_oid_fromstrn(&oid, "edf3dcee", 8));
@@ -54,6 +54,7 @@ void test_diff_blob__can_compare_text_blobs(void)
/* Doing the equivalent of a `git diff -U1` on these files */
+ /* diff on tests/resources/attr/root_test1 */
cl_git_pass(git_diff_blobs(
a, b, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
@@ -67,6 +68,7 @@ void test_diff_blob__can_compare_text_blobs(void)
cl_assert(expected.line_adds == 5);
cl_assert(expected.line_dels == 0);
+ /* diff on tests/resources/attr/root_test2 */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
b, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
@@ -81,6 +83,7 @@ void test_diff_blob__can_compare_text_blobs(void)
cl_assert(expected.line_adds == 9);
cl_assert(expected.line_dels == 3);
+ /* diff on tests/resources/attr/root_test3 */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
a, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
@@ -95,8 +98,6 @@ void test_diff_blob__can_compare_text_blobs(void)
cl_assert(expected.line_adds == 12);
cl_assert(expected.line_dels == 1);
- opts.context_lines = 1;
-
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
c, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
@@ -252,3 +253,62 @@ void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void)
assert_binary_blobs_comparison(expected);
}
+
+/*
+ * $ git diff fe773770 a0f7217
+ * diff --git a/fe773770 b/a0f7217
+ * index fe77377..a0f7217 100644
+ * --- a/fe773770
+ * +++ b/a0f7217
+ * @@ -1,6 +1,6 @@
+ * Here is some stuff at the start
+ *
+ * -This should go in one hunk
+ * +This should go in one hunk (first)
+ *
+ * Some additional lines
+ *
+ * @@ -8,7 +8,7 @@ Down here below the other lines
+ *
+ * With even more at the end
+ *
+ * -Followed by a second hunk of stuff
+ * +Followed by a second hunk of stuff (second)
+ *
+ * That happens down here
+ */
+void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void)
+{
+ git_blob *old_d;
+ git_oid old_d_oid;
+
+ opts.context_lines = 3;
+
+ /* tests/resources/attr/root_test1 from commit f5b0af1 */
+ cl_git_pass(git_oid_fromstrn(&old_d_oid, "fe773770", 8));
+ cl_git_pass(git_blob_lookup_prefix(&old_d, g_repo, &old_d_oid, 4));
+
+ /* Test with default inter-hunk-context (not set) => default is 0 */
+ cl_git_pass(git_diff_blobs(
+ old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+
+ cl_assert(expected.hunks == 2);
+
+ /* Test with inter-hunk-context explicitly set to 0 */
+ opts.interhunk_lines = 0;
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blobs(
+ old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+
+ cl_assert(expected.hunks == 2);
+
+ /* Test with inter-hunk-context explicitly set to 1 */
+ opts.interhunk_lines = 1;
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_blobs(
+ old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
+
+ cl_assert(expected.hunks == 1);
+
+ git_blob_free(old_d);
+}
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index eee84810a..c27d3fa6c 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -312,7 +312,7 @@ static const char *expected_index_oids_0[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
- "fe773770c5a6cc7185580c9204b1ff18a33ff3fc",
+ "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
@@ -343,7 +343,7 @@ static const char *expected_index_oids_range[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
- "fe773770c5a6cc7185580c9204b1ff18a33ff3fc",
+ "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
};
void test_diff_iterator__index_range(void)