Mon, 20 Feb 2017 16:04:14 +0100
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 |
1.1 --- a/test/string_tests.c Mon Feb 20 15:25:28 2017 +0100 1.2 +++ b/test/string_tests.c Mon Feb 20 16:04:14 2017 +0100 1.3 @@ -283,7 +283,7 @@ 1.4 list = sstrsplit(test, S("string"), &n); 1.5 UCX_TEST_ASSERT(n == 2, "ewd, list length must be 2"); 1.6 UCX_TEST_ASSERT(strcmp(list[0].ptr, "this,is,a,csv,") == 0, 1.7 - "swd, first item corrupt"); 1.8 + "ewd, first item corrupt"); 1.9 UCX_TEST_ASSERT(list[1].length == 0, "ewd, second item must be empty"); 1.10 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, 1.11 "ewd, original has been modified"); 1.12 @@ -291,6 +291,19 @@ 1.13 free(list[i].ptr); 1.14 } 1.15 free(list); 1.16 + 1.17 + /* end with delimiter exceed bound (ewdeb) */ 1.18 + n = 3; 1.19 + sstr_t ewdebtest = ST("a,b,c,"); 1.20 + list = sstrsplit(ewdebtest, S(","), &n); 1.21 + UCX_TEST_ASSERT(n == 3, "ewdeb, list length must be 3"); 1.22 + UCX_TEST_ASSERT(strcmp(list[0].ptr, "a") == 0, "ewdeb, fst item corrupt"); 1.23 + UCX_TEST_ASSERT(strcmp(list[1].ptr, "b") == 0, "ewdeb, snd item corrupt"); 1.24 + UCX_TEST_ASSERT(strcmp(list[2].ptr, "c") == 0, "ewdeb, trd item corrupt"); 1.25 + for(int i=0;i<n;i++) { 1.26 + free(list[i].ptr); 1.27 + } 1.28 + free(list); 1.29 1.30 /* exact match (exm) */ 1.31 n = 0;