mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-18 16:16:21 +00:00
tests: Add test for get_mentions()
This commit is contained in:
@@ -864,6 +864,73 @@ prof_partial_occurrences_tests(void** state)
|
||||
expected = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
get_mentions_tests(void** state)
|
||||
{
|
||||
GSList* actual = NULL;
|
||||
GSList* expected = NULL;
|
||||
|
||||
// Basic match, case sensitive
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(6));
|
||||
actual = get_mentions(FALSE, TRUE, "hello boothj5", "boothj5");
|
||||
assert_true(_lists_equal(actual, expected));
|
||||
g_slist_free(actual); actual = NULL;
|
||||
g_slist_free(expected); expected = NULL;
|
||||
|
||||
// Case insensitive match
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(6));
|
||||
actual = get_mentions(FALSE, FALSE, "hello BOOTHJ5", "boothj5");
|
||||
assert_true(_lists_equal(actual, expected));
|
||||
g_slist_free(actual); actual = NULL;
|
||||
g_slist_free(expected); expected = NULL;
|
||||
|
||||
// Whole word match
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(0));
|
||||
actual = get_mentions(TRUE, TRUE, "boothj5 hello", "boothj5");
|
||||
assert_true(_lists_equal(actual, expected));
|
||||
g_slist_free(actual); actual = NULL;
|
||||
g_slist_free(expected); expected = NULL;
|
||||
|
||||
// Whole word no match (partial)
|
||||
actual = get_mentions(TRUE, TRUE, "boothj5hello", "boothj5");
|
||||
assert_true(_lists_equal(actual, expected)); // expected is NULL
|
||||
g_slist_free(actual); actual = NULL;
|
||||
|
||||
// Multiple matches
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(0));
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(14));
|
||||
actual = get_mentions(FALSE, TRUE, "boothj5 hello boothj5", "boothj5");
|
||||
assert_true(_lists_equal(actual, expected));
|
||||
g_slist_free(actual); actual = NULL;
|
||||
g_slist_free(expected); expected = NULL;
|
||||
|
||||
// Nick with punctuation (whole word)
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(0));
|
||||
actual = get_mentions(TRUE, TRUE, "boothj5: hi", "boothj5");
|
||||
assert_true(_lists_equal(actual, expected));
|
||||
g_slist_free(actual); actual = NULL;
|
||||
g_slist_free(expected); expected = NULL;
|
||||
|
||||
// Nick surrounded by punctuation
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(1));
|
||||
actual = get_mentions(TRUE, TRUE, "(boothj5)", "boothj5");
|
||||
assert_true(_lists_equal(actual, expected));
|
||||
g_slist_free(actual); actual = NULL;
|
||||
g_slist_free(expected); expected = NULL;
|
||||
|
||||
// Empty message
|
||||
actual = get_mentions(FALSE, TRUE, "", "boothj5");
|
||||
assert_true(_lists_equal(actual, expected)); // expected is NULL
|
||||
g_slist_free(actual); actual = NULL;
|
||||
|
||||
// UTF-8 characters
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(0));
|
||||
actual = get_mentions(TRUE, TRUE, "我能 hello", "我能");
|
||||
assert_true(_lists_equal(actual, expected));
|
||||
g_slist_free(actual); actual = NULL;
|
||||
g_slist_free(expected); expected = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
prof_whole_occurrences_tests(void** state)
|
||||
{
|
||||
|
||||
@@ -43,3 +43,4 @@ void test_strtoi_range_null_empty_input(void** state);
|
||||
void test_strtoi_range_null_err_msg(void** state);
|
||||
void test_string_matches_one_of_edge_cases(void** state);
|
||||
void test_valid_tls_policy_option(void** state);
|
||||
void get_mentions_tests(void** state);
|
||||
|
||||
@@ -634,6 +634,7 @@ main(int argc, char* argv[])
|
||||
cmocka_unit_test(prof_partial_occurrences_tests),
|
||||
cmocka_unit_test(prof_whole_occurrences_tests),
|
||||
cmocka_unit_test(prof_occurrences_of_large_message_tests),
|
||||
cmocka_unit_test(get_mentions_tests),
|
||||
|
||||
cmocka_unit_test_setup_teardown(returns_no_commands,
|
||||
load_preferences,
|
||||
|
||||
Reference in New Issue
Block a user