]> git.proxmox.com Git - libgit2.git/blob - tests/filter/ident.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / filter / ident.c
1 #include "clar_libgit2.h"
2 #include "git2/sys/filter.h"
3
4 static git_repository *g_repo = NULL;
5
6 void test_filter_ident__initialize(void)
7 {
8 g_repo = cl_git_sandbox_init("crlf");
9 }
10
11 void test_filter_ident__cleanup(void)
12 {
13 cl_git_sandbox_cleanup();
14 }
15
16 static void add_blob_and_filter(
17 const char *data,
18 git_filter_list *fl,
19 const char *expected)
20 {
21 git_oid id;
22 git_blob *blob;
23 git_buf out = { 0 };
24
25 cl_git_mkfile("crlf/identtest", data);
26 cl_git_pass(git_blob_create_from_workdir(&id, g_repo, "identtest"));
27 cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
28
29 cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
30
31 cl_assert_equal_s(expected, out.ptr);
32
33 git_blob_free(blob);
34 git_buf_dispose(&out);
35 }
36
37 void test_filter_ident__to_worktree(void)
38 {
39 git_filter_list *fl;
40 git_filter *ident;
41
42 cl_git_pass(git_filter_list_new(
43 &fl, g_repo, GIT_FILTER_TO_WORKTREE, 0));
44
45 ident = git_filter_lookup(GIT_FILTER_IDENT);
46 cl_assert(ident != NULL);
47
48 cl_git_pass(git_filter_list_push(fl, ident, NULL));
49
50 add_blob_and_filter(
51 "Hello\n$Id$\nFun stuff\n", fl,
52 "Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30 $\nFun stuff\n");
53 add_blob_and_filter(
54 "Hello\n$Id: Junky$\nFun stuff\n", fl,
55 "Hello\n$Id: 45cd107a7102911cb2a7df08404674327fa050b9 $\nFun stuff\n");
56 add_blob_and_filter(
57 "$Id$\nAt the start\n", fl,
58 "$Id: b13415c767abc196fb95bd17070e8c1113e32160 $\nAt the start\n");
59 add_blob_and_filter(
60 "At the end\n$Id$", fl,
61 "At the end\n$Id: 1344925c6bc65b34c5a7b50f86bf688e48e9a272 $");
62 add_blob_and_filter(
63 "$Id$", fl,
64 "$Id: b3f5ebfb5843bc43ceecff6d4f26bb37c615beb1 $");
65 add_blob_and_filter(
66 "$Id: Some sort of junk goes here$", fl,
67 "$Id: ab2dd3853c7c9a4bff55aca2bea077a73c32ac06 $");
68
69 add_blob_and_filter("$Id: ", fl, "$Id: ");
70 add_blob_and_filter("$Id", fl, "$Id");
71 add_blob_and_filter("$I", fl, "$I");
72 add_blob_and_filter("Id$", fl, "Id$");
73
74 git_filter_list_free(fl);
75 }
76
77 void test_filter_ident__to_odb(void)
78 {
79 git_filter_list *fl;
80 git_filter *ident;
81
82 cl_git_pass(git_filter_list_new(
83 &fl, g_repo, GIT_FILTER_TO_ODB, 0));
84
85 ident = git_filter_lookup(GIT_FILTER_IDENT);
86 cl_assert(ident != NULL);
87
88 cl_git_pass(git_filter_list_push(fl, ident, NULL));
89
90 add_blob_and_filter(
91 "Hello\n$Id$\nFun stuff\n",
92 fl, "Hello\n$Id$\nFun stuff\n");
93 add_blob_and_filter(
94 "Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30$\nFun stuff\n",
95 fl, "Hello\n$Id$\nFun stuff\n");
96 add_blob_and_filter(
97 "Hello\n$Id: Any junk you may have left here$\nFun stuff\n",
98 fl, "Hello\n$Id$\nFun stuff\n");
99 add_blob_and_filter(
100 "Hello\n$Id:$\nFun stuff\n",
101 fl, "Hello\n$Id$\nFun stuff\n");
102 add_blob_and_filter(
103 "Hello\n$Id:x$\nFun stuff\n",
104 fl, "Hello\n$Id$\nFun stuff\n");
105
106 add_blob_and_filter(
107 "$Id$\nAt the start\n", fl, "$Id$\nAt the start\n");
108 add_blob_and_filter(
109 "$Id: lots of random text that should be removed from here$\nAt the start\n", fl, "$Id$\nAt the start\n");
110 add_blob_and_filter(
111 "$Id: lots of random text that should not be removed without a terminator\nAt the start\n", fl, "$Id: lots of random text that should not be removed without a terminator\nAt the start\n");
112
113 add_blob_and_filter(
114 "At the end\n$Id$", fl, "At the end\n$Id$");
115 add_blob_and_filter(
116 "At the end\n$Id:$", fl, "At the end\n$Id$");
117 add_blob_and_filter(
118 "At the end\n$Id:asdfasdf$", fl, "At the end\n$Id$");
119 add_blob_and_filter(
120 "At the end\n$Id", fl, "At the end\n$Id");
121 add_blob_and_filter(
122 "At the end\n$IddI", fl, "At the end\n$IddI");
123
124 add_blob_and_filter("$Id$", fl, "$Id$");
125 add_blob_and_filter("$Id: any$", fl, "$Id$");
126 add_blob_and_filter("$Id: any long stuff goes here you see$", fl, "$Id$");
127 add_blob_and_filter("$Id: ", fl, "$Id: ");
128 add_blob_and_filter("$Id", fl, "$Id");
129 add_blob_and_filter("$I", fl, "$I");
130 add_blob_and_filter("Id$", fl, "Id$");
131
132 git_filter_list_free(fl);
133 }