adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound

Mon, 20 Feb 2017 16:04:14 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 20 Feb 2017 16:04:14 +0100
changeset 232
5f2d650eade7
parent 231
35490eb48214
child 233
bd58fdde142d

adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound

test/string_tests.c file | annotate | diff | comparison | revisions
--- a/test/string_tests.c	Mon Feb 20 15:25:28 2017 +0100
+++ b/test/string_tests.c	Mon Feb 20 16:04:14 2017 +0100
@@ -283,7 +283,7 @@
     list = sstrsplit(test, S("string"), &n);
     UCX_TEST_ASSERT(n == 2, "ewd, list length must be 2");
     UCX_TEST_ASSERT(strcmp(list[0].ptr, "this,is,a,csv,") == 0,
-            "swd, first item corrupt");
+            "ewd, first item corrupt");
     UCX_TEST_ASSERT(list[1].length == 0, "ewd, second item must be empty");
     UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
             "ewd, original has been modified");
@@ -291,6 +291,19 @@
         free(list[i].ptr);
     }
     free(list);
+    
+    /* end with delimiter exceed bound (ewdeb) */
+    n = 3;
+    sstr_t ewdebtest = ST("a,b,c,");
+    list = sstrsplit(ewdebtest, S(","), &n);
+    UCX_TEST_ASSERT(n == 3, "ewdeb, list length must be 3");
+    UCX_TEST_ASSERT(strcmp(list[0].ptr, "a") == 0, "ewdeb, fst item corrupt");
+    UCX_TEST_ASSERT(strcmp(list[1].ptr, "b") == 0, "ewdeb, snd item corrupt");
+    UCX_TEST_ASSERT(strcmp(list[2].ptr, "c") == 0, "ewdeb, trd item corrupt");
+    for(int i=0;i<n;i++) {
+        free(list[i].ptr);
+    }
+    free(list);
 
     /* exact match (exm) */
     n = 0;

mercurial