Tag
Hash :
307c4a2b
Author :
Date :
2015-10-21T11:58:44
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#include "clar_libgit2.h"
static int try_build_signature(const char *name, const char *email, git_time_t time, int offset)
{
git_signature *sign;
int error = 0;
if ((error = git_signature_new(&sign, name, email, time, offset)) < 0)
return error;
git_signature_free((git_signature *)sign);
return error;
}
static void assert_name_and_email(
const char *expected_name,
const char *expected_email,
const char *name,
const char *email)
{
git_signature *sign;
cl_git_pass(git_signature_new(&sign, name, email, 1234567890, 60));
cl_assert_equal_s(expected_name, sign->name);
cl_assert_equal_s(expected_email, sign->email);
git_signature_free(sign);
}
void test_commit_signature__leading_and_trailing_spaces_are_trimmed(void)
{
assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", " nulltoken ", " emeric.fermas@gmail.com ");
assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", " nulltoken ", " emeric.fermas@gmail.com \n");
assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", " \t nulltoken \n", " \n emeric.fermas@gmail.com \n");
}
void test_commit_signature__leading_and_trailing_crud_is_trimmed(void)
{
assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", "\"nulltoken\"", "\"emeric.fermas@gmail.com\"");
assert_name_and_email("nulltoken w", "emeric.fermas@gmail.com", "nulltoken w.", "emeric.fermas@gmail.com");
assert_name_and_email("nulltoken \xe2\x98\xba", "emeric.fermas@gmail.com", "nulltoken \xe2\x98\xba", "emeric.fermas@gmail.com");
}
void test_commit_signature__angle_brackets_in_names_are_not_supported(void)
{
cl_git_fail(try_build_signature("<Phil Haack", "phil@haack", 1234567890, 60));
cl_git_fail(try_build_signature("Phil>Haack", "phil@haack", 1234567890, 60));
cl_git_fail(try_build_signature("<Phil Haack>", "phil@haack", 1234567890, 60));
}
void test_commit_signature__angle_brackets_in_email_are_not_supported(void)
{
cl_git_fail(try_build_signature("Phil Haack", ">phil@haack", 1234567890, 60));
cl_git_fail(try_build_signature("Phil Haack", "phil@>haack", 1234567890, 60));
cl_git_fail(try_build_signature("Phil Haack", "<phil@haack>", 1234567890, 60));
}
void test_commit_signature__create_empties(void)
{
// can not create a signature with empty name or email
cl_git_pass(try_build_signature("nulltoken", "emeric.fermas@gmail.com", 1234567890, 60));
cl_git_fail(try_build_signature("", "emeric.fermas@gmail.com", 1234567890, 60));
cl_git_fail(try_build_signature(" ", "emeric.fermas@gmail.com", 1234567890, 60));
cl_git_fail(try_build_signature("nulltoken", "", 1234567890, 60));
cl_git_fail(try_build_signature("nulltoken", " ", 1234567890, 60));
}
void test_commit_signature__create_one_char(void)
{
// creating a one character signature
assert_name_and_email("x", "foo@bar.baz", "x", "foo@bar.baz");
}
void test_commit_signature__create_two_char(void)
{
// creating a two character signature
assert_name_and_email("xx", "foo@bar.baz", "xx", "foo@bar.baz");
}
void test_commit_signature__create_zero_char(void)
{
// creating a zero character signature
git_signature *sign;
cl_git_fail(git_signature_new(&sign, "", "x@y.z", 1234567890, 60));
cl_assert(sign == NULL);
}