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:
authorRussell Belfer <rb@github.com>2013-07-23 03:07:56 +0400
committerRussell Belfer <rb@github.com>2013-07-23 03:07:56 +0400
commitb4a4cf24a539ce07d86fed6835c98154fb40e723 (patch)
tree74e8807bc0993d480ed38278b4f41cfde83da641 /tests-clar/diff
parent1cd9dc29b7105cb33959d15ab670a085f5a1445b (diff)
Add git_diff_patch_size() API
This adds a new API to get the size in bytes of the diffs in a git_diff_patch object.
Diffstat (limited to 'tests-clar/diff')
-rw-r--r--tests-clar/diff/patch.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c
index 3f14a0de7..51baadf2e 100644
--- a/tests-clar/diff/patch.c
+++ b/tests-clar/diff/patch.c
@@ -128,6 +128,9 @@ void test_diff_patch__to_string(void)
cl_assert_equal_s(expected, text);
+ cl_assert_equal_sz(31, git_diff_patch_size(patch, 0));
+ cl_assert_equal_sz(31, git_diff_patch_size(patch, 1));
+
git__free(text);
git_diff_patch_free(patch);
git_diff_list_free(diff);
@@ -409,6 +412,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
static void check_single_patch_stats(
git_repository *repo, size_t hunks,
size_t adds, size_t dels, size_t ctxt,
+ size_t size_with_context, size_t size_without_context,
const char *expected)
{
git_diff_list *diff;
@@ -439,6 +443,13 @@ static void check_single_patch_stats(
git__free(text);
}
+ if (size_with_context)
+ cl_assert_equal_sz(
+ size_with_context, git_diff_patch_size(patch, 1));
+ if (size_without_context)
+ cl_assert_equal_sz(
+ size_without_context, git_diff_patch_size(patch, 0));
+
/* walk lines in hunk with basic sanity checks */
for (; hunks > 0; --hunks) {
size_t i, max_i;
@@ -495,14 +506,14 @@ void test_diff_patch__line_counts_with_eofnl(void)
git_buf_consume(&content, end);
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
- check_single_patch_stats(g_repo, 1, 0, 1, 3, NULL);
+ check_single_patch_stats(g_repo, 1, 0, 1, 3, 0, 0, NULL);
/* remove trailing whitespace */
git_buf_rtrim(&content);
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
- check_single_patch_stats(g_repo, 2, 1, 2, 6, NULL);
+ check_single_patch_stats(g_repo, 2, 1, 2, 6, 0, 0, NULL);
/* add trailing whitespace */
@@ -514,7 +525,7 @@ void test_diff_patch__line_counts_with_eofnl(void)
cl_git_pass(git_buf_putc(&content, '\n'));
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
- check_single_patch_stats(g_repo, 1, 1, 1, 3, NULL);
+ check_single_patch_stats(g_repo, 1, 1, 1, 3, 0, 0, NULL);
/* no trailing whitespace as context line */
@@ -537,7 +548,7 @@ void test_diff_patch__line_counts_with_eofnl(void)
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
check_single_patch_stats(
- g_repo, 1, 1, 1, 6,
+ g_repo, 1, 1, 1, 6, 349, 115,
/* below is pasted output of 'git diff' with fn context removed */
"diff --git a/songof7cities.txt b/songof7cities.txt\n"
"index 378a7d9..3d0154e 100644\n"