about summary refs log tree commit diff stats
path: root/tests/test_util.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-07-01 14:47:09 +0100
committerJames Booth <boothj5@gmail.com>2012-07-01 14:47:09 +0100
commit30ca6cac3d7f86e4a43410ba361793cd99d97a10 (patch)
treedf0c1fa32c36b1b5ce7e2129892646547a28435e /tests/test_util.c
parent9e686c0e01520c238b53b5620f936cebc7d5ba88 (diff)
downloadprofani-tty-30ca6cac3d7f86e4a43410ba361793cd99d97a10.tar.gz
Added autobuild tools
Diffstat (limited to 'tests/test_util.c')
-rw-r--r--tests/test_util.c165
1 files changed, 165 insertions, 0 deletions
diff --git a/tests/test_util.c b/tests/test_util.c
new file mode 100644
index 00000000..ffe12506
--- /dev/null
+++ b/tests/test_util.c
@@ -0,0 +1,165 @@
+#include <stdlib.h>
+#include <string.h>
+#include <head-unit.h>
+#include "util.h"
+
+void replace_one_substr(void)
+{
+    char *string = "it is a string";
+    char *sub = "is";
+    char *new = "was";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("it was a string", result);
+}
+
+void replace_one_substr_beginning(void)
+{
+    char *string = "it is a string";
+    char *sub = "it";
+    char *new = "that";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("that is a string", result);
+}
+
+void replace_one_substr_end(void)
+{
+    char *string = "it is a string";
+    char *sub = "string";
+    char *new = "thing";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("it is a thing", result);
+}
+
+void replace_two_substr(void)
+{
+    char *string = "it is a is string";
+    char *sub = "is";
+    char *new = "was";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("it was a was string", result);
+}
+
+void replace_char(void)
+{
+    char *string = "some & a thing & something else";
+    char *sub = "&";
+    char *new = "&amp;";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("some &amp; a thing &amp; something else", result);
+}
+
+void replace_when_none(void)
+{
+    char *string = "its another string";
+    char *sub = "haha";
+    char *new = "replaced";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("its another string", result);
+}
+
+void replace_when_match(void)
+{
+    char *string = "hello";
+    char *sub = "hello";
+    char *new = "goodbye";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("goodbye", result);
+}
+
+void replace_when_string_empty(void)
+{
+    char *string = "";
+    char *sub = "hello";
+    char *new = "goodbye";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("", result);
+}
+
+void replace_when_string_null(void)
+{
+    char *string = NULL;
+    char *sub = "hello";
+    char *new = "goodbye";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_is_null(result);
+}
+
+void replace_when_sub_empty(void)
+{
+    char *string = "hello";
+    char *sub = "";
+    char *new = "goodbye";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("hello", result);
+}
+
+void replace_when_sub_null(void)
+{
+    char *string = "hello";
+    char *sub = NULL;
+    char *new = "goodbye";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("hello", result);
+}
+
+void replace_when_new_empty(void)
+{
+    char *string = "hello";
+    char *sub = "hello";
+    char *new = "";
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("", result);
+}
+
+void replace_when_new_null(void)
+{
+    char *string = "hello";
+    char *sub = "hello";
+    char *new = NULL;
+
+    char *result = str_replace(string, sub, new);
+
+    assert_string_equals("hello", result);
+}
+
+void register_util_tests(void)
+{
+    TEST_MODULE("util tests");
+    TEST(replace_one_substr);
+    TEST(replace_one_substr_beginning);
+    TEST(replace_one_substr_end);
+    TEST(replace_two_substr);
+    TEST(replace_char);
+    TEST(replace_when_none);
+    TEST(replace_when_match);
+    TEST(replace_when_string_empty);
+    TEST(replace_when_string_null);
+    TEST(replace_when_sub_empty);
+    TEST(replace_when_sub_null);
+    TEST(replace_when_new_empty);
+    TEST(replace_when_new_null);
+}