tests/test_string.c

changeset 890
54565fd74e74
parent 809
b7e2e1d7ed22
child 926
8fdd8d78c14b
equal deleted inserted replaced
889:f549fd9fbd8f 890:54565fd74e74
620 cxstring empty = CX_STR(""); 620 cxstring empty = CX_STR("");
621 cxstring astr = CX_STR("aaaaaaaaaa"); 621 cxstring astr = CX_STR("aaaaaaaaaa");
622 cxstring csstr = CX_STR("test AB ab TEST xyz"); 622 cxstring csstr = CX_STR("test AB ab TEST xyz");
623 623
624 cxmutstr repl = cx_strreplace(str, CX_STR("abab"), CX_STR("muchlonger")); 624 cxmutstr repl = cx_strreplace(str, CX_STR("abab"), CX_STR("muchlonger"));
625 char const *expected = "test muchlongerab string aba"; 625 const char *expected = "test muchlongerab string aba";
626 626
627 cxmutstr repln = cx_strreplacen(str, CX_STR("ab"), CX_STR("c"), 2); 627 cxmutstr repln = cx_strreplacen(str, CX_STR("ab"), CX_STR("c"), 2);
628 char const *expectedn = "test ccab string aba"; 628 const char *expectedn = "test ccab string aba";
629 629
630 cxmutstr longrepl = cx_strreplace(longstr, CX_STR("a"), CX_STR("z")); 630 cxmutstr longrepl = cx_strreplace(longstr, CX_STR("a"), CX_STR("z"));
631 char const *longexpect = "xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzcd"; 631 const char *longexpect = "xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzcd";
632 632
633 cxmutstr replnotrail = cx_strreplace(notrail, CX_STR("ab"), CX_STR("z")); 633 cxmutstr replnotrail = cx_strreplace(notrail, CX_STR("ab"), CX_STR("z"));
634 char const *notrailexpect = "test zz"; 634 const char *notrailexpect = "test zz";
635 635
636 cxmutstr repleq = cx_strreplace(str, str, CX_STR("hello")); 636 cxmutstr repleq = cx_strreplace(str, str, CX_STR("hello"));
637 char const *eqexpect = "hello"; 637 const char *eqexpect = "hello";
638 638
639 cxmutstr replempty1 = cx_strreplace(empty, CX_STR("ab"), CX_STR("c")); // expect: empty 639 cxmutstr replempty1 = cx_strreplace(empty, CX_STR("ab"), CX_STR("c")); // expect: empty
640 cxmutstr replempty2 = cx_strreplace(str, CX_STR("abab"), empty); 640 cxmutstr replempty2 = cx_strreplace(str, CX_STR("abab"), empty);
641 char const *emptyexpect2 = "test ab string aba"; 641 const char *emptyexpect2 = "test ab string aba";
642 642
643 cxmutstr replpre = cx_strreplace(str, CX_STR("test "), CX_STR("TEST ")); 643 cxmutstr replpre = cx_strreplace(str, CX_STR("test "), CX_STR("TEST "));
644 char const *preexpected = "TEST ababab string aba"; 644 const char *preexpected = "TEST ababab string aba";
645 645
646 cxmutstr replan1 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 1); 646 cxmutstr replan1 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 1);
647 char const *an1expected = "xaaaaaaaaa"; 647 const char *an1expected = "xaaaaaaaaa";
648 648
649 cxmutstr replan4 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 4); 649 cxmutstr replan4 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 4);
650 char const *an4expected = "xxxxaaaaaa"; 650 const char *an4expected = "xxxxaaaaaa";
651 651
652 cxmutstr replan9 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 9); 652 cxmutstr replan9 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 9);
653 char const *an9expected = "xxxxxxxxxa"; 653 const char *an9expected = "xxxxxxxxxa";
654 654
655 cxmutstr replan10 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 10); 655 cxmutstr replan10 = cx_strreplacen(astr, CX_STR("a"), CX_STR("x"), 10);
656 char const *an10expected = "xxxxxxxxxx"; 656 const char *an10expected = "xxxxxxxxxx";
657 657
658 CX_TEST_DO { 658 CX_TEST_DO {
659 cxmutstr repl1_a = cx_strreplace_a(alloc, csstr, CX_STR("AB"), CX_STR("*")); 659 cxmutstr repl1_a = cx_strreplace_a(alloc, csstr, CX_STR("AB"), CX_STR("*"));
660 char const *expeced1_a = "test * ab TEST xyz"; 660 const char *expeced1_a = "test * ab TEST xyz";
661 661
662 cxmutstr repl2_a = cx_strreplace_a(alloc, csstr, CX_STR("test"), CX_STR("TEST")); 662 cxmutstr repl2_a = cx_strreplace_a(alloc, csstr, CX_STR("test"), CX_STR("TEST"));
663 char const *expected2_a = "TEST AB ab TEST xyz"; 663 const char *expected2_a = "TEST AB ab TEST xyz";
664 664
665 CX_TEST_ASSERT(repl.ptr != str.ptr); 665 CX_TEST_ASSERT(repl.ptr != str.ptr);
666 ASSERT_ZERO_TERMINATED(repl); 666 ASSERT_ZERO_TERMINATED(repl);
667 CX_TEST_ASSERT(0 == strcmp(repl.ptr, expected)); 667 CX_TEST_ASSERT(0 == strcmp(repl.ptr, expected));
668 ASSERT_ZERO_TERMINATED(repln); 668 ASSERT_ZERO_TERMINATED(repln);

mercurial