|
| 1 | +#include "clar_libgit2.h" |
| 2 | +#include "crlf.h" |
| 3 | + |
| 4 | +static git_repository *g_repo = NULL; |
| 5 | +static git_blob_filter_options filter_opts = GIT_BLOB_FILTER_OPTIONS_INIT; |
| 6 | + |
| 7 | +void test_filter_bare__initialize(void) |
| 8 | +{ |
| 9 | + cl_fixture_sandbox("crlf.git"); |
| 10 | + cl_git_pass(git_repository_open(&g_repo, "crlf.git")); |
| 11 | + |
| 12 | + filter_opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES; |
| 13 | + filter_opts.flags |= GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD; |
| 14 | +} |
| 15 | + |
| 16 | +void test_filter_bare__cleanup(void) |
| 17 | +{ |
| 18 | + git_repository_free(g_repo); |
| 19 | + cl_fixture_cleanup("crlf.git"); |
| 20 | +} |
| 21 | + |
| 22 | +void test_filter_bare__all_crlf(void) |
| 23 | +{ |
| 24 | + git_blob *blob; |
| 25 | + git_buf buf = { 0 }; |
| 26 | + |
| 27 | + cl_git_pass(git_revparse_single( |
| 28 | + (git_object **)&blob, g_repo, "a9a2e89")); /* all-crlf */ |
| 29 | + |
| 30 | + cl_assert_equal_s(ALL_CRLF_TEXT_RAW, git_blob_rawcontent(blob)); |
| 31 | + |
| 32 | + cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts)); |
| 33 | + |
| 34 | + cl_assert_equal_s(ALL_CRLF_TEXT_RAW, buf.ptr); |
| 35 | + |
| 36 | + cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts)); |
| 37 | + |
| 38 | + /* in this case, raw content has crlf in it already */ |
| 39 | + cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr); |
| 40 | + |
| 41 | + cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts)); |
| 42 | + |
| 43 | + /* we never convert CRLF -> LF on platforms that have LF */ |
| 44 | + cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr); |
| 45 | + |
| 46 | + cl_git_pass(git_blob_filter(&buf, blob, "file.txt", &filter_opts)); |
| 47 | + |
| 48 | + /* in this case, raw content has crlf in it already */ |
| 49 | + cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr); |
| 50 | + |
| 51 | + git_buf_dispose(&buf); |
| 52 | + git_blob_free(blob); |
| 53 | +} |
| 54 | + |
| 55 | +void test_filter_bare__from_lf(void) |
| 56 | +{ |
| 57 | + git_blob *blob; |
| 58 | + git_buf buf = { 0 }; |
| 59 | + |
| 60 | + cl_git_pass(git_revparse_single( |
| 61 | + (git_object **)&blob, g_repo, "799770d")); /* all-lf */ |
| 62 | + |
| 63 | + cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob)); |
| 64 | + |
| 65 | + cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts)); |
| 66 | + |
| 67 | + cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr); |
| 68 | + |
| 69 | + cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts)); |
| 70 | + |
| 71 | + /* in this case, raw content has crlf in it already */ |
| 72 | + cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF, buf.ptr); |
| 73 | + |
| 74 | + cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts)); |
| 75 | + |
| 76 | + /* we never convert CRLF -> LF on platforms that have LF */ |
| 77 | + cl_assert_equal_s(ALL_LF_TEXT_AS_LF, buf.ptr); |
| 78 | + |
| 79 | + git_buf_dispose(&buf); |
| 80 | + git_blob_free(blob); |
| 81 | +} |
| 82 | + |
| 83 | +void test_filter_bare__sanitizes(void) |
| 84 | +{ |
| 85 | + git_blob *blob; |
| 86 | + git_buf buf = GIT_BUF_INIT; |
| 87 | + |
| 88 | + cl_git_pass(git_revparse_single( |
| 89 | + (git_object **)&blob, g_repo, "e69de29")); /* zero-byte */ |
| 90 | + |
| 91 | + cl_assert_equal_i(0, git_blob_rawsize(blob)); |
| 92 | + cl_assert_equal_s("", git_blob_rawcontent(blob)); |
| 93 | + |
| 94 | + cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts)); |
| 95 | + cl_assert_equal_sz(0, buf.size); |
| 96 | + cl_assert_equal_s("", buf.ptr); |
| 97 | + git_buf_dispose(&buf); |
| 98 | + |
| 99 | + cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts)); |
| 100 | + cl_assert_equal_sz(0, buf.size); |
| 101 | + cl_assert_equal_s("", buf.ptr); |
| 102 | + git_buf_dispose(&buf); |
| 103 | + |
| 104 | + cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts)); |
| 105 | + cl_assert_equal_sz(0, buf.size); |
| 106 | + cl_assert_equal_s("", buf.ptr); |
| 107 | + git_buf_dispose(&buf); |
| 108 | + |
| 109 | + git_blob_free(blob); |
| 110 | +} |
| 111 | + |
0 commit comments