]>
git.proxmox.com Git - libgit2.git/blob - tests/filter/blob.c
1 #include "clar_libgit2.h"
4 static git_repository
*g_repo
= NULL
;
6 void test_filter_blob__initialize(void)
8 g_repo
= cl_git_sandbox_init("crlf");
9 cl_git_mkfile("crlf/.gitattributes",
10 "*.txt text\n*.bin binary\n"
11 "*.crlf text eol=crlf\n"
13 "*.ident text ident\n"
14 "*.identcrlf ident text eol=crlf\n"
15 "*.identlf ident text eol=lf\n");
18 void test_filter_blob__cleanup(void)
20 cl_git_sandbox_cleanup();
23 void test_filter_blob__all_crlf(void)
28 cl_git_pass(git_revparse_single(
29 (git_object
**)&blob
, g_repo
, "a9a2e891")); /* all-crlf */
31 cl_assert_equal_s(ALL_CRLF_TEXT_RAW
, git_blob_rawcontent(blob
));
33 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", NULL
));
35 cl_assert_equal_s(ALL_CRLF_TEXT_RAW
, buf
.ptr
);
37 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", NULL
));
39 /* in this case, raw content has crlf in it already */
40 cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF
, buf
.ptr
);
42 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", NULL
));
44 /* we never convert CRLF -> LF on platforms that have LF */
45 cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF
, buf
.ptr
);
47 git_buf_dispose(&buf
);
51 void test_filter_blob__from_lf(void)
56 cl_git_pass(git_revparse_single(
57 (git_object
**)&blob
, g_repo
, "799770d")); /* all-lf */
59 cl_assert_equal_s(ALL_LF_TEXT_RAW
, git_blob_rawcontent(blob
));
61 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", NULL
));
63 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
65 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", NULL
));
67 /* in this case, raw content has crlf in it already */
68 cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF
, buf
.ptr
);
70 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", NULL
));
72 /* we never convert CRLF -> LF on platforms that have LF */
73 cl_assert_equal_s(ALL_LF_TEXT_AS_LF
, buf
.ptr
);
75 git_buf_dispose(&buf
);
79 void test_filter_blob__sanitizes(void)
84 cl_git_pass(git_revparse_single(
85 (git_object
**)&blob
, g_repo
, "e69de29")); /* zero-byte */
87 cl_assert_equal_i(0, git_blob_rawsize(blob
));
88 cl_assert_equal_s("", git_blob_rawcontent(blob
));
90 memset(&buf
, 0, sizeof(git_buf
));
91 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", NULL
));
92 cl_assert_equal_sz(0, buf
.size
);
93 cl_assert_equal_s("", buf
.ptr
);
94 git_buf_dispose(&buf
);
96 memset(&buf
, 0, sizeof(git_buf
));
97 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", NULL
));
98 cl_assert_equal_sz(0, buf
.size
);
99 cl_assert_equal_s("", buf
.ptr
);
100 git_buf_dispose(&buf
);
102 memset(&buf
, 0, sizeof(git_buf
));
103 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", NULL
));
104 cl_assert_equal_sz(0, buf
.size
);
105 cl_assert_equal_s("", buf
.ptr
);
106 git_buf_dispose(&buf
);
111 void test_filter_blob__ident(void)
117 cl_git_mkfile("crlf/test.ident", "Some text\n$Id$\nGoes there\n");
118 cl_git_pass(git_blob_create_from_workdir(&id
, g_repo
, "test.ident"));
119 cl_git_pass(git_blob_lookup(&blob
, g_repo
, &id
));
121 "Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob
));
124 cl_git_mkfile("crlf/test.ident", "Some text\n$Id: Any old just you want$\nGoes there\n");
125 cl_git_pass(git_blob_create_from_workdir(&id
, g_repo
, "test.ident"));
126 cl_git_pass(git_blob_lookup(&blob
, g_repo
, &id
));
128 "Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob
));
130 cl_git_pass(git_blob_filter(&buf
, blob
, "filter.bin", NULL
));
132 "Some text\n$Id$\nGoes there\n", buf
.ptr
);
134 cl_git_pass(git_blob_filter(&buf
, blob
, "filter.identcrlf", NULL
));
136 "Some text\r\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845 $\r\nGoes there\r\n", buf
.ptr
);
138 cl_git_pass(git_blob_filter(&buf
, blob
, "filter.identlf", NULL
));
140 "Some text\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845 $\nGoes there\n", buf
.ptr
);
142 git_buf_dispose(&buf
);