diff options
author | Ben Straub <bs@github.com> | 2013-08-08 19:54:38 +0400 |
---|---|---|
committer | Ben Straub <bs@github.com> | 2013-08-08 19:54:38 +0400 |
commit | 5e96f31638fe71a0c76805b1352f437881791d98 (patch) | |
tree | 45c14d45f24bedd86b494ca76f1e4a26909de8cd /tests-clar/diff | |
parent | bf145a6a2f08add441f55387e5ae7daef58187ae (diff) | |
parent | eb1c1707ab6a399734d9083152c05516af052412 (diff) |
Merge pull request #1738 from libgit2/diff-patch-content-size
Add API for getting at git_diff_patch->content_size
Diffstat (limited to 'tests-clar/diff')
-rw-r--r-- | tests-clar/diff/patch.c | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c index 3f14a0de7..6a33fa990 100644 --- a/tests-clar/diff/patch.c +++ b/tests-clar/diff/patch.c @@ -128,6 +128,11 @@ void test_diff_patch__to_string(void) cl_assert_equal_s(expected, text); + cl_assert_equal_sz(31, git_diff_patch_size(patch, 0, 0, 0)); + cl_assert_equal_sz(31, git_diff_patch_size(patch, 1, 0, 0)); + cl_assert_equal_sz(31 + 16, git_diff_patch_size(patch, 1, 1, 0)); + cl_assert_equal_sz(strlen(expected), git_diff_patch_size(patch, 1, 1, 1)); + git__free(text); git_diff_patch_free(patch); git_diff_list_free(diff); @@ -408,7 +413,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 adds, size_t dels, size_t ctxt, size_t *sizes, const char *expected) { git_diff_list *diff; @@ -437,6 +442,18 @@ static void check_single_patch_stats( cl_git_pass(git_diff_patch_to_str(&text, patch)); cl_assert_equal_s(expected, text); git__free(text); + + cl_assert_equal_sz( + strlen(expected), git_diff_patch_size(patch, 1, 1, 1)); + } + + if (sizes) { + if (sizes[0]) + cl_assert_equal_sz(sizes[0], git_diff_patch_size(patch, 0, 0, 0)); + if (sizes[1]) + cl_assert_equal_sz(sizes[1], git_diff_patch_size(patch, 1, 0, 0)); + if (sizes[2]) + cl_assert_equal_sz(sizes[2], git_diff_patch_size(patch, 1, 1, 0)); } /* walk lines in hunk with basic sanity checks */ @@ -481,6 +498,23 @@ void test_diff_patch__line_counts_with_eofnl(void) git_buf content = GIT_BUF_INIT; const char *end; git_index *index; + const char *expected = + /* 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" + "--- a/songof7cities.txt\n" + "+++ b/songof7cities.txt\n" + "@@ -42,7 +42,7 @@ With peoples undefeated of the dark, enduring blood.\n" + " \n" + " To the sound of trumpets shall their seed restore my Cities\n" + " Wealthy and well-weaponed, that once more may I behold\n" + "-All the world go softly when it walks before my Cities,\n" + "+#All the world go softly when it walks before my Cities,\n" + " And the horses and the chariots fleeing from them as of old!\n" + " \n" + " -- Rudyard Kipling\n" + "\\ No newline at end of file\n"; + size_t expected_sizes[3] = { 115, 119 + 115 + 114, 119 + 115 + 114 + 71 }; g_repo = cl_git_sandbox_init("renames"); @@ -495,14 +529,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, NULL, 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, NULL, NULL); /* add trailing whitespace */ @@ -514,7 +548,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, NULL, NULL); /* no trailing whitespace as context line */ @@ -537,22 +571,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, - /* 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" - "--- a/songof7cities.txt\n" - "+++ b/songof7cities.txt\n" - "@@ -42,7 +42,7 @@ With peoples undefeated of the dark, enduring blood.\n" - " \n" - " To the sound of trumpets shall their seed restore my Cities\n" - " Wealthy and well-weaponed, that once more may I behold\n" - "-All the world go softly when it walks before my Cities,\n" - "+#All the world go softly when it walks before my Cities,\n" - " And the horses and the chariots fleeing from them as of old!\n" - " \n" - " -- Rudyard Kipling\n" - "\\ No newline at end of file\n"); + g_repo, 1, 1, 1, 6, expected_sizes, expected); git_buf_free(&content); git_config_free(cfg); |