diff options
author | Russell Belfer <rb@github.com> | 2013-05-07 15:36:42 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-05-07 15:36:42 +0400 |
commit | fd96f98e142cdb129f447ace189b2086951be313 (patch) | |
tree | 9fed06a957fca4751bad3bd1682df64d2bc923b6 /tests-clar | |
parent | e35e2684f693f28afb7a8f28028b4cb8bdd19f49 (diff) |
More tests for files with no newline at end
Diffstat (limited to 'tests-clar')
-rw-r--r-- | tests-clar/diff/patch.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c index c9a13f7fb..6181ffbaf 100644 --- a/tests-clar/diff/patch.c +++ b/tests-clar/diff/patch.c @@ -323,7 +323,9 @@ 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) + git_repository *repo, size_t hunks, + size_t adds, size_t dels, size_t ctxt, + const char *expected) { git_diff_list *diff; git_diff_patch *patch; @@ -346,6 +348,13 @@ static void check_single_patch_stats( cl_assert_equal_sz(adds, actual_adds); cl_assert_equal_sz(dels, actual_dels); + if (expected != NULL) { + char *text; + cl_git_pass(git_diff_patch_to_str(&text, patch)); + cl_assert_equal_s(expected, text); + git__free(text); + } + git_diff_patch_free(patch); git_diff_list_free(diff); } @@ -370,14 +379,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); + check_single_patch_stats(g_repo, 1, 0, 1, 3, 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); + check_single_patch_stats(g_repo, 2, 1, 2, 6, NULL); /* add trailing whitespace */ @@ -389,7 +398,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); + check_single_patch_stats(g_repo, 1, 1, 1, 3, NULL); /* no trailing whitespace as context line */ @@ -411,7 +420,23 @@ 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); + 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 @@\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"); git_buf_free(&content); git_config_free(cfg); |