about summary refs log tree commit diff stats
path: root/tests/unittests
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-04-03 22:30:24 +0100
committerJames Booth <boothj5@gmail.com>2016-04-03 22:30:24 +0100
commitd9344b00fe6d3c77d8e935b7029ac11587e5001f (patch)
treeeda834822f7dc273cc0a029f98c3d429759a6f59 /tests/unittests
parent3086341e6882997009d30f6815f37ddc206eba7e (diff)
downloadprofani-tty-d9344b00fe6d3c77d8e935b7029ac11587e5001f.tar.gz
Added prof_strstr function
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_common.c171
-rw-r--r--tests/unittests/test_common.h1
-rw-r--r--tests/unittests/unittests.c10
3 files changed, 112 insertions, 70 deletions
diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c
index 0e26b704..e80edb1c 100644
--- a/tests/unittests/test_common.c
+++ b/tests/unittests/test_common.c
@@ -631,66 +631,113 @@ void strip_quotes_strips_both(void **state)
     free(result);
 }
 
-void str_not_contains_str(void **state)
-{
-    char *main = "somestring";
-    char *occur = "not";
-
-    assert_false(str_contains_str(main, occur));
-}
-
-void str_contains_str_at_start(void **state)
-{
-    char *main = "somestring";
-    char *occur = "some";
-
-    assert_true(str_contains_str(main, occur));
-}
-
-void str_contains_str_at_end(void **state)
-{
-    char *main = "somestring";
-    char *occur = "string";
-
-    assert_true(str_contains_str(main, occur));
-}
-
-void str_contains_str_in_middle(void **state)
-{
-    char *main = "somestring";
-    char *occur = "str";
-
-    assert_true(str_contains_str(main, occur));
-}
-
-void str_contains_str_whole(void **state)
-{
-    char *main = "somestring";
-    char *occur = "somestring";
-
-    assert_true(str_contains_str(main, occur));
-}
-
-void str_empty_not_contains_str(void **state)
-{
-    char *main = NULL;
-    char *occur = "str";
-
-    assert_false(str_contains_str(main, occur));
-}
-
-void str_not_contains_str_empty(void **state)
-{
-    char *main = "somestring";
-    char *occur = NULL;
-
-    assert_false(str_contains_str(main, occur));
-}
-
-void str_empty_not_contains_str_empty(void **state)
-{
-    char *main = NULL;
-    char *occur = NULL;
-
-    assert_false(str_contains_str(main, occur));
+void prof_strstr_contains(void **state)
+{
+    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);
+
+    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);
+
+    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);
+
+    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);
+
+    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",               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);
 }
diff --git a/tests/unittests/test_common.h b/tests/unittests/test_common.h
index 6f3f1698..f0e901a7 100644
--- a/tests/unittests/test_common.h
+++ b/tests/unittests/test_common.h
@@ -64,3 +64,4 @@ 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);
diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c
index 6b26cb29..8826f2ec 100644
--- a/tests/unittests/unittests.c
+++ b/tests/unittests/unittests.c
@@ -94,14 +94,6 @@ int main(int argc, char* argv[]) {
         unit_test(strip_quotes_strips_first),
         unit_test(strip_quotes_strips_last),
         unit_test(strip_quotes_strips_both),
-        unit_test(str_not_contains_str),
-        unit_test(str_contains_str_at_start),
-        unit_test(str_contains_str_at_end),
-        unit_test(str_contains_str_in_middle),
-        unit_test(str_contains_str_whole),
-        unit_test(str_empty_not_contains_str),
-        unit_test(str_not_contains_str_empty),
-        unit_test(str_empty_not_contains_str_empty),
 
         unit_test(clear_empty),
         unit_test(reset_after_create),
@@ -624,6 +616,8 @@ int main(int argc, char* argv[]) {
         unit_test_setup_teardown(clears_chat_sessions,
             load_preferences,
             close_preferences),
+
+        unit_test(prof_strstr_contains),
     };
 
     return run_tests(all_tests);