* mu-str: add mu_str_guess_first_name, mu_str_guess_last_name and

mu_str_guess_nick, + unit tests

  these function do a simple guess for the first/lastname and nick, so we can
prefill	the results of 'mu cfind' with some first guesses.
This commit is contained in:
Dirk-Jan C. Binnema
2011-03-06 12:14:26 +02:00
parent 17f2e3bdf9
commit 9a600e71c9
3 changed files with 216 additions and 0 deletions

View File

@ -251,6 +251,82 @@ test_mu_str_date_parse_hdwmy (void)
}
static void
test_mu_str_guess_first_name (void)
{
int i;
struct {
char *src, *exp;
} tests[] = {
{ "Richard M. Stallman", "Richard M." },
{ "John Rambo", "John" },
{ "Ivanhoe", "Ivanhoe" },
{ "", "" }
};
for (i = 0; i != G_N_ELEMENTS(tests); ++i) {
gchar *s;
s = mu_str_guess_first_name (tests[i].src);
g_assert_cmpstr (s, ==, tests[i].exp);
g_free (s);
}
}
static void
test_mu_str_guess_last_name (void)
{
int i;
struct {
char *src, *exp;
} tests[] = {
{ "Richard M. Stallman", "Stallman" },
{ "John Rambo", "Rambo" },
{ "Ivanhoe", "" },
{ "", "" }
};
for (i = 0; i != G_N_ELEMENTS(tests); ++i) {
gchar *s;
s = mu_str_guess_last_name (tests[i].src);
g_assert_cmpstr (s, ==, tests[i].exp);
g_free (s);
}
}
static void
test_mu_str_guess_nick (void)
{
int i;
struct {
char *src, *exp;
} tests[] = {
{ "Richard M. Stallman", "RichardMS" },
{ "John Rambo", "JohnR" },
{ "Ivanhoe", "Ivanhoe" },
{ "", "" }
};
for (i = 0; i != G_N_ELEMENTS(tests); ++i) {
gchar *s;
s = mu_str_guess_nick (tests[i].src);
g_assert_cmpstr (s, ==, tests[i].exp);
g_free (s);
}
}
int
main (int argc, char *argv[])
@ -289,6 +365,12 @@ main (int argc, char *argv[])
g_test_add_func ("/mu-str/mu-str_date_parse_hdwmy",
test_mu_str_date_parse_hdwmy);
g_test_add_func ("/mu-str/mu-str_guess_first_name",
test_mu_str_guess_first_name);
g_test_add_func ("/mu-str/mu-str_guess_last_name",
test_mu_str_guess_last_name);
g_test_add_func ("/mu-str/mu-str_guess_nick",
test_mu_str_guess_nick);
/* FIXME: add tests for mu_str_flags; but note the
* function simply calls mu_msg_field_str */