about summary refs log tree commit diff stats
path: root/tests/unittests/test_common.c
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/test_common.c
parent3086341e6882997009d30f6815f37ddc206eba7e (diff)
downloadprofani-tty-d9344b00fe6d3c77d8e935b7029ac11587e5001f.tar.gz
Added prof_strstr function
Diffstat (limited to 'tests/unittests/test_common.c')
-rw-r--r--tests/unittests/test_common.c171
1 files changed, 109 insertions, 62 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);
 }