Skip to content

Commit b88cbf8

Browse files
emiliomystor
authored andcommitted
mailmap: Add some super-basic tests
1 parent 7bafd17 commit b88cbf8

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

tests/mailmap/basic.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include "clar.h"
2+
#include "clar_libgit2.h"
3+
4+
#include "common.h"
5+
#include "git2/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+
void test_mailmap_basic__initialize(void)
17+
{
18+
cl_git_pass(git_mailmap_parse(&mailmap, TEST_MAILMAP, sizeof(TEST_MAILMAP)));
19+
}
20+
21+
void test_mailmap_basic__cleanup(void)
22+
{
23+
if (mailmap) {
24+
git_mailmap_free(mailmap);
25+
mailmap = NULL;
26+
}
27+
}
28+
29+
void test_mailmap_basic__entry(void)
30+
{
31+
git_mailmap_entry* entry;
32+
33+
cl_assert(git_mailmap_entry_count(mailmap) == 4);
34+
35+
entry = git_mailmap_entry_byindex(mailmap, 0);
36+
cl_assert(entry);
37+
cl_assert(!entry->replace_name);
38+
cl_assert(!git__strcmp(entry->replace_email, "foo@baz.com"));
39+
40+
entry = git_mailmap_entry_byindex(mailmap, 10000);
41+
cl_assert(!entry);
42+
}
43+
44+
void test_mailmap_basic__lookup_not_found(void)
45+
{
46+
git_mailmap_entry* entry = git_mailmap_entry_lookup(
47+
mailmap,
48+
"Whoever",
49+
"doesnotexist@fo.com");
50+
cl_assert(!entry);
51+
}
52+
53+
void test_mailmap_basic__lookup(void)
54+
{
55+
git_mailmap_entry* entry = git_mailmap_entry_lookup(
56+
mailmap,
57+
"Typoed the name once",
58+
"foo@baz.com");
59+
cl_assert(entry);
60+
cl_assert(!git__strcmp(entry->real_name, "Foo bar"));
61+
}
62+
63+
void test_mailmap_basic__empty_email_query(void)
64+
{
65+
const char* name;
66+
const char* email;
67+
git_mailmap_resolve(
68+
&name,
69+
&email,
70+
mailmap,
71+
"Author name",
72+
"otheremail@foo.com");
73+
cl_assert(!git__strcmp(name, "Author name"));
74+
cl_assert(!git__strcmp(email, "email@foo.com"));
75+
}
76+
77+
void test_mailmap_basic__name_matching(void)
78+
{
79+
const char* name;
80+
const char* email;
81+
git_mailmap_resolve(
82+
&name,
83+
&email,
84+
mailmap,
85+
"Other Name",
86+
"yetanotheremail@foo.com");
87+
cl_assert(!git__strcmp(name, "Other Name"));
88+
cl_assert(!git__strcmp(email, "email@foo.com"));
89+
90+
git_mailmap_resolve(
91+
&name,
92+
&email,
93+
mailmap,
94+
"Other Name That Doesn't Match",
95+
"yetanotheremail@foo.com");
96+
cl_assert(!git__strcmp(name, "Other Name That Doesn't Match"));
97+
cl_assert(!git__strcmp(email, "yetanotheremail@foo.com"));
98+
}

0 commit comments

Comments
 (0)