summaryrefslogtreecommitdiff
path: root/tests/mailmap
diff options
context:
space:
mode:
authorNika Layzell <nika@thelayzells.com>2018-03-27 22:48:03 -0400
committerNika Layzell <nika@thelayzells.com>2018-06-14 22:43:28 -0700
commit18ff9babd7476097a67e122b9126c878f98ff47f (patch)
treeb415caa793dfd36c74b55738d2a1525019e49799 /tests/mailmap
parent57cfeab9fe480591e3f56d61ccfbb68f9b500156 (diff)
downloadlibgit2-18ff9babd7476097a67e122b9126c878f98ff47f.tar.gz
mailmap: API and style cleanup
Diffstat (limited to 'tests/mailmap')
-rw-r--r--tests/mailmap/basic.c71
-rw-r--r--tests/mailmap/parsing.c30
2 files changed, 68 insertions, 33 deletions
diff --git a/tests/mailmap/basic.c b/tests/mailmap/basic.c
index 508598440..23f447f53 100644
--- a/tests/mailmap/basic.c
+++ b/tests/mailmap/basic.c
@@ -13,43 +13,59 @@ const char TEST_MAILMAP[] =
"<email@foo.com> <otheremail@foo.com>\n"
"<email@foo.com> Other Name <yetanotheremail@foo.com>\n";
+struct {
+ const char *real_name;
+ const char *real_email;
+ const char *replace_name;
+ const char *replace_email;
+} expected[] = {
+ { "Foo bar", "foo@bar.com", NULL, "foo@baz.com" },
+ { "Foo bar", "foo@bar.com", NULL, "foo@bal.com" },
+ { NULL, "email@foo.com", NULL, "otheremail@foo.com" },
+ { NULL, "email@foo.com", "Other Name", "yetanotheremail@foo.com" }
+};
+
void test_mailmap_basic__initialize(void)
{
git_buf buf = GIT_BUF_INIT;
- git_buf_attach_notowned(&buf, TEST_MAILMAP, sizeof(TEST_MAILMAP) - 1);
+ git_buf_attach_notowned(&buf, TEST_MAILMAP, strlen(TEST_MAILMAP));
cl_git_pass(git_mailmap_from_buffer(&mailmap, &buf));
}
void test_mailmap_basic__cleanup(void)
{
- if (mailmap) {
- git_mailmap_free(mailmap);
- mailmap = NULL;
- }
+ git_mailmap_free(mailmap);
+ mailmap = NULL;
}
void test_mailmap_basic__entry(void)
{
const git_mailmap_entry *entry;
- cl_assert(git_mailmap_entry_count(mailmap) == 4);
+ cl_assert_equal_sz(ARRAY_SIZE(expected), git_mailmap_entry_count(mailmap));
- entry = git_mailmap_entry_byindex(mailmap, 0);
- cl_assert(entry);
- cl_assert(!entry->replace_name);
- cl_assert(!git__strcmp(entry->replace_email, "foo@baz.com"));
+ for (size_t i = 0; i < ARRAY_SIZE(expected); ++i) {
+ entry = git_mailmap_entry_byindex(mailmap, i);
+ cl_assert(entry);
+ cl_assert_equal_s(entry->real_name, expected[i].real_name);
+ cl_assert_equal_s(entry->real_email, expected[i].real_email);
+ cl_assert_equal_s(entry->replace_name, expected[i].replace_name);
+ cl_assert_equal_s(entry->replace_email, expected[i].replace_email);
+ }
+}
- entry = git_mailmap_entry_byindex(mailmap, 10000);
+void test_mailmap_basic__entry_large_index(void)
+{
+ const git_mailmap_entry *entry =
+ git_mailmap_entry_byindex(mailmap, 10000);
cl_assert(!entry);
}
void test_mailmap_basic__lookup_not_found(void)
{
const git_mailmap_entry *entry = git_mailmap_entry_lookup(
- mailmap,
- "Whoever",
- "doesnotexist@fo.com");
+ mailmap, "Whoever", "doesnotexist@fo.com");
cl_assert(!entry);
}
@@ -58,31 +74,32 @@ void test_mailmap_basic__lookup(void)
const git_mailmap_entry *entry = git_mailmap_entry_lookup(
mailmap, "Typoed the name once", "foo@baz.com");
cl_assert(entry);
- cl_assert(!git__strcmp(entry->real_name, "Foo bar"));
+ cl_assert_equal_s(entry->real_name, "Foo bar");
}
void test_mailmap_basic__empty_email_query(void)
{
const char *name;
const char *email;
- git_mailmap_resolve(
- &name, &email, mailmap, "Author name", "otheremail@foo.com");
- cl_assert(!git__strcmp(name, "Author name"));
- cl_assert(!git__strcmp(email, "email@foo.com"));
+ cl_git_pass(git_mailmap_resolve(
+ &name, &email, mailmap, "Author name", "otheremail@foo.com"));
+ cl_assert_equal_s(name, "Author name");
+ cl_assert_equal_s(email, "email@foo.com");
}
void test_mailmap_basic__name_matching(void)
{
const char *name;
const char *email;
- git_mailmap_resolve(
- &name, &email, mailmap, "Other Name", "yetanotheremail@foo.com");
- cl_assert(!git__strcmp(name, "Other Name"));
- cl_assert(!git__strcmp(email, "email@foo.com"));
+ cl_git_pass(git_mailmap_resolve(
+ &name, &email, mailmap, "Other Name", "yetanotheremail@foo.com"));
+
+ cl_assert_equal_s(name, "Other Name");
+ cl_assert_equal_s(email, "email@foo.com");
- git_mailmap_resolve(
+ cl_git_pass(git_mailmap_resolve(
&name, &email, mailmap,
- "Other Name That Doesn't Match", "yetanotheremail@foo.com");
- cl_assert(!git__strcmp(name, "Other Name That Doesn't Match"));
- cl_assert(!git__strcmp(email, "yetanotheremail@foo.com"));
+ "Other Name That Doesn't Match", "yetanotheremail@foo.com"));
+ cl_assert_equal_s(name, "Other Name That Doesn't Match");
+ cl_assert_equal_s(email, "yetanotheremail@foo.com");
}
diff --git a/tests/mailmap/parsing.c b/tests/mailmap/parsing.c
index fecb882cd..a40d93b47 100644
--- a/tests/mailmap/parsing.c
+++ b/tests/mailmap/parsing.c
@@ -44,12 +44,9 @@ static void check_mailmap_resolve(
/* Check that the resolver behaves correctly */
for (idx = 0; idx < resolved_size; ++idx) {
- git_mailmap_resolve(
- &resolved_name,
- &resolved_email,
- mailmap,
- resolved[idx].replace_name,
- resolved[idx].replace_email);
+ cl_git_pass(git_mailmap_resolve(
+ &resolved_name, &resolved_email, mailmap,
+ resolved[idx].replace_name, resolved[idx].replace_email));
cl_assert_equal_s(resolved_name, resolved[idx].real_name);
cl_assert_equal_s(resolved_email, resolved[idx].real_email);
}
@@ -70,6 +67,27 @@ void test_mailmap_parsing__string(void)
g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
}
+void test_mailmap_parsing__windows_string(void)
+{
+ git_buf unixbuf = GIT_BUF_INIT;
+ git_buf winbuf = GIT_BUF_INIT;
+
+ /* Parse with windows-style line endings */
+ git_buf_attach_notowned(&unixbuf, string_mailmap, strlen(string_mailmap));
+ git_buf_text_lf_to_crlf(&winbuf, &unixbuf);
+
+ cl_git_pass(git_mailmap_from_buffer(&g_mailmap, &winbuf));
+ git_buf_free(winbuf);
+
+ /* We should have parsed all of the entries */
+ check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
+
+ /* Check that resolving the entries works */
+ check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
+ check_mailmap_resolve(
+ g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
+}
+
void test_mailmap_parsing__fromrepo(void)
{
g_repo = cl_git_sandbox_init("mailmap");