Added whole word matches for room mention

This commit is contained in:
James Booth
2016-04-07 01:01:27 +01:00
parent 6edf3b3f94
commit f243e333fc
14 changed files with 263 additions and 217 deletions

View File

@@ -631,113 +631,138 @@ void strip_quotes_strips_both(void **state)
free(result);
}
void prof_strstr_contains(void **state)
gboolean
_lists_equal(GSList *a, GSList *b)
{
assert_true(prof_strstr(NULL, "some string", FALSE, FALSE) == FALSE);
assert_true(prof_strstr("boothj5", NULL, FALSE, FALSE) == FALSE);
assert_true(prof_strstr(NULL, NULL, FALSE, FALSE) == FALSE);
if (g_slist_length(a) != g_slist_length(b)) {
return FALSE;
}
assert_true(prof_strstr("boothj5", "boothj5", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("boothj5", "boothj5 hello", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("boothj5", "hello boothj5", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("boothj5", "hello boothj5 there", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("boothj5", "helloboothj5test", FALSE, FALSE) == TRUE);
GSList *curra = a;
GSList *currb = b;
assert_true(prof_strstr("boothj5", "BoothJ5", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("boothj5", "BoothJ5 hello", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("boothj5", "hello BoothJ5", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("boothj5", "hello BoothJ5 there", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("boothj5", "helloBoothJ5test", FALSE, FALSE) == TRUE);
while (curra) {
int aval = GPOINTER_TO_INT(curra->data);
int bval = GPOINTER_TO_INT(currb->data);
assert_true(prof_strstr("BoothJ5", "boothj5", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("BoothJ5", "boothj5 hello", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("BoothJ5", "hello boothj5", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("BoothJ5", "hello boothj5 there", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("BoothJ5", "helloboothj5test", FALSE, FALSE) == TRUE);
if (aval != bval) {
return FALSE;
}
assert_true(prof_strstr("boothj5", "BoothJ5", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("boothj5", "BoothJ5 hello", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("boothj5", "hello BoothJ5", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("boothj5", "hello BoothJ5 there", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("boothj5", "helloBoothJ5test", TRUE, FALSE) == FALSE);
curra = g_list_next(curra);
currb = g_list_next(currb);
}
assert_true(prof_strstr("BoothJ5", "boothj5", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("BoothJ5", "boothj5 hello", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("BoothJ5", "hello boothj5", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("BoothJ5", "hello boothj5 there", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("BoothJ5", "helloboothj5test", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("boothj5", "boothj5", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "boothj5 hello", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "hello boothj5", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "hello boothj5 there", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "boothj5test", FALSE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "helloboothj5", FALSE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "helloboothj5test", FALSE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "BoothJ5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "BoothJ5 hello", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "hello BoothJ5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "hello BoothJ5 there", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "BoothJ5test", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "helloBoothJ5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "helloBoothJ5test", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("BoothJ5", "boothj5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("BoothJ5", "boothj5 hello", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("BoothJ5", "hello boothj5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("BoothJ5", "hello boothj5 there", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("BoothJ5", "boothj5test", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("BoothJ5", "helloboothj5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("BoothJ5", "helloboothj5test", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "boothj5:", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "boothj5,", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "boothj5-", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", ":boothj5", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", ",boothj5", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "-boothj5", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", ":boothj5:", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", ",boothj5,", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "-boothj5-", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "BoothJ5:", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "BoothJ5,", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "BoothJ5-", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", ":BoothJ5", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", ",BoothJ5", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "-BoothJ5", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", ":BoothJ5:", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", ",BoothJ5,", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "-BoothJ5-", FALSE, TRUE) == TRUE);
assert_true(prof_strstr("boothj5", "BoothJ5:", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "BoothJ5,", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "BoothJ5-", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", ":BoothJ5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", ",BoothJ5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "-BoothJ5", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", ":BoothJ5:", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", ",BoothJ5,", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("boothj5", "-BoothJ5-", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("K", "don't know", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("K", "don't know", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("K", "don't know", FALSE, TRUE) == FALSE);
assert_true(prof_strstr("K", "don't know", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("K", "don't Know", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("K", "don't Know", TRUE, FALSE) == TRUE);
assert_true(prof_strstr("K", "don't Know", FALSE, TRUE) == FALSE);
assert_true(prof_strstr("K", "don't Know", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("K", "backwards", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("K", "backwards", TRUE, FALSE) == FALSE);
assert_true(prof_strstr("K", "backwards", FALSE, TRUE) == FALSE);
assert_true(prof_strstr("K", "backwards", TRUE, TRUE) == FALSE);
assert_true(prof_strstr("K", "BACKWARDS", FALSE, FALSE) == TRUE);
assert_true(prof_strstr("K", "BACKWARDS", TRUE, FALSE) == TRUE);
assert_true(prof_strstr("K", "BACKWARDS", FALSE, TRUE) == FALSE);
assert_true(prof_strstr("K", "BACKWARDS", TRUE, TRUE) == FALSE);
return TRUE;
}
void prof_partial_occurrences_tests(void **state)
{
GSList *actual = NULL;
GSList *expected = NULL;
assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected));
g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences(NULL, "some string", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", NULL, 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "Boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("Boothj5", "boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5hello", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hello", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(5));
assert_true(_lists_equal(prof_occurrences("boothj5", "helloboothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "helloboothj5hello", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(6));
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 hello", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
expected = g_slist_append(expected, GINT_TO_POINTER(7));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
expected = g_slist_append(expected, GINT_TO_POINTER(12));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5helloboothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
expected = g_slist_append(expected, GINT_TO_POINTER(14));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hello boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(2));
expected = g_slist_append(expected, GINT_TO_POINTER(16));
expected = g_slist_append(expected, GINT_TO_POINTER(29));
assert_true(_lists_equal(prof_occurrences("boothj5", "hiboothj5 hello boothj5there boothj5s", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
}
void prof_whole_occurrences_tests(void **state)
{
GSList *actual = NULL;
GSList *expected = NULL;
assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected));
g_slist_free(actual); actual = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hi", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5: hi", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5, hi", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(6));
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 there", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyy @boothj5, there", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(6));
expected = g_slist_append(expected, GINT_TO_POINTER(26));
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 some more a boothj5 stuff", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 there ands #boothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyy @boothj5, there hows boothj5?", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(6));
assert_true(_lists_equal(prof_occurrences("p", "ppppp p", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
assert_true(_lists_equal(prof_occurrences("p", "p ppppp", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(4));
assert_true(_lists_equal(prof_occurrences("p", "ppp p ppp", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5hello", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "hey boothj5hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "hey @boothj5hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5 hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5, hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5boothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5fillboothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "dont know", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kick", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kick kick", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kick kickk", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kic", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "ick", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kk", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kkkkkkk", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
}

View File

@@ -64,4 +64,5 @@ void str_contains_str_whole(void **state);
void str_empty_not_contains_str(void **state);
void str_not_contains_str_empty(void **state);
void str_empty_not_contains_str_empty(void **state);
void prof_strstr_contains(void **state);
void prof_partial_occurrences_tests(void **state);
void prof_whole_occurrences_tests(void **state);

View File

@@ -193,7 +193,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char
const char * const affiliation, const char * const actor, const char * const reason) {}
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char * const presence) {}
void mucwin_history(ProfMucWin *mucwin, const char * const nick, GDateTime *timestamp, const char * const message) {}
void mucwin_message(ProfMucWin *mucwin, const char * const nick, const char * const message, gboolean mention, GList *triggers) {}
void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers) {}
void mucwin_subject(ProfMucWin *mucwin, const char * const nick, const char * const subject) {}
void mucwin_requires_config(ProfMucWin *mucwin) {}
void ui_room_destroy(const char * const roomjid) {}

View File

@@ -617,7 +617,8 @@ int main(int argc, char* argv[]) {
load_preferences,
close_preferences),
unit_test(prof_strstr_contains),
unit_test(prof_partial_occurrences_tests),
unit_test(prof_whole_occurrences_tests),
};
return run_tests(all_tests);