]> git.proxmox.com Git - libgit2.git/blob - tests/mailmap/basic.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / mailmap / basic.c
1 #include "clar.h"
2 #include "clar_libgit2.h"
3
4 #include "common.h"
5 #include "mailmap.h"
6
7 static git_mailmap *mailmap = NULL;
8
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";
15
16 struct {
17 const char *real_name;
18 const char *real_email;
19 const char *replace_name;
20 const char *replace_email;
21 } expected[] = {
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" }
26 };
27
28 void test_mailmap_basic__initialize(void)
29 {
30 cl_git_pass(git_mailmap_from_buffer(
31 &mailmap, TEST_MAILMAP, strlen(TEST_MAILMAP)));
32 }
33
34 void test_mailmap_basic__cleanup(void)
35 {
36 git_mailmap_free(mailmap);
37 mailmap = NULL;
38 }
39
40 void test_mailmap_basic__entry(void)
41 {
42 size_t idx;
43 const git_mailmap_entry *entry;
44
45 /* Check that we have the expected # of entries */
46 cl_assert_equal_sz(ARRAY_SIZE(expected), git_vector_length(&mailmap->entries));
47
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);
52
53 cl_assert(entry);
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);
58 }
59 }
60
61 void test_mailmap_basic__lookup_not_found(void)
62 {
63 const git_mailmap_entry *entry = git_mailmap_entry_lookup(
64 mailmap, "Whoever", "doesnotexist@fo.com");
65 cl_assert(!entry);
66 }
67
68 void test_mailmap_basic__lookup(void)
69 {
70 const git_mailmap_entry *entry = git_mailmap_entry_lookup(
71 mailmap, "Typoed the name once", "foo@baz.com");
72 cl_assert(entry);
73 cl_assert_equal_s(entry->real_name, "Foo bar");
74 }
75
76 void test_mailmap_basic__empty_email_query(void)
77 {
78 const char *name;
79 const char *email;
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");
84 }
85
86 void test_mailmap_basic__name_matching(void)
87 {
88 const char *name;
89 const char *email;
90 cl_git_pass(git_mailmap_resolve(
91 &name, &email, mailmap, "Other Name", "yetanotheremail@foo.com"));
92
93 cl_assert_equal_s(name, "Other Name");
94 cl_assert_equal_s(email, "email@foo.com");
95
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");
101 }