tests: attr: verify that in-memory macros are respected Add some tests to ensure that the `git_attr_add_macro` function works as expected.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/tests/attr/macro.c b/tests/attr/macro.c
index 79e8225..bdec901 100644
--- a/tests/attr/macro.c
+++ b/tests/attr/macro.c
@@ -6,6 +6,8 @@
*/
#include "clar_libgit2.h"
+
+#include "git2/sys/repository.h"
#include "attr.h"
static git_repository *g_repo = NULL;
@@ -122,3 +124,56 @@ void test_attr_macro__changing_macro_in_root_wd_updates_attributes(void)
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "key"));
cl_assert_equal_s(value, "second");
}
+
+void test_attr_macro__adding_macro_succeeds(void)
+{
+ const char *value;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value"));
+ cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro\n");
+
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key"));
+ cl_assert_equal_s(value, "value");
+}
+
+void test_attr_macro__adding_boolean_macros_succeeds(void)
+{
+ const char *value;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_pass(git_attr_add_macro(g_repo, "macro-pos", "positive"));
+ cl_git_pass(git_attr_add_macro(g_repo, "macro-neg", "-negative"));
+ cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro-pos macro-neg\n");
+
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "positive"));
+ cl_assert(GIT_ATTR_IS_TRUE(value));
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "negative"));
+ cl_assert(GIT_ATTR_IS_FALSE(value));
+}
+
+void test_attr_macro__redefining_macro_succeeds(void)
+{
+ const char *value;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value1"));
+ cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value2"));
+ cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro");
+
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key"));
+ cl_assert_equal_s(value, "value2");
+}
+
+void test_attr_macro__recursive_macro_resolves(void)
+{
+ const char *value;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_git_pass(git_attr_add_macro(g_repo, "expandme", "key=value"));
+ cl_git_pass(git_attr_add_macro(g_repo, "macro", "expandme"));
+ cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro");
+
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key"));
+ cl_assert_equal_s(value, "value");
+}