test/string_tests.c

changeset 184
5c0990c95f74
parent 180
2185f19dcc45
child 192
1e51558b9d09
--- a/test/string_tests.c	Mon Jul 21 13:04:57 2014 +0200
+++ b/test/string_tests.c	Mon Jul 21 13:18:32 2014 +0200
@@ -45,11 +45,15 @@
     sstr_t s2 = ST(".:.:.");
     sstr_t s3 = ST("X");
     
-    size_t len = sstrnlen(3, s1, s2, s3);
+    size_t len1 = sstrnlen(1, s1);
+    size_t len2 = sstrnlen(2, s1, s2);
+    size_t len3 = sstrnlen(3, s1, s2, s3);
     
     UCX_TEST_BEGIN
     
-    UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size");
+    UCX_TEST_ASSERT(len1 == 4, "sstrnlen returned wrong size");
+    UCX_TEST_ASSERT(len2 == 9, "sstrnlen returned wrong size");
+    UCX_TEST_ASSERT(len3 == 10, "sstrnlen returned wrong size");
 
     UCX_TEST_END
 }
@@ -59,6 +63,9 @@
     sstr_t str = ST("I will find you - and I will kill you");
     UCX_TEST_BEGIN
     
+    sstr_t notfound = sstrchr(str, 'x');
+    UCX_TEST_ASSERT(notfound.length == 0, "string length not 0");
+    
     sstr_t result = sstrchr(str, 'w');
     UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length");
     UCX_TEST_ASSERT(strcmp("will find you - and I will kill you", result.ptr)
@@ -76,6 +83,8 @@
     sstr_t str = ST("compare this");
     
     UCX_TEST_BEGIN
+    UCX_TEST_ASSERT(sstrcmp(str, S("")) == 1, "empty cmp failed");
+    UCX_TEST_ASSERT(sstrcmp(S(""), S("")) == 0, "empty cmp false negative");
     UCX_TEST_ASSERT(sstrcmp(str, S("compare this")) == 0, "false negative");
     UCX_TEST_ASSERT(sstrcmp(str, S("Compare This")) != 0, "false positive");
     UCX_TEST_ASSERT(sstrcmp(str, S("compare tool")) < 0, "memcmp < 0 failed");
@@ -90,6 +99,8 @@
     sstr_t str = ST("compare this");
     
     UCX_TEST_BEGIN
+    UCX_TEST_ASSERT(sstrcasecmp(str, S("")) == 1, "empty cmp failed");
+    UCX_TEST_ASSERT(sstrcasecmp(S(""), S("")) == 0, "empty cmp false negative");
     UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this")) == 0, "false negative");
     UCX_TEST_ASSERT(sstrcasecmp(str, S("Compare This")) == 0,
         "not ignoring case");

mercurial