474 UCX_TEST_ASSERT(sstrcasesuffix(str, S("FIX")), "suffix false negative"); |
474 UCX_TEST_ASSERT(sstrcasesuffix(str, S("FIX")), "suffix false negative"); |
475 UCX_TEST_ASSERT(!sstrcasesuffix(str, S("fox")), "suffix false positive"); |
475 UCX_TEST_ASSERT(!sstrcasesuffix(str, S("fox")), "suffix false positive"); |
476 |
476 |
477 UCX_TEST_END |
477 UCX_TEST_END |
478 } |
478 } |
|
479 |
|
480 UCX_TEST(test_sstrreplace) { |
|
481 |
|
482 sstr_t str = ST("test ababab string aba"); |
|
483 sstr_t longstr = ST("xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd"); |
|
484 sstr_t notrail = ST("test abab"); |
|
485 |
|
486 sstr_t repl = sstrreplace(str, SC("abab"), SC("muchlonger")); |
|
487 sstr_t expected = ST("test muchlongerab string aba"); |
|
488 |
|
489 sstr_t repln = sstrreplacen(str, SC("ab"), SC("c"), 2); |
|
490 sstr_t expectedn = ST("test ccab string aba"); |
|
491 |
|
492 sstr_t longrepl = sstrreplace(longstr, SC("a"), SC("z")); |
|
493 sstr_t longexpect = ST("xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzcd"); |
|
494 |
|
495 sstr_t replnotrail = sstrreplace(notrail, SC("ab"), SC("z")); |
|
496 sstr_t notrailexpect = ST("test zz"); |
|
497 |
|
498 UCX_TEST_BEGIN |
|
499 |
|
500 UCX_TEST_ASSERT(repl.ptr != str.ptr, "result string is not fresh"); |
|
501 UCX_TEST_ASSERT(!sstrcmp(repl, expected), "incorrect replacement"); |
|
502 |
|
503 UCX_TEST_ASSERT(repln.ptr != str.ptr, "result string is not fresh"); |
|
504 UCX_TEST_ASSERT(!sstrcmp(repln, expectedn), "incorrect replacement"); |
|
505 |
|
506 UCX_TEST_ASSERT(!sstrcmp(longrepl, longexpect), |
|
507 "incorrect handling of long strings"); |
|
508 |
|
509 UCX_TEST_ASSERT(!sstrcmp(replnotrail, notrailexpect), |
|
510 "no trail replacement fails"); |
|
511 |
|
512 UCX_TEST_END |
|
513 |
|
514 free(repl.ptr); |
|
515 free(repln.ptr); |
|
516 } |