| 291 cx_testing_allocator_init(&talloc); |
291 cx_testing_allocator_init(&talloc); |
| 292 CxAllocator *alloc = &talloc.base; |
292 CxAllocator *alloc = &talloc.base; |
| 293 |
293 |
| 294 CX_TEST_DO { |
294 CX_TEST_DO { |
| 295 cxmutstr t1 = cx_strcat_a(alloc, 2, s1, s2); |
295 cxmutstr t1 = cx_strcat_a(alloc, 2, s1, s2); |
| 296 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t1), CX_STR("1234"))); |
296 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t1), cx_str("1234"))); |
| 297 ASSERT_ZERO_TERMINATED(t1); |
297 ASSERT_ZERO_TERMINATED(t1); |
| 298 cx_strfree_a(alloc, &t1); |
298 cx_strfree_a(alloc, &t1); |
| 299 |
299 |
| 300 cxmutstr t2 = cx_strcat_a(alloc, 3, s1, s2, s3); |
300 cxmutstr t2 = cx_strcat_a(alloc, 3, s1, s2, s3); |
| 301 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t2), CX_STR("123456"))); |
301 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t2), cx_str("123456"))); |
| 302 ASSERT_ZERO_TERMINATED(t2); |
302 ASSERT_ZERO_TERMINATED(t2); |
| 303 cx_strfree_a(alloc, &t2); |
303 cx_strfree_a(alloc, &t2); |
| 304 |
304 |
| 305 cxmutstr t3 = cx_strcat_a(alloc, 6, s1, sn, s2, sn, s3, sn); |
305 cxmutstr t3 = cx_strcat_a(alloc, 6, s1, sn, s2, sn, s3, sn); |
| 306 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t3), CX_STR("123456"))); |
306 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t3), cx_str("123456"))); |
| 307 ASSERT_ZERO_TERMINATED(t3); |
307 ASSERT_ZERO_TERMINATED(t3); |
| 308 cx_strfree_a(alloc, &t3); |
308 cx_strfree_a(alloc, &t3); |
| 309 |
309 |
| 310 cxmutstr t4 = cx_strcat_a(alloc, 2, sn, sn); |
310 cxmutstr t4 = cx_strcat_a(alloc, 2, sn, sn); |
| 311 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t4), CX_STR(""))); |
311 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t4), cx_str(""))); |
| 312 ASSERT_ZERO_TERMINATED(t4); |
312 ASSERT_ZERO_TERMINATED(t4); |
| 313 cx_strfree_a(alloc, &t4); |
313 cx_strfree_a(alloc, &t4); |
| 314 |
314 |
| 315 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
315 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| 316 |
316 |
| 317 // use the macro |
317 // use the macro |
| 318 cxmutstr t5 = cx_strcat(3, s3, s1, s2); |
318 cxmutstr t5 = cx_strcat(3, s3, s1, s2); |
| 319 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t5), CX_STR("561234"))); |
319 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t5), cx_str("561234"))); |
| 320 ASSERT_ZERO_TERMINATED(t5); |
320 ASSERT_ZERO_TERMINATED(t5); |
| 321 cx_strfree(&t5); |
321 cx_strfree(&t5); |
| 322 |
322 |
| 323 // use an initial string |
323 // use an initial string |
| 324 cxmutstr t6 = cx_strdup(CX_STR("Hello")); |
324 cxmutstr t6 = cx_strdup(cx_str("Hello")); |
| 325 t6 = cx_strcat_m(t6, 2, CX_STR(", "), CX_STR("World!")); |
325 t6 = cx_strcat_m(t6, 2, cx_str(", "), cx_str("World!")); |
| 326 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t6), CX_STR("Hello, World!"))); |
326 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t6), cx_str("Hello, World!"))); |
| 327 ASSERT_ZERO_TERMINATED(t6); |
327 ASSERT_ZERO_TERMINATED(t6); |
| 328 cx_strfree(&t6); |
328 cx_strfree(&t6); |
| 329 } |
329 } |
| 330 cx_testing_allocator_destroy(&talloc); |
330 cx_testing_allocator_destroy(&talloc); |
| 331 } |
331 } |
| 354 size_t capa = 8; |
354 size_t capa = 8; |
| 355 cxstring list[8]; |
355 cxstring list[8]; |
| 356 size_t n; |
356 size_t n; |
| 357 CX_TEST_DO { |
357 CX_TEST_DO { |
| 358 // special case: empty string |
358 // special case: empty string |
| 359 n = cx_strsplit(test, CX_STR(""), capa, list); |
359 n = cx_strsplit(test, cx_str(""), capa, list); |
| 360 CX_TEST_ASSERT(n == 1); |
360 CX_TEST_ASSERT(n == 1); |
| 361 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
361 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
| 362 |
362 |
| 363 // no delimiter occurrence |
363 // no delimiter occurrence |
| 364 n = cx_strsplit(test, CX_STR("z"), capa, list); |
364 n = cx_strsplit(test, cx_str("z"), capa, list); |
| 365 CX_TEST_ASSERT(n == 1); |
365 CX_TEST_ASSERT(n == 1); |
| 366 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
366 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
| 367 |
367 |
| 368 // partially matching delimiter |
368 // partially matching delimiter |
| 369 n = cx_strsplit(test, CX_STR("is,not"), capa, list); |
369 n = cx_strsplit(test, cx_str("is,not"), capa, list); |
| 370 CX_TEST_ASSERT(n == 1); |
370 CX_TEST_ASSERT(n == 1); |
| 371 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
371 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
| 372 |
372 |
| 373 // matching single-char delimiter |
373 // matching single-char delimiter |
| 374 n = cx_strsplit(test, CX_STR(","), capa, list); |
374 n = cx_strsplit(test, cx_str(","), capa, list); |
| 375 CX_TEST_ASSERT(n == 5); |
375 CX_TEST_ASSERT(n == 5); |
| 376 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this"))); |
376 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this"))); |
| 377 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("is"))); |
377 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("is"))); |
| 378 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a"))); |
378 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a"))); |
| 379 CX_TEST_ASSERT(0 == cx_strcmp(list[3], CX_STR("csv"))); |
379 CX_TEST_ASSERT(0 == cx_strcmp(list[3], cx_str("csv"))); |
| 380 CX_TEST_ASSERT(0 == cx_strcmp(list[4], CX_STR("string"))); |
380 CX_TEST_ASSERT(0 == cx_strcmp(list[4], cx_str("string"))); |
| 381 |
381 |
| 382 // matching multi-char delimiter |
382 // matching multi-char delimiter |
| 383 n = cx_strsplit(test, CX_STR("is"), capa, list); |
383 n = cx_strsplit(test, cx_str("is"), capa, list); |
| 384 CX_TEST_ASSERT(n == 3); |
384 CX_TEST_ASSERT(n == 3); |
| 385 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th"))); |
385 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th"))); |
| 386 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(","))); |
386 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(","))); |
| 387 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR(",a,csv,string"))); |
387 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str(",a,csv,string"))); |
| 388 |
388 |
| 389 // bounded list using single-char delimiter |
389 // bounded list using single-char delimiter |
| 390 n = cx_strsplit(test, CX_STR(","), 3, list); |
390 n = cx_strsplit(test, cx_str(","), 3, list); |
| 391 CX_TEST_ASSERT(n == 3); |
391 CX_TEST_ASSERT(n == 3); |
| 392 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this"))); |
392 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this"))); |
| 393 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("is"))); |
393 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("is"))); |
| 394 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a,csv,string"))); |
394 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a,csv,string"))); |
| 395 |
395 |
| 396 // bounded list using multi-char delimiter |
396 // bounded list using multi-char delimiter |
| 397 n = cx_strsplit(test, CX_STR("is"), 2, list); |
397 n = cx_strsplit(test, cx_str("is"), 2, list); |
| 398 CX_TEST_ASSERT(n == 2); |
398 CX_TEST_ASSERT(n == 2); |
| 399 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th"))); |
399 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th"))); |
| 400 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",is,a,csv,string"))); |
400 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",is,a,csv,string"))); |
| 401 |
401 |
| 402 // start with delimiter |
402 // start with delimiter |
| 403 n = cx_strsplit(test, CX_STR("this"), capa, list); |
403 n = cx_strsplit(test, cx_str("this"), capa, list); |
| 404 CX_TEST_ASSERT(n == 2); |
404 CX_TEST_ASSERT(n == 2); |
| 405 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR(""))); |
405 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str(""))); |
| 406 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",is,a,csv,string"))); |
406 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",is,a,csv,string"))); |
| 407 |
407 |
| 408 // end with delimiter |
408 // end with delimiter |
| 409 n = cx_strsplit(test, CX_STR("string"), capa, list); |
409 n = cx_strsplit(test, cx_str("string"), capa, list); |
| 410 CX_TEST_ASSERT(n == 2); |
410 CX_TEST_ASSERT(n == 2); |
| 411 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this,is,a,csv,"))); |
411 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this,is,a,csv,"))); |
| 412 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(""))); |
412 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(""))); |
| 413 |
413 |
| 414 |
414 |
| 415 // end with delimiter exceed bound |
415 // end with delimiter exceed bound |
| 416 n = cx_strsplit(CX_STR("a,b,c,"), CX_STR(","), 3, list); |
416 n = cx_strsplit(cx_str("a,b,c,"), cx_str(","), 3, list); |
| 417 CX_TEST_ASSERT(n == 3); |
417 CX_TEST_ASSERT(n == 3); |
| 418 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("a"))); |
418 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("a"))); |
| 419 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("b"))); |
419 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("b"))); |
| 420 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("c,"))); |
420 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("c,"))); |
| 421 |
421 |
| 422 // exact match |
422 // exact match |
| 423 n = cx_strsplit(test, CX_STR("this,is,a,csv,string"), capa, list); |
423 n = cx_strsplit(test, cx_str("this,is,a,csv,string"), capa, list); |
| 424 CX_TEST_ASSERT(n == 2); |
424 CX_TEST_ASSERT(n == 2); |
| 425 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR(""))); |
425 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str(""))); |
| 426 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(""))); |
426 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(""))); |
| 427 |
427 |
| 428 // string to be split is only substring |
428 // string to be split is only substring |
| 429 n = cx_strsplit(test, CX_STR("this,is,a,csv,string,with,extension"), capa, list); |
429 n = cx_strsplit(test, cx_str("this,is,a,csv,string,with,extension"), capa, list); |
| 430 CX_TEST_ASSERT(n == 1); |
430 CX_TEST_ASSERT(n == 1); |
| 431 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
431 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
| 432 |
432 |
| 433 // subsequent encounter of delimiter (the string between is empty) |
433 // subsequent encounter of delimiter (the string between is empty) |
| 434 n = cx_strsplit(test, CX_STR("is,"), capa, list); |
434 n = cx_strsplit(test, cx_str("is,"), capa, list); |
| 435 CX_TEST_ASSERT(n == 3); |
435 CX_TEST_ASSERT(n == 3); |
| 436 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th"))); |
436 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th"))); |
| 437 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(""))); |
437 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(""))); |
| 438 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a,csv,string"))); |
438 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a,csv,string"))); |
| 439 |
439 |
| 440 // call the _m variant just for coverage |
440 // call the _m variant just for coverage |
| 441 cxmutstr mtest = cx_strdup(test); |
441 cxmutstr mtest = cx_strdup(test); |
| 442 cxmutstr mlist[4]; |
442 cxmutstr mlist[4]; |
| 443 n = cx_strsplit_m(mtest, CX_STR("is,"), 4, mlist); |
443 n = cx_strsplit_m(mtest, cx_str("is,"), 4, mlist); |
| 444 CX_TEST_ASSERT(n == 3); |
444 CX_TEST_ASSERT(n == 3); |
| 445 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), CX_STR("th"))); |
445 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), cx_str("th"))); |
| 446 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), CX_STR(""))); |
446 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), cx_str(""))); |
| 447 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), CX_STR("a,csv,string"))); |
447 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string"))); |
| 448 cx_strfree(&mtest); |
448 cx_strfree(&mtest); |
| 449 } |
449 } |
| 450 } |
450 } |
| 451 |
451 |
| 452 CX_TEST(test_strsplit_a) { |
452 CX_TEST(test_strsplit_a) { |
| 458 size_t capa = 8; |
458 size_t capa = 8; |
| 459 cxstring *list; |
459 cxstring *list; |
| 460 size_t n; |
460 size_t n; |
| 461 CX_TEST_DO { |
461 CX_TEST_DO { |
| 462 // special case: empty string |
462 // special case: empty string |
| 463 n = cx_strsplit_a(alloc, test, CX_STR(""), capa, &list); |
463 n = cx_strsplit_a(alloc, test, cx_str(""), capa, &list); |
| 464 CX_TEST_ASSERT(n == 1); |
464 CX_TEST_ASSERT(n == 1); |
| 465 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
465 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
| 466 cxFree(alloc, list); |
466 cxFree(alloc, list); |
| 467 |
467 |
| 468 // no delimiter occurrence |
468 // no delimiter occurrence |
| 469 n = cx_strsplit_a(alloc, test, CX_STR("z"), capa, &list); |
469 n = cx_strsplit_a(alloc, test, cx_str("z"), capa, &list); |
| 470 CX_TEST_ASSERT(n == 1); |
470 CX_TEST_ASSERT(n == 1); |
| 471 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
471 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
| 472 cxFree(alloc, list); |
472 cxFree(alloc, list); |
| 473 |
473 |
| 474 // partially matching delimiter |
474 // partially matching delimiter |
| 475 n = cx_strsplit_a(alloc, test, CX_STR("is,not"), capa, &list); |
475 n = cx_strsplit_a(alloc, test, cx_str("is,not"), capa, &list); |
| 476 CX_TEST_ASSERT(n == 1); |
476 CX_TEST_ASSERT(n == 1); |
| 477 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
477 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
| 478 cxFree(alloc, list); |
478 cxFree(alloc, list); |
| 479 |
479 |
| 480 // matching single-char delimiter |
480 // matching single-char delimiter |
| 481 n = cx_strsplit_a(alloc, test, CX_STR(","), capa, &list); |
481 n = cx_strsplit_a(alloc, test, cx_str(","), capa, &list); |
| 482 CX_TEST_ASSERT(n == 5); |
482 CX_TEST_ASSERT(n == 5); |
| 483 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this"))); |
483 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this"))); |
| 484 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("is"))); |
484 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("is"))); |
| 485 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a"))); |
485 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a"))); |
| 486 CX_TEST_ASSERT(0 == cx_strcmp(list[3], CX_STR("csv"))); |
486 CX_TEST_ASSERT(0 == cx_strcmp(list[3], cx_str("csv"))); |
| 487 CX_TEST_ASSERT(0 == cx_strcmp(list[4], CX_STR("string"))); |
487 CX_TEST_ASSERT(0 == cx_strcmp(list[4], cx_str("string"))); |
| 488 cxFree(alloc, list); |
488 cxFree(alloc, list); |
| 489 |
489 |
| 490 // matching multi-char delimiter |
490 // matching multi-char delimiter |
| 491 n = cx_strsplit_a(alloc, test, CX_STR("is"), capa, &list); |
491 n = cx_strsplit_a(alloc, test, cx_str("is"), capa, &list); |
| 492 CX_TEST_ASSERT(n == 3); |
492 CX_TEST_ASSERT(n == 3); |
| 493 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th"))); |
493 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th"))); |
| 494 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(","))); |
494 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(","))); |
| 495 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR(",a,csv,string"))); |
495 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str(",a,csv,string"))); |
| 496 cxFree(alloc, list); |
496 cxFree(alloc, list); |
| 497 |
497 |
| 498 // bounded list using single-char delimiter |
498 // bounded list using single-char delimiter |
| 499 n = cx_strsplit_a(alloc, test, CX_STR(","), 3, &list); |
499 n = cx_strsplit_a(alloc, test, cx_str(","), 3, &list); |
| 500 CX_TEST_ASSERT(n == 3); |
500 CX_TEST_ASSERT(n == 3); |
| 501 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this"))); |
501 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this"))); |
| 502 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("is"))); |
502 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("is"))); |
| 503 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a,csv,string"))); |
503 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a,csv,string"))); |
| 504 cxFree(alloc, list); |
504 cxFree(alloc, list); |
| 505 |
505 |
| 506 // bounded list using multi-char delimiter |
506 // bounded list using multi-char delimiter |
| 507 n = cx_strsplit_a(alloc, test, CX_STR("is"), 2, &list); |
507 n = cx_strsplit_a(alloc, test, cx_str("is"), 2, &list); |
| 508 CX_TEST_ASSERT(n == 2); |
508 CX_TEST_ASSERT(n == 2); |
| 509 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th"))); |
509 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th"))); |
| 510 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",is,a,csv,string"))); |
510 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",is,a,csv,string"))); |
| 511 cxFree(alloc, list); |
511 cxFree(alloc, list); |
| 512 |
512 |
| 513 // start with delimiter |
513 // start with delimiter |
| 514 n = cx_strsplit_a(alloc, test, CX_STR("this"), capa, &list); |
514 n = cx_strsplit_a(alloc, test, cx_str("this"), capa, &list); |
| 515 CX_TEST_ASSERT(n == 2); |
515 CX_TEST_ASSERT(n == 2); |
| 516 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR(""))); |
516 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str(""))); |
| 517 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(",is,a,csv,string"))); |
517 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",is,a,csv,string"))); |
| 518 cxFree(alloc, list); |
518 cxFree(alloc, list); |
| 519 |
519 |
| 520 // end with delimiter |
520 // end with delimiter |
| 521 n = cx_strsplit_a(alloc, test, CX_STR("string"), capa, &list); |
521 n = cx_strsplit_a(alloc, test, cx_str("string"), capa, &list); |
| 522 CX_TEST_ASSERT(n == 2); |
522 CX_TEST_ASSERT(n == 2); |
| 523 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("this,is,a,csv,"))); |
523 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this,is,a,csv,"))); |
| 524 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(""))); |
524 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(""))); |
| 525 cxFree(alloc, list); |
525 cxFree(alloc, list); |
| 526 |
526 |
| 527 // end with delimiter exceed bound |
527 // end with delimiter exceed bound |
| 528 n = cx_strsplit_a(alloc, CX_STR("a,b,c,"), CX_STR(","), 3, &list); |
528 n = cx_strsplit_a(alloc, cx_str("a,b,c,"), cx_str(","), 3, &list); |
| 529 CX_TEST_ASSERT(n == 3); |
529 CX_TEST_ASSERT(n == 3); |
| 530 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("a"))); |
530 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("a"))); |
| 531 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR("b"))); |
531 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("b"))); |
| 532 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("c,"))); |
532 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("c,"))); |
| 533 cxFree(alloc, list); |
533 cxFree(alloc, list); |
| 534 |
534 |
| 535 // exact match |
535 // exact match |
| 536 n = cx_strsplit_a(alloc, test, CX_STR("this,is,a,csv,string"), capa, &list); |
536 n = cx_strsplit_a(alloc, test, cx_str("this,is,a,csv,string"), capa, &list); |
| 537 CX_TEST_ASSERT(n == 2); |
537 CX_TEST_ASSERT(n == 2); |
| 538 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR(""))); |
538 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str(""))); |
| 539 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(""))); |
539 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(""))); |
| 540 cxFree(alloc, list); |
540 cxFree(alloc, list); |
| 541 |
541 |
| 542 // string to be split is only substring |
542 // string to be split is only substring |
| 543 n = cx_strsplit_a(alloc, test, CX_STR("this,is,a,csv,string,with,extension"), capa, &list); |
543 n = cx_strsplit_a(alloc, test, cx_str("this,is,a,csv,string,with,extension"), capa, &list); |
| 544 CX_TEST_ASSERT(n == 1); |
544 CX_TEST_ASSERT(n == 1); |
| 545 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
545 CX_TEST_ASSERT(0 == cx_strcmp(list[0], test)); |
| 546 cxFree(alloc, list); |
546 cxFree(alloc, list); |
| 547 |
547 |
| 548 // subsequent encounter of delimiter (the string between is empty) |
548 // subsequent encounter of delimiter (the string between is empty) |
| 549 n = cx_strsplit_a(alloc, test, CX_STR("is,"), capa, &list); |
549 n = cx_strsplit_a(alloc, test, cx_str("is,"), capa, &list); |
| 550 CX_TEST_ASSERT(n == 3); |
550 CX_TEST_ASSERT(n == 3); |
| 551 CX_TEST_ASSERT(0 == cx_strcmp(list[0], CX_STR("th"))); |
551 CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th"))); |
| 552 CX_TEST_ASSERT(0 == cx_strcmp(list[1], CX_STR(""))); |
552 CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(""))); |
| 553 CX_TEST_ASSERT(0 == cx_strcmp(list[2], CX_STR("a,csv,string"))); |
553 CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a,csv,string"))); |
| 554 cxFree(alloc, list); |
554 cxFree(alloc, list); |
| 555 |
555 |
| 556 // call the _m variant just for coverage |
556 // call the _m variant just for coverage |
| 557 cxmutstr mtest = cx_strdup(test); |
557 cxmutstr mtest = cx_strdup(test); |
| 558 cxmutstr *mlist; |
558 cxmutstr *mlist; |
| 559 n = cx_strsplit_ma(alloc, mtest, CX_STR("is,"), 4, &mlist); |
559 n = cx_strsplit_ma(alloc, mtest, cx_str("is,"), 4, &mlist); |
| 560 CX_TEST_ASSERT(n == 3); |
560 CX_TEST_ASSERT(n == 3); |
| 561 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), CX_STR("th"))); |
561 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), cx_str("th"))); |
| 562 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), CX_STR(""))); |
562 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), cx_str(""))); |
| 563 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), CX_STR("a,csv,string"))); |
563 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string"))); |
| 564 cxFree(alloc, mlist); |
564 cxFree(alloc, mlist); |
| 565 cx_strfree(&mtest); |
565 cx_strfree(&mtest); |
| 566 |
566 |
| 567 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
567 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| 568 } |
568 } |
| 569 cx_testing_allocator_destroy(&talloc); |
569 cx_testing_allocator_destroy(&talloc); |
| 570 } |
570 } |
| 571 |
571 |
| 572 CX_TEST(test_strtrim) { |
572 CX_TEST(test_strtrim) { |
| 573 cxstring t1 = cx_strtrim(CX_STR(" ein test \t ")); |
573 cxstring t1 = cx_strtrim(cx_str(" ein test \t ")); |
| 574 cxstring t2 = cx_strtrim(CX_STR("abc")); |
574 cxstring t2 = cx_strtrim(cx_str("abc")); |
| 575 cxstring t3 = cx_strtrim(CX_STR(" 123")); |
575 cxstring t3 = cx_strtrim(cx_str(" 123")); |
| 576 cxstring t4 = cx_strtrim(CX_STR("xyz ")); |
576 cxstring t4 = cx_strtrim(cx_str("xyz ")); |
| 577 cxstring t5 = cx_strtrim(CX_STR(" ")); |
577 cxstring t5 = cx_strtrim(cx_str(" ")); |
| 578 cxstring empty = cx_strtrim(CX_STR("")); |
578 cxstring empty = cx_strtrim(cx_str("")); |
| 579 |
579 |
| 580 CX_TEST_DO { |
580 CX_TEST_DO { |
| 581 CX_TEST_ASSERT(0 == cx_strcmp(t1, CX_STR("ein test"))); |
581 CX_TEST_ASSERT(0 == cx_strcmp(t1, cx_str("ein test"))); |
| 582 CX_TEST_ASSERT(0 == cx_strcmp(t2, CX_STR("abc"))); |
582 CX_TEST_ASSERT(0 == cx_strcmp(t2, cx_str("abc"))); |
| 583 CX_TEST_ASSERT(0 == cx_strcmp(t3, CX_STR("123"))); |
583 CX_TEST_ASSERT(0 == cx_strcmp(t3, cx_str("123"))); |
| 584 CX_TEST_ASSERT(0 == cx_strcmp(t4, CX_STR("xyz"))); |
584 CX_TEST_ASSERT(0 == cx_strcmp(t4, cx_str("xyz"))); |
| 585 CX_TEST_ASSERT(0 == cx_strcmp(t5, CX_STR(""))); |
585 CX_TEST_ASSERT(0 == cx_strcmp(t5, cx_str(""))); |
| 586 CX_TEST_ASSERT(0 == cx_strcmp(empty, CX_STR(""))); |
586 CX_TEST_ASSERT(0 == cx_strcmp(empty, cx_str(""))); |
| 587 |
587 |
| 588 // call the _m variant just for coverage |
588 // call the _m variant just for coverage |
| 589 cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) " ein test \t ")); |
589 cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) " ein test \t ")); |
| 590 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m1), CX_STR("ein test"))); |
590 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m1), cx_str("ein test"))); |
| 591 } |
591 } |
| 592 } |
592 } |
| 593 |
593 |
| 594 CX_TEST(test_strprefix) { |
594 CX_TEST(test_strprefix) { |
| 595 cxstring str = CX_STR("test my prefix and my suffix"); |
595 cxstring str = CX_STR("test my prefix and my suffix"); |
| 596 cxstring empty = CX_STR(""); |
596 cxstring empty = CX_STR(""); |
| 597 CX_TEST_DO { |
597 CX_TEST_DO { |
| 598 CX_TEST_ASSERT(!cx_strprefix(empty, CX_STR("pref"))); |
598 CX_TEST_ASSERT(!cx_strprefix(empty, cx_str("pref"))); |
| 599 CX_TEST_ASSERT(cx_strprefix(str, empty)); |
599 CX_TEST_ASSERT(cx_strprefix(str, empty)); |
| 600 CX_TEST_ASSERT(cx_strprefix(empty, empty)); |
600 CX_TEST_ASSERT(cx_strprefix(empty, empty)); |
| 601 CX_TEST_ASSERT(cx_strprefix(str, CX_STR("test "))); |
601 CX_TEST_ASSERT(cx_strprefix(str, cx_str("test "))); |
| 602 CX_TEST_ASSERT(!cx_strprefix(str, CX_STR("8-) fsck "))); |
602 CX_TEST_ASSERT(!cx_strprefix(str, cx_str("8-) fsck "))); |
| 603 } |
603 } |
| 604 } |
604 } |
| 605 |
605 |
| 606 CX_TEST(test_strsuffix) { |
606 CX_TEST(test_strsuffix) { |
| 607 cxstring str = CX_STR("test my prefix and my suffix"); |
607 cxstring str = CX_STR("test my prefix and my suffix"); |
| 608 cxstring empty = CX_STR(""); |
608 cxstring empty = CX_STR(""); |
| 609 CX_TEST_DO { |
609 CX_TEST_DO { |
| 610 CX_TEST_ASSERT(!cx_strsuffix(empty, CX_STR("suf"))); |
610 CX_TEST_ASSERT(!cx_strsuffix(empty, cx_str("suf"))); |
| 611 CX_TEST_ASSERT(cx_strsuffix(str, empty)); |
611 CX_TEST_ASSERT(cx_strsuffix(str, empty)); |
| 612 CX_TEST_ASSERT(cx_strsuffix(empty, empty)); |
612 CX_TEST_ASSERT(cx_strsuffix(empty, empty)); |
| 613 CX_TEST_ASSERT(cx_strsuffix(str, CX_STR("fix"))); |
613 CX_TEST_ASSERT(cx_strsuffix(str, cx_str("fix"))); |
| 614 CX_TEST_ASSERT(!cx_strsuffix(str, CX_STR("fox"))); |
614 CX_TEST_ASSERT(!cx_strsuffix(str, cx_str("fox"))); |
| 615 } |
615 } |
| 616 } |
616 } |
| 617 |
617 |
| 618 CX_TEST(test_strcaseprefix) { |
618 CX_TEST(test_strcaseprefix) { |
| 619 cxstring str = CX_STR("test my prefix and my suffix"); |
619 cxstring str = CX_STR("test my prefix and my suffix"); |
| 620 cxstring empty = CX_STR(""); |
620 cxstring empty = CX_STR(""); |
| 621 CX_TEST_DO { |
621 CX_TEST_DO { |
| 622 CX_TEST_ASSERT(!cx_strcaseprefix(empty, CX_STR("pREf"))); |
622 CX_TEST_ASSERT(!cx_strcaseprefix(empty, cx_str("pREf"))); |
| 623 CX_TEST_ASSERT(cx_strcaseprefix(str, empty)); |
623 CX_TEST_ASSERT(cx_strcaseprefix(str, empty)); |
| 624 CX_TEST_ASSERT(cx_strcaseprefix(empty, empty)); |
624 CX_TEST_ASSERT(cx_strcaseprefix(empty, empty)); |
| 625 CX_TEST_ASSERT(cx_strcaseprefix(str, CX_STR("TEST "))); |
625 CX_TEST_ASSERT(cx_strcaseprefix(str, cx_str("TEST "))); |
| 626 CX_TEST_ASSERT(!cx_strcaseprefix(str, CX_STR("8-) fsck "))); |
626 CX_TEST_ASSERT(!cx_strcaseprefix(str, cx_str("8-) fsck "))); |
| 627 } |
627 } |
| 628 } |
628 } |
| 629 |
629 |
| 630 CX_TEST(test_strcasesuffix) { |
630 CX_TEST(test_strcasesuffix) { |
| 631 cxstring str = CX_STR("test my prefix and my suffix"); |
631 cxstring str = CX_STR("test my prefix and my suffix"); |
| 632 cxstring empty = CX_STR(""); |
632 cxstring empty = CX_STR(""); |
| 633 CX_TEST_DO { |
633 CX_TEST_DO { |
| 634 CX_TEST_ASSERT(!cx_strcasesuffix(empty, CX_STR("sUf"))); |
634 CX_TEST_ASSERT(!cx_strcasesuffix(empty, cx_str("sUf"))); |
| 635 CX_TEST_ASSERT(cx_strcasesuffix(str, empty)); |
635 CX_TEST_ASSERT(cx_strcasesuffix(str, empty)); |
| 636 CX_TEST_ASSERT(cx_strcasesuffix(empty, empty)); |
636 CX_TEST_ASSERT(cx_strcasesuffix(empty, empty)); |
| 637 CX_TEST_ASSERT(cx_strcasesuffix(str, CX_STR("FIX"))); |
637 CX_TEST_ASSERT(cx_strcasesuffix(str, cx_str("FIX"))); |
| 638 CX_TEST_ASSERT(!cx_strcasesuffix(str, CX_STR("fox"))); |
638 CX_TEST_ASSERT(!cx_strcasesuffix(str, cx_str("fox"))); |
| 639 } |
639 } |
| 640 } |
640 } |
| 641 |
641 |
| 642 CX_TEST(test_strreplace) { |
642 CX_TEST(test_strreplace) { |
| 643 CxTestingAllocator talloc; |
643 CxTestingAllocator talloc; |
| 650 cxstring notrail = CX_STR("test abab"); |
650 cxstring notrail = CX_STR("test abab"); |
| 651 cxstring empty = CX_STR(""); |
651 cxstring empty = CX_STR(""); |
| 652 cxstring astr = CX_STR("aaaaaaaaaa"); |
652 cxstring astr = CX_STR("aaaaaaaaaa"); |
| 653 cxstring csstr = CX_STR("test AB ab TEST xyz"); |
653 cxstring csstr = CX_STR("test AB ab TEST xyz"); |
| 654 |
654 |
| 655 cxmutstr repl = cx_strreplace(str, CX_STR("abab"), CX_STR("muchlonger")); |
655 cxmutstr repl = cx_strreplace(str, cx_str("abab"), cx_str("muchlonger")); |
| 656 const char *expected = "test muchlongerab string aba"; |
656 const char *expected = "test muchlongerab string aba"; |
| 657 |
657 |
| 658 cxmutstr repln = cx_strreplacen(str, CX_STR("ab"), CX_STR("c"), 2); |
658 cxmutstr repln = cx_strreplacen(str, cx_str("ab"), cx_str("c"), 2); |
| 659 const char *expectedn = "test ccab string aba"; |
659 const char *expectedn = "test ccab string aba"; |
| 660 |
660 |
| 661 cxmutstr longrepl = cx_strreplace(longstr, CX_STR("a"), CX_STR("z")); |
661 cxmutstr longrepl = cx_strreplace(longstr, cx_str("a"), cx_str("z")); |
| 662 const char *longexpect = "xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzcd"; |
662 const char *longexpect = "xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzcd"; |
| 663 |
663 |
| 664 cxmutstr replnotrail = cx_strreplace(notrail, CX_STR("ab"), CX_STR("z")); |
664 cxmutstr replnotrail = cx_strreplace(notrail, cx_str("ab"), cx_str("z")); |
| 665 const char *notrailexpect = "test zz"; |
665 const char *notrailexpect = "test zz"; |
| 666 |
666 |
| 667 cxmutstr repleq = cx_strreplace(str, str, CX_STR("hello")); |
667 cxmutstr repleq = cx_strreplace(str, str, cx_str("hello")); |
| 668 const char *eqexpect = "hello"; |
668 const char *eqexpect = "hello"; |
| 669 |
669 |
| 670 cxmutstr replempty1 = cx_strreplace(empty, CX_STR("ab"), CX_STR("c")); // expect: empty |
670 cxmutstr replempty1 = cx_strreplace(empty, cx_str("ab"), cx_str("c")); // expect: empty |
| 671 cxmutstr replempty2 = cx_strreplace(str, CX_STR("abab"), empty); |
671 cxmutstr replempty2 = cx_strreplace(str, cx_str("abab"), empty); |
| 672 const char *emptyexpect2 = "test ab string aba"; |
672 const char *emptyexpect2 = "test ab string aba"; |
| 673 |
673 |
| 674 cxmutstr replpre = cx_strreplace(str, CX_STR("test "), CX_STR("TEST ")); |
674 cxmutstr replpre = cx_strreplace(str, cx_str("test "), cx_str("TEST ")); |
| 675 const char *preexpected = "TEST ababab string aba"; |
675 const char *preexpected = "TEST ababab string aba"; |
| 676 |
676 |
| 677 cxmutstr replan1 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 1); |
677 cxmutstr replan1 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 1); |
| 678 const char *an1expected = "xaaaaaaaaa"; |
678 const char *an1expected = "xaaaaaaaaa"; |
| 679 |
679 |
| 680 cxmutstr replan4 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 4); |
680 cxmutstr replan4 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 4); |
| 681 const char *an4expected = "xxxxaaaaaa"; |
681 const char *an4expected = "xxxxaaaaaa"; |
| 682 |
682 |
| 683 cxmutstr replan9 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 9); |
683 cxmutstr replan9 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 9); |
| 684 const char *an9expected = "xxxxxxxxxa"; |
684 const char *an9expected = "xxxxxxxxxa"; |
| 685 |
685 |
| 686 cxmutstr replan10 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 10); |
686 cxmutstr replan10 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 10); |
| 687 const char *an10expected = "xxxxxxxxxx"; |
687 const char *an10expected = "xxxxxxxxxx"; |
| 688 |
688 |
| 689 CX_TEST_DO { |
689 CX_TEST_DO { |
| 690 cxmutstr repl1_a = cx_strreplace_a(alloc, csstr, CX_STR("AB"), CX_STR("*")); |
690 cxmutstr repl1_a = cx_strreplace_a(alloc, csstr, cx_str("AB"), cx_str("*")); |
| 691 const char *expeced1_a = "test * ab TEST xyz"; |
691 const char *expeced1_a = "test * ab TEST xyz"; |
| 692 |
692 |
| 693 cxmutstr repl2_a = cx_strreplace_a(alloc, csstr, CX_STR("test"), CX_STR("TEST")); |
693 cxmutstr repl2_a = cx_strreplace_a(alloc, csstr, cx_str("test"), cx_str("TEST")); |
| 694 const char *expected2_a = "TEST AB ab TEST xyz"; |
694 const char *expected2_a = "TEST AB ab TEST xyz"; |
| 695 |
695 |
| 696 CX_TEST_ASSERT(repl.ptr != str.ptr); |
696 CX_TEST_ASSERT(repl.ptr != str.ptr); |
| 697 ASSERT_ZERO_TERMINATED(repl); |
697 ASSERT_ZERO_TERMINATED(repl); |
| 698 CX_TEST_ASSERT(0 == strcmp(repl.ptr, expected)); |
698 CX_TEST_ASSERT(0 == strcmp(repl.ptr, expected)); |
| 914 CX_TEST_ASSERT(ctx.found == 5); |
914 CX_TEST_ASSERT(ctx.found == 5); |
| 915 } |
915 } |
| 916 } |
916 } |
| 917 |
917 |
| 918 CX_TEST(test_strtok_next_advanced) { |
918 CX_TEST(test_strtok_next_advanced) { |
| 919 cxmutstr str = cx_strdup(CX_STR("an,arbitrarily;||separated;string")); |
919 cxmutstr str = cx_strdup(cx_str("an,arbitrarily;||separated;string")); |
| 920 cxstring delim = CX_STR(","); |
920 cxstring delim = CX_STR(","); |
| 921 cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; |
921 cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; |
| 922 CX_TEST_DO { |
922 CX_TEST_DO { |
| 923 CxStrtokCtx ctx = cx_strtok_m(str, delim, 10); |
923 CxStrtokCtx ctx = cx_strtok_m(str, delim, 10); |
| 924 cx_strtok_delim(&ctx, delim_more, 2); |
924 cx_strtok_delim(&ctx, delim_more, 2); |
| 925 bool ret; |
925 bool ret; |
| 926 cxmutstr tok; |
926 cxmutstr tok; |
| 927 |
927 |
| 928 ret = cx_strtok_next_m(&ctx, &tok); |
928 ret = cx_strtok_next_m(&ctx, &tok); |
| 929 CX_TEST_ASSERT(ret); |
929 CX_TEST_ASSERT(ret); |
| 930 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("an"))); |
930 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("an"))); |
| 931 CX_TEST_ASSERT(ctx.pos == 0); |
931 CX_TEST_ASSERT(ctx.pos == 0); |
| 932 CX_TEST_ASSERT(ctx.next_pos == 3); |
932 CX_TEST_ASSERT(ctx.next_pos == 3); |
| 933 CX_TEST_ASSERT(ctx.delim_pos == 2); |
933 CX_TEST_ASSERT(ctx.delim_pos == 2); |
| 934 CX_TEST_ASSERT(ctx.found == 1); |
934 CX_TEST_ASSERT(ctx.found == 1); |
| 935 cx_strupper(tok); |
935 cx_strupper(tok); |
| 936 |
936 |
| 937 ret = cx_strtok_next_m(&ctx, &tok); |
937 ret = cx_strtok_next_m(&ctx, &tok); |
| 938 CX_TEST_ASSERT(ret); |
938 CX_TEST_ASSERT(ret); |
| 939 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("arbitrarily"))); |
939 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("arbitrarily"))); |
| 940 CX_TEST_ASSERT(ctx.pos == 3); |
940 CX_TEST_ASSERT(ctx.pos == 3); |
| 941 CX_TEST_ASSERT(ctx.next_pos == 15); |
941 CX_TEST_ASSERT(ctx.next_pos == 15); |
| 942 CX_TEST_ASSERT(ctx.delim_pos == 14); |
942 CX_TEST_ASSERT(ctx.delim_pos == 14); |
| 943 CX_TEST_ASSERT(ctx.found == 2); |
943 CX_TEST_ASSERT(ctx.found == 2); |
| 944 cx_strupper(tok); |
944 cx_strupper(tok); |
| 945 |
945 |
| 946 ret = cx_strtok_next_m(&ctx, &tok); |
946 ret = cx_strtok_next_m(&ctx, &tok); |
| 947 CX_TEST_ASSERT(ret); |
947 CX_TEST_ASSERT(ret); |
| 948 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR(""))); |
948 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str(""))); |
| 949 CX_TEST_ASSERT(ctx.pos == 15); |
949 CX_TEST_ASSERT(ctx.pos == 15); |
| 950 CX_TEST_ASSERT(ctx.next_pos == 17); |
950 CX_TEST_ASSERT(ctx.next_pos == 17); |
| 951 CX_TEST_ASSERT(ctx.delim_pos == 15); |
951 CX_TEST_ASSERT(ctx.delim_pos == 15); |
| 952 CX_TEST_ASSERT(ctx.found == 3); |
952 CX_TEST_ASSERT(ctx.found == 3); |
| 953 cx_strupper(tok); |
953 cx_strupper(tok); |
| 954 |
954 |
| 955 ret = cx_strtok_next_m(&ctx, &tok); |
955 ret = cx_strtok_next_m(&ctx, &tok); |
| 956 CX_TEST_ASSERT(ret); |
956 CX_TEST_ASSERT(ret); |
| 957 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("separated"))); |
957 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("separated"))); |
| 958 CX_TEST_ASSERT(ctx.pos == 17); |
958 CX_TEST_ASSERT(ctx.pos == 17); |
| 959 CX_TEST_ASSERT(ctx.next_pos == 27); |
959 CX_TEST_ASSERT(ctx.next_pos == 27); |
| 960 CX_TEST_ASSERT(ctx.delim_pos == 26); |
960 CX_TEST_ASSERT(ctx.delim_pos == 26); |
| 961 CX_TEST_ASSERT(ctx.found == 4); |
961 CX_TEST_ASSERT(ctx.found == 4); |
| 962 cx_strupper(tok); |
962 cx_strupper(tok); |
| 963 |
963 |
| 964 ret = cx_strtok_next_m(&ctx, &tok); |
964 ret = cx_strtok_next_m(&ctx, &tok); |
| 965 CX_TEST_ASSERT(ret); |
965 CX_TEST_ASSERT(ret); |
| 966 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), CX_STR("string"))); |
966 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("string"))); |
| 967 CX_TEST_ASSERT(ctx.pos == 27); |
967 CX_TEST_ASSERT(ctx.pos == 27); |
| 968 CX_TEST_ASSERT(ctx.next_pos == 33); |
968 CX_TEST_ASSERT(ctx.next_pos == 33); |
| 969 CX_TEST_ASSERT(ctx.delim_pos == 33); |
969 CX_TEST_ASSERT(ctx.delim_pos == 33); |
| 970 CX_TEST_ASSERT(ctx.found == 5); |
970 CX_TEST_ASSERT(ctx.found == 5); |
| 971 cx_strupper(tok); |
971 cx_strupper(tok); |