Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2014-06-20 16:42:16 +0400
committerVicent Marti <tanoku@gmail.com>2014-06-20 16:42:16 +0400
commit28f087c8642ff9c8dd6964e101e6d8539db6281a (patch)
tree3518d1bf420e92c964bed03074575d8a1db88654 /tests/diff/blob.c
parent4b0a36e881506a02b43a4ae3c19c93c919b36eeb (diff)
parent1589aa0c4d48fb130d8a5db28c45cd3d173cde6d (diff)
libgit2 v0.21.0v0.21.0
Diffstat (limited to 'tests/diff/blob.c')
-rw-r--r--tests/diff/blob.c317
1 files changed, 129 insertions, 188 deletions
diff --git a/tests/diff/blob.c b/tests/diff/blob.c
index 93f20711c..527007965 100644
--- a/tests/diff/blob.c
+++ b/tests/diff/blob.c
@@ -26,7 +26,7 @@ void test_diff_blob__initialize(void)
g_repo = cl_git_sandbox_init("attr");
- cl_git_pass(git_diff_options_init(&opts, GIT_DIFF_OPTIONS_VERSION));
+ cl_git_pass(git_diff_init_options(&opts, GIT_DIFF_OPTIONS_VERSION));
opts.context_lines = 1;
memset(&expected, 0, sizeof(expected));
@@ -51,6 +51,20 @@ void test_diff_blob__cleanup(void)
cl_git_sandbox_cleanup();
}
+static void assert_one_modified(
+ int hunks, int lines, int ctxt, int adds, int dels, diff_expects *exp)
+{
+ cl_assert_equal_i(1, exp->files);
+ cl_assert_equal_i(1, exp->file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(0, exp->files_binary);
+
+ cl_assert_equal_i(hunks, exp->hunks);
+ cl_assert_equal_i(lines, exp->lines);
+ cl_assert_equal_i(ctxt, exp->line_ctxt);
+ cl_assert_equal_i(adds, exp->line_adds);
+ cl_assert_equal_i(dels, exp->line_dels);
+}
+
void test_diff_blob__can_compare_text_blobs(void)
{
git_blob *a, *b, *c;
@@ -71,79 +85,81 @@ 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 */
+ memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
a, NULL, b, NULL, &opts,
diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_one_modified(1, 6, 1, 5, 0, &expected);
- cl_assert_equal_i(1, expected.files);
- cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, expected.files_binary);
-
- cl_assert_equal_i(1, expected.hunks);
- cl_assert_equal_i(6, expected.lines);
- cl_assert_equal_i(1, expected.line_ctxt);
- cl_assert_equal_i(5, expected.line_adds);
- cl_assert_equal_i(0, expected.line_dels);
+ /* same diff but use direct buffers */
+ memset(&expected, 0, sizeof(expected));
+ cl_git_pass(git_diff_buffers(
+ git_blob_rawcontent(a), (size_t)git_blob_rawsize(a), NULL,
+ git_blob_rawcontent(b), (size_t)git_blob_rawsize(b), NULL, &opts,
+ diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_one_modified(1, 6, 1, 5, 0, &expected);
/* diff on tests/resources/attr/root_test2 */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
b, NULL, c, NULL, &opts,
diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
-
- cl_assert_equal_i(1, expected.files);
- cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, expected.files_binary);
-
- cl_assert_equal_i(1, expected.hunks);
- cl_assert_equal_i(15, expected.lines);
- cl_assert_equal_i(3, expected.line_ctxt);
- cl_assert_equal_i(9, expected.line_adds);
- cl_assert_equal_i(3, expected.line_dels);
+ assert_one_modified(1, 15, 3, 9, 3, &expected);
/* diff on tests/resources/attr/root_test3 */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
a, NULL, c, NULL, &opts,
diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
-
- cl_assert_equal_i(1, expected.files);
- cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, expected.files_binary);
-
- cl_assert_equal_i(1, expected.hunks);
- cl_assert_equal_i(13, expected.lines);
- cl_assert_equal_i(0, expected.line_ctxt);
- cl_assert_equal_i(12, expected.line_adds);
- cl_assert_equal_i(1, expected.line_dels);
+ assert_one_modified(1, 13, 0, 12, 1, &expected);
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
c, NULL, d, NULL, &opts,
diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
-
- cl_assert_equal_i(1, expected.files);
- cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, expected.files_binary);
-
- cl_assert_equal_i(2, expected.hunks);
- cl_assert_equal_i(14, expected.lines);
- cl_assert_equal_i(4, expected.line_ctxt);
- cl_assert_equal_i(6, expected.line_adds);
- cl_assert_equal_i(4, expected.line_dels);
+ assert_one_modified(2, 14, 4, 6, 4, &expected);
git_blob_free(a);
git_blob_free(b);
git_blob_free(c);
}
+static void assert_patch_matches_blobs(
+ git_patch *p, git_blob *a, git_blob *b,
+ int hunks, int l0, int l1, int ctxt, int adds, int dels)
+{
+ const git_diff_delta *delta;
+ size_t tc, ta, td;
+
+ cl_assert(p != NULL);
+
+ delta = git_patch_get_delta(p);
+ cl_assert(delta != NULL);
+
+ cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
+ cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.id));
+ cl_assert_equal_sz(git_blob_rawsize(a), delta->old_file.size);
+ cl_assert(git_oid_equal(git_blob_id(b), &delta->new_file.id));
+ cl_assert_equal_sz(git_blob_rawsize(b), delta->new_file.size);
+
+ cl_assert_equal_i(hunks, (int)git_patch_num_hunks(p));
+
+ if (hunks > 0)
+ cl_assert_equal_i(l0, git_patch_num_lines_in_hunk(p, 0));
+ if (hunks > 1)
+ cl_assert_equal_i(l1, git_patch_num_lines_in_hunk(p, 1));
+
+ cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
+ cl_assert_equal_i(ctxt, (int)tc);
+ cl_assert_equal_i(adds, (int)ta);
+ cl_assert_equal_i(dels, (int)td);
+}
+
void test_diff_blob__can_compare_text_blobs_with_patch(void)
{
git_blob *a, *b, *c;
git_oid a_oid, b_oid, c_oid;
git_patch *p;
- const git_diff_delta *delta;
- size_t tc, ta, td;
/* tests/resources/attr/root_test1 */
cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8));
@@ -161,92 +177,22 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
/* diff on tests/resources/attr/root_test1 */
cl_git_pass(git_patch_from_blobs(&p, a, NULL, b, NULL, &opts));
-
- cl_assert(p != NULL);
-
- delta = git_patch_get_delta(p);
- cl_assert(delta != NULL);
- cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
- cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
- cl_assert_equal_sz(git_blob_rawsize(a), delta->old_file.size);
- cl_assert(git_oid_equal(git_blob_id(b), &delta->new_file.oid));
- cl_assert_equal_sz(git_blob_rawsize(b), delta->new_file.size);
-
- cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
- cl_assert_equal_i(6, git_patch_num_lines_in_hunk(p, 0));
-
- cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
- cl_assert_equal_i(1, (int)tc);
- cl_assert_equal_i(5, (int)ta);
- cl_assert_equal_i(0, (int)td);
-
+ assert_patch_matches_blobs(p, a, b, 1, 6, 0, 1, 5, 0);
git_patch_free(p);
/* diff on tests/resources/attr/root_test2 */
cl_git_pass(git_patch_from_blobs(&p, b, NULL, c, NULL, &opts));
-
- cl_assert(p != NULL);
-
- delta = git_patch_get_delta(p);
- cl_assert(delta != NULL);
- cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
- cl_assert(git_oid_equal(git_blob_id(b), &delta->old_file.oid));
- cl_assert_equal_sz(git_blob_rawsize(b), delta->old_file.size);
- cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
- cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
-
- cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
- cl_assert_equal_i(15, git_patch_num_lines_in_hunk(p, 0));
-
- cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
- cl_assert_equal_i(3, (int)tc);
- cl_assert_equal_i(9, (int)ta);
- cl_assert_equal_i(3, (int)td);
-
+ assert_patch_matches_blobs(p, b, c, 1, 15, 0, 3, 9, 3);
git_patch_free(p);
/* diff on tests/resources/attr/root_test3 */
cl_git_pass(git_patch_from_blobs(&p, a, NULL, c, NULL, &opts));
-
- cl_assert(p != NULL);
-
- delta = git_patch_get_delta(p);
- cl_assert(delta != NULL);
- cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
- cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
- cl_assert_equal_sz(git_blob_rawsize(a), delta->old_file.size);
- cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
- cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
-
- cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
- cl_assert_equal_i(0, (int)tc);
- cl_assert_equal_i(12, (int)ta);
- cl_assert_equal_i(1, (int)td);
-
+ assert_patch_matches_blobs(p, a, c, 1, 13, 0, 0, 12, 1);
git_patch_free(p);
/* one more */
cl_git_pass(git_patch_from_blobs(&p, c, NULL, d, NULL, &opts));
-
- cl_assert(p != NULL);
-
- delta = git_patch_get_delta(p);
- cl_assert(delta != NULL);
- cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
- cl_assert(git_oid_equal(git_blob_id(c), &delta->old_file.oid));
- cl_assert_equal_sz(git_blob_rawsize(c), delta->old_file.size);
- cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
- cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
-
- cl_assert_equal_i(2, (int)git_patch_num_hunks(p));
- cl_assert_equal_i(5, git_patch_num_lines_in_hunk(p, 0));
- cl_assert_equal_i(9, git_patch_num_lines_in_hunk(p, 1));
-
- cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
- cl_assert_equal_i(4, (int)tc);
- cl_assert_equal_i(6, (int)ta);
- cl_assert_equal_i(4, (int)td);
-
+ assert_patch_matches_blobs(p, c, d, 2, 5, 9, 4, 6, 4);
git_patch_free(p);
git_blob_free(a);
@@ -328,9 +274,9 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
- cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.oid));
+ cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.id));
cl_assert_equal_sz(git_blob_rawsize(d), delta->old_file.size);
- cl_assert(git_oid_iszero(&delta->new_file.oid));
+ cl_assert(git_oid_iszero(&delta->new_file.id));
cl_assert_equal_sz(0, delta->new_file.size);
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
@@ -353,9 +299,9 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
- cl_assert(git_oid_iszero(&delta->old_file.oid));
+ cl_assert(git_oid_iszero(&delta->old_file.id));
cl_assert_equal_sz(0, delta->old_file.size);
- cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
+ cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.id));
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
@@ -446,9 +392,9 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
cl_assert_equal_sz(delta->old_file.size, git_blob_rawsize(d));
- cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.oid));
+ cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.id));
cl_assert_equal_sz(delta->new_file.size, git_blob_rawsize(d));
- cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
+ cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.id));
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
git_patch_free(p);
@@ -460,9 +406,9 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
cl_assert_equal_sz(0, delta->old_file.size);
- cl_assert(git_oid_iszero(&delta->old_file.oid));
+ cl_assert(git_oid_iszero(&delta->old_file.id));
cl_assert_equal_sz(0, delta->new_file.size);
- cl_assert(git_oid_iszero(&delta->new_file.oid));
+ cl_assert(git_oid_iszero(&delta->new_file.id));
cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
git_patch_free(p);
@@ -656,14 +602,7 @@ void test_diff_blob__can_compare_blob_to_buffer(void)
/* diff from blob a to content of b */
quick_diff_blob_to_str(a, NULL, b_content, 0, NULL);
- cl_assert_equal_i(1, expected.files);
- cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, expected.files_binary);
- cl_assert_equal_i(1, expected.hunks);
- cl_assert_equal_i(6, expected.lines);
- cl_assert_equal_i(1, expected.line_ctxt);
- cl_assert_equal_i(5, expected.line_adds);
- cl_assert_equal_i(0, expected.line_dels);
+ assert_one_modified(1, 6, 1, 5, 0, &expected);
/* diff from blob a to content of a */
opts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
@@ -853,7 +792,7 @@ void test_diff_blob__using_path_and_attributes(void)
size_t bin_len = 33;
const char *changed;
git_patch *p;
- char *pout;
+ git_buf buf = GIT_BUF_INIT;
/* set up custom diff drivers and 'diff' attribute mappings for them */
@@ -861,15 +800,15 @@ void test_diff_blob__using_path_and_attributes(void)
cl_git_pass(git_config_set_bool(cfg, "diff.iam_binary.binary", 1));
cl_git_pass(git_config_set_bool(cfg, "diff.iam_text.binary", 0));
cl_git_pass(git_config_set_string(
- cfg, "diff.iam_alphactx.xfuncname", "^[A-Za-z]"));
+ cfg, "diff.iam_alphactx.xfuncname", "^[A-Za-z].*$"));
cl_git_pass(git_config_set_bool(cfg, "diff.iam_textalpha.binary", 0));
cl_git_pass(git_config_set_string(
- cfg, "diff.iam_textalpha.xfuncname", "^[A-Za-z]"));
+ cfg, "diff.iam_textalpha.xfuncname", "^[A-Za-z].*$"));
cl_git_pass(git_config_set_string(
- cfg, "diff.iam_numctx.funcname", "^[0-9]"));
+ cfg, "diff.iam_numctx.funcname", "^[0-9][0-9]*"));
cl_git_pass(git_config_set_bool(cfg, "diff.iam_textnum.binary", 0));
cl_git_pass(git_config_set_string(
- cfg, "diff.iam_textnum.funcname", "^[0-9]"));
+ cfg, "diff.iam_textnum.funcname", "^[0-9][0-9]*"));
git_config_free(cfg);
cl_git_append2file(
@@ -910,14 +849,7 @@ void test_diff_blob__using_path_and_attributes(void)
changed = "Hello from the root\nMore lines\nAnd more\nGo here\n";
quick_diff_blob_to_str(nonbin, NULL, changed, 0, NULL);
- cl_assert_equal_i(1, expected.files);
- cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, expected.files_binary);
- cl_assert_equal_i(1, expected.hunks);
- cl_assert_equal_i(3, expected.lines);
- cl_assert_equal_i(0, expected.line_ctxt);
- cl_assert_equal_i(3, expected.line_adds);
- cl_assert_equal_i(0, expected.line_dels);
+ assert_one_modified(1, 3, 0, 3, 0, &expected);
quick_diff_blob_to_str(nonbin, "foo/bar.binary", changed, 0, NULL);
cl_assert_equal_i(1, expected.files);
@@ -925,33 +857,16 @@ void test_diff_blob__using_path_and_attributes(void)
cl_assert_equal_i(1, expected.files_binary);
cl_assert_equal_i(0, expected.hunks);
cl_assert_equal_i(0, expected.lines);
- cl_assert_equal_i(0, expected.line_ctxt);
- cl_assert_equal_i(0, expected.line_adds);
- cl_assert_equal_i(0, expected.line_dels);
quick_diff_blob_to_str(nonbin, "foo/bar.textary", changed, 0, NULL);
- cl_assert_equal_i(1, expected.files);
- cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, expected.files_binary);
- cl_assert_equal_i(1, expected.hunks);
- cl_assert_equal_i(3, expected.lines);
- cl_assert_equal_i(0, expected.line_ctxt);
- cl_assert_equal_i(3, expected.line_adds);
- cl_assert_equal_i(0, expected.line_dels);
+ assert_one_modified(1, 3, 0, 3, 0, &expected);
quick_diff_blob_to_str(nonbin, "foo/bar.alphary", changed, 0, NULL);
- cl_assert_equal_i(1, expected.files);
- cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, expected.files_binary);
- cl_assert_equal_i(1, expected.hunks);
- cl_assert_equal_i(3, expected.lines);
- cl_assert_equal_i(0, expected.line_ctxt);
- cl_assert_equal_i(3, expected.line_adds);
- cl_assert_equal_i(0, expected.line_dels);
+ assert_one_modified(1, 3, 0, 3, 0, &expected);
cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.normal", changed, strlen(changed), NULL, &opts));
- cl_git_pass(git_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_buf(&buf, p));
cl_assert_equal_s(
"diff --git a/zzz.normal b/zzz.normal\n"
"index 45141a7..75b0dbb 100644\n"
@@ -960,23 +875,23 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -1,0 +2,3 @@ Hello from the root\n"
"+More lines\n"
"+And more\n"
- "+Go here\n", pout);
- git__free(pout);
+ "+Go here\n", buf.ptr);
+ git_buf_clear(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.binary", changed, strlen(changed), NULL, &opts));
- cl_git_pass(git_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_buf(&buf, p));
cl_assert_equal_s(
"diff --git a/zzz.binary b/zzz.binary\n"
"index 45141a7..75b0dbb 100644\n"
- "Binary files a/zzz.binary and b/zzz.binary differ\n", pout);
- git__free(pout);
+ "Binary files a/zzz.binary and b/zzz.binary differ\n", buf.ptr);
+ git_buf_clear(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.alphary", changed, strlen(changed), NULL, &opts));
- cl_git_pass(git_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_buf(&buf, p));
cl_assert_equal_s(
"diff --git a/zzz.alphary b/zzz.alphary\n"
"index 45141a7..75b0dbb 100644\n"
@@ -985,13 +900,13 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -1,0 +2,3 @@ Hello from the root\n"
"+More lines\n"
"+And more\n"
- "+Go here\n", pout);
- git__free(pout);
+ "+Go here\n", buf.ptr);
+ git_buf_clear(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.numary", changed, strlen(changed), NULL, &opts));
- cl_git_pass(git_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_buf(&buf, p));
cl_assert_equal_s(
"diff --git a/zzz.numary b/zzz.numary\n"
"index 45141a7..75b0dbb 100644\n"
@@ -1000,8 +915,8 @@ void test_diff_blob__using_path_and_attributes(void)
"@@ -1,0 +2,3 @@\n"
"+More lines\n"
"+And more\n"
- "+Go here\n", pout);
- git__free(pout);
+ "+Go here\n", buf.ptr);
+ git_buf_clear(&buf);
git_patch_free(p);
/* "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n"
@@ -1012,17 +927,17 @@ void test_diff_blob__using_path_and_attributes(void)
cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.normal", changed, 37, NULL, &opts));
- cl_git_pass(git_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_buf(&buf, p));
cl_assert_equal_s(
"diff --git a/zzz.normal b/zzz.normal\n"
"index b435cd5..1604519 100644\n"
- "Binary files a/zzz.normal and b/zzz.normal differ\n", pout);
- git__free(pout);
+ "Binary files a/zzz.normal and b/zzz.normal differ\n", buf.ptr);
+ git_buf_clear(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textary", changed, 37, NULL, &opts));
- cl_git_pass(git_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_buf(&buf, p));
cl_assert_equal_s(
"diff --git a/zzz.textary b/zzz.textary\n"
"index b435cd5..1604519 100644\n"
@@ -1030,13 +945,13 @@ void test_diff_blob__using_path_and_attributes(void)
"+++ b/zzz.textary\n"
"@@ -3 +3 @@\n"
"-0123456789\n"
- "+replace a line\n", pout);
- git__free(pout);
+ "+replace a line\n", buf.ptr);
+ git_buf_clear(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textalphary", changed, 37, NULL, &opts));
- cl_git_pass(git_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_buf(&buf, p));
cl_assert_equal_s(
"diff --git a/zzz.textalphary b/zzz.textalphary\n"
"index b435cd5..1604519 100644\n"
@@ -1044,13 +959,13 @@ void test_diff_blob__using_path_and_attributes(void)
"+++ b/zzz.textalphary\n"
"@@ -3 +3 @@\n"
"-0123456789\n"
- "+replace a line\n", pout);
- git__free(pout);
+ "+replace a line\n", buf.ptr);
+ git_buf_clear(&buf);
git_patch_free(p);
cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textnumary", changed, 37, NULL, &opts));
- cl_git_pass(git_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_buf(&buf, p));
cl_assert_equal_s(
"diff --git a/zzz.textnumary b/zzz.textnumary\n"
"index b435cd5..1604519 100644\n"
@@ -1058,10 +973,36 @@ void test_diff_blob__using_path_and_attributes(void)
"+++ b/zzz.textnumary\n"
"@@ -3 +3 @@ 0123456789\n"
"-0123456789\n"
- "+replace a line\n", pout);
- git__free(pout);
+ "+replace a line\n", buf.ptr);
+ git_buf_clear(&buf);
git_patch_free(p);
+ git_buf_free(&buf);
git_blob_free(nonbin);
git_blob_free(bin);
}
+
+void test_diff_blob__can_compare_buffer_to_buffer(void)
+{
+ const char *a = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\n";
+ const char *b = "a\nB\nc\nd\nE\nF\nh\nj\nk\n";
+
+ opts.interhunk_lines = 0;
+ opts.context_lines = 0;
+
+ memset(&expected, 0, sizeof(expected));
+
+ cl_git_pass(git_diff_buffers(
+ a, strlen(a), NULL, b, strlen(b), NULL,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_one_modified(4, 9, 0, 4, 5, &expected);
+
+ opts.flags ^= GIT_DIFF_REVERSE;
+
+ memset(&expected, 0, sizeof(expected));
+
+ cl_git_pass(git_diff_buffers(
+ a, strlen(a), NULL, b, strlen(b), NULL,
+ &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected));
+ assert_one_modified(4, 9, 0, 5, 4, &expected);
+}