|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | #include "clar_libgit2.h" |
| 9 | + |
| 10 | +#include "git2/sys/repository.h" |
9 | 11 | #include "attr.h" |
10 | 12 |
|
11 | 13 | static git_repository *g_repo = NULL; |
@@ -122,3 +124,56 @@ void test_attr_macro__changing_macro_in_root_wd_updates_attributes(void) |
122 | 124 | cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "key")); |
123 | 125 | cl_assert_equal_s(value, "second"); |
124 | 126 | } |
| 127 | + |
| 128 | +void test_attr_macro__adding_macro_succeeds(void) |
| 129 | +{ |
| 130 | + const char *value; |
| 131 | + |
| 132 | + g_repo = cl_git_sandbox_init("empty_standard_repo"); |
| 133 | + cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value")); |
| 134 | + cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro\n"); |
| 135 | + |
| 136 | + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key")); |
| 137 | + cl_assert_equal_s(value, "value"); |
| 138 | +} |
| 139 | + |
| 140 | +void test_attr_macro__adding_boolean_macros_succeeds(void) |
| 141 | +{ |
| 142 | + const char *value; |
| 143 | + |
| 144 | + g_repo = cl_git_sandbox_init("empty_standard_repo"); |
| 145 | + cl_git_pass(git_attr_add_macro(g_repo, "macro-pos", "positive")); |
| 146 | + cl_git_pass(git_attr_add_macro(g_repo, "macro-neg", "-negative")); |
| 147 | + cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro-pos macro-neg\n"); |
| 148 | + |
| 149 | + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "positive")); |
| 150 | + cl_assert(GIT_ATTR_IS_TRUE(value)); |
| 151 | + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "negative")); |
| 152 | + cl_assert(GIT_ATTR_IS_FALSE(value)); |
| 153 | +} |
| 154 | + |
| 155 | +void test_attr_macro__redefining_macro_succeeds(void) |
| 156 | +{ |
| 157 | + const char *value; |
| 158 | + |
| 159 | + g_repo = cl_git_sandbox_init("empty_standard_repo"); |
| 160 | + cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value1")); |
| 161 | + cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value2")); |
| 162 | + cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro"); |
| 163 | + |
| 164 | + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key")); |
| 165 | + cl_assert_equal_s(value, "value2"); |
| 166 | +} |
| 167 | + |
| 168 | +void test_attr_macro__recursive_macro_resolves(void) |
| 169 | +{ |
| 170 | + const char *value; |
| 171 | + |
| 172 | + g_repo = cl_git_sandbox_init("empty_standard_repo"); |
| 173 | + cl_git_pass(git_attr_add_macro(g_repo, "expandme", "key=value")); |
| 174 | + cl_git_pass(git_attr_add_macro(g_repo, "macro", "expandme")); |
| 175 | + cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro"); |
| 176 | + |
| 177 | + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key")); |
| 178 | + cl_assert_equal_s(value, "value"); |
| 179 | +} |
0 commit comments