]>
git.proxmox.com Git - libgit2.git/blob - tests/mailmap/basic.c
2 #include "clar_libgit2.h"
7 static git_mailmap
*mailmap
= NULL
;
9 const char TEST_MAILMAP
[] =
10 "Foo bar <foo@bar.com> <foo@baz.com> \n"
11 "Blatantly invalid line\n"
12 "Foo bar <foo@bar.com> <foo@bal.com>\n"
13 "<email@foo.com> <otheremail@foo.com>\n"
14 "<email@foo.com> Other Name <yetanotheremail@foo.com>\n";
17 const char *real_name
;
18 const char *real_email
;
19 const char *replace_name
;
20 const char *replace_email
;
22 { "Foo bar", "foo@bar.com", NULL
, "foo@baz.com" },
23 { "Foo bar", "foo@bar.com", NULL
, "foo@bal.com" },
24 { NULL
, "email@foo.com", NULL
, "otheremail@foo.com" },
25 { NULL
, "email@foo.com", "Other Name", "yetanotheremail@foo.com" }
28 void test_mailmap_basic__initialize(void)
30 cl_git_pass(git_mailmap_from_buffer(
31 &mailmap
, TEST_MAILMAP
, strlen(TEST_MAILMAP
)));
34 void test_mailmap_basic__cleanup(void)
36 git_mailmap_free(mailmap
);
40 void test_mailmap_basic__entry(void)
43 const git_mailmap_entry
*entry
;
45 /* Check that we have the expected # of entries */
46 cl_assert_equal_sz(ARRAY_SIZE(expected
), git_vector_length(&mailmap
->entries
));
48 for (idx
= 0; idx
< ARRAY_SIZE(expected
); ++idx
) {
49 /* Try to look up each entry and make sure they match */
50 entry
= git_mailmap_entry_lookup(
51 mailmap
, expected
[idx
].replace_name
, expected
[idx
].replace_email
);
54 cl_assert_equal_s(entry
->real_name
, expected
[idx
].real_name
);
55 cl_assert_equal_s(entry
->real_email
, expected
[idx
].real_email
);
56 cl_assert_equal_s(entry
->replace_name
, expected
[idx
].replace_name
);
57 cl_assert_equal_s(entry
->replace_email
, expected
[idx
].replace_email
);
61 void test_mailmap_basic__lookup_not_found(void)
63 const git_mailmap_entry
*entry
= git_mailmap_entry_lookup(
64 mailmap
, "Whoever", "doesnotexist@fo.com");
68 void test_mailmap_basic__lookup(void)
70 const git_mailmap_entry
*entry
= git_mailmap_entry_lookup(
71 mailmap
, "Typoed the name once", "foo@baz.com");
73 cl_assert_equal_s(entry
->real_name
, "Foo bar");
76 void test_mailmap_basic__empty_email_query(void)
80 cl_git_pass(git_mailmap_resolve(
81 &name
, &email
, mailmap
, "Author name", "otheremail@foo.com"));
82 cl_assert_equal_s(name
, "Author name");
83 cl_assert_equal_s(email
, "email@foo.com");
86 void test_mailmap_basic__name_matching(void)
90 cl_git_pass(git_mailmap_resolve(
91 &name
, &email
, mailmap
, "Other Name", "yetanotheremail@foo.com"));
93 cl_assert_equal_s(name
, "Other Name");
94 cl_assert_equal_s(email
, "email@foo.com");
96 cl_git_pass(git_mailmap_resolve(
97 &name
, &email
, mailmap
,
98 "Other Name That Doesn't Match", "yetanotheremail@foo.com"));
99 cl_assert_equal_s(name
, "Other Name That Doesn't Match");
100 cl_assert_equal_s(email
, "yetanotheremail@foo.com");