test/string_tests.c

changeset 232
5f2d650eade7
parent 225
a1a068c2c4ef
child 233
bd58fdde142d
equal deleted inserted replaced
231:35490eb48214 232:5f2d650eade7
281 /* end with delimiter (ewd) */ 281 /* end with delimiter (ewd) */
282 n = 0; 282 n = 0;
283 list = sstrsplit(test, S("string"), &n); 283 list = sstrsplit(test, S("string"), &n);
284 UCX_TEST_ASSERT(n == 2, "ewd, list length must be 2"); 284 UCX_TEST_ASSERT(n == 2, "ewd, list length must be 2");
285 UCX_TEST_ASSERT(strcmp(list[0].ptr, "this,is,a,csv,") == 0, 285 UCX_TEST_ASSERT(strcmp(list[0].ptr, "this,is,a,csv,") == 0,
286 "swd, first item corrupt"); 286 "ewd, first item corrupt");
287 UCX_TEST_ASSERT(list[1].length == 0, "ewd, second item must be empty"); 287 UCX_TEST_ASSERT(list[1].length == 0, "ewd, second item must be empty");
288 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, 288 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
289 "ewd, original has been modified"); 289 "ewd, original has been modified");
290 for(int i=0;i<n;i++) {
291 free(list[i].ptr);
292 }
293 free(list);
294
295 /* end with delimiter exceed bound (ewdeb) */
296 n = 3;
297 sstr_t ewdebtest = ST("a,b,c,");
298 list = sstrsplit(ewdebtest, S(","), &n);
299 UCX_TEST_ASSERT(n == 3, "ewdeb, list length must be 3");
300 UCX_TEST_ASSERT(strcmp(list[0].ptr, "a") == 0, "ewdeb, fst item corrupt");
301 UCX_TEST_ASSERT(strcmp(list[1].ptr, "b") == 0, "ewdeb, snd item corrupt");
302 UCX_TEST_ASSERT(strcmp(list[2].ptr, "c") == 0, "ewdeb, trd item corrupt");
290 for(int i=0;i<n;i++) { 303 for(int i=0;i<n;i++) {
291 free(list[i].ptr); 304 free(list[i].ptr);
292 } 305 }
293 free(list); 306 free(list);
294 307

mercurial