test/test_string.cpp

changeset 598
70b7456b5b12
parent 597
8b48126671cf
child 628
1e2be40f0cb5
equal deleted inserted replaced
597:8b48126671cf 598:70b7456b5b12
540 EXPECT_TRUE(cx_strcasesuffix(str, cx_str("FIX"))); 540 EXPECT_TRUE(cx_strcasesuffix(str, cx_str("FIX")));
541 EXPECT_FALSE(cx_strcasesuffix(str, cx_str("fox"))); 541 EXPECT_FALSE(cx_strcasesuffix(str, cx_str("fox")));
542 } 542 }
543 543
544 TEST(String, strreplace) { 544 TEST(String, strreplace) {
545 CxTestingAllocator alloc;
545 cxstring str = CX_STR("test ababab string aba"); 546 cxstring str = CX_STR("test ababab string aba");
546 cxstring longstr = CX_STR( 547 cxstring longstr = CX_STR(
547 "xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd"); 548 "xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd");
548 cxstring notrail = CX_STR("test abab"); 549 cxstring notrail = CX_STR("test abab");
549 cxstring empty = CX_STR(""); 550 cxstring empty = CX_STR("");
582 auto an9expected = "xxxxxxxxxa"; 583 auto an9expected = "xxxxxxxxxa";
583 584
584 cxmutstr replan10 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 10); 585 cxmutstr replan10 = cx_strreplacen(astr, cx_str("a"), cx_str("x"), 10);
585 auto an10expected = "xxxxxxxxxx"; 586 auto an10expected = "xxxxxxxxxx";
586 587
587 cxmutstr replcs1 = cx_strreplace(csstr, cx_str("AB"), cx_str("*")); 588 cxmutstr repl1_a = cx_strreplace_a(&alloc, csstr, cx_str("AB"), cx_str("*"));
588 auto cs1expected = "test * ab TEST xyz"; 589 auto expeced1_a = "test * ab TEST xyz";
589 590
590 cxmutstr replcs2 = cx_strreplace(csstr, cx_str("test"), cx_str("TEST")); 591 cxmutstr repl2_a = cx_strreplace_a(&alloc, csstr, cx_str("test"), cx_str("TEST"));
591 auto cs2expected = "TEST AB ab TEST xyz"; 592 auto expected2_a = "TEST AB ab TEST xyz";
592 593
593 594
594 EXPECT_NE(repl.ptr, str.ptr); 595 EXPECT_NE(repl.ptr, str.ptr);
595 EXPECT_ZERO_TERMINATED(repl); 596 EXPECT_ZERO_TERMINATED(repl);
596 EXPECT_STREQ(repl.ptr, expected); 597 EXPECT_STREQ(repl.ptr, expected);
614 EXPECT_STREQ(replan4.ptr, an4expected); 615 EXPECT_STREQ(replan4.ptr, an4expected);
615 EXPECT_ZERO_TERMINATED(replan9); 616 EXPECT_ZERO_TERMINATED(replan9);
616 EXPECT_STREQ(replan9.ptr, an9expected); 617 EXPECT_STREQ(replan9.ptr, an9expected);
617 EXPECT_ZERO_TERMINATED(replan10); 618 EXPECT_ZERO_TERMINATED(replan10);
618 EXPECT_STREQ(replan10.ptr, an10expected); 619 EXPECT_STREQ(replan10.ptr, an10expected);
619 EXPECT_ZERO_TERMINATED(replcs1); 620 EXPECT_ZERO_TERMINATED(repl1_a);
620 EXPECT_STREQ(replcs1.ptr, cs1expected); 621 EXPECT_STREQ(repl1_a.ptr, expeced1_a);
621 EXPECT_ZERO_TERMINATED(replcs2); 622 EXPECT_ZERO_TERMINATED(repl2_a);
622 EXPECT_STREQ(replcs2.ptr, cs2expected); 623 EXPECT_STREQ(repl2_a.ptr, expected2_a);
623 624
624 cx_strfree(&repl); 625 cx_strfree(&repl);
625 cx_strfree(&repln); 626 cx_strfree(&repln);
626 cx_strfree(&longrepl); 627 cx_strfree(&longrepl);
627 cx_strfree(&replnotrail); 628 cx_strfree(&replnotrail);
631 cx_strfree(&replpre); 632 cx_strfree(&replpre);
632 cx_strfree(&replan1); 633 cx_strfree(&replan1);
633 cx_strfree(&replan4); 634 cx_strfree(&replan4);
634 cx_strfree(&replan9); 635 cx_strfree(&replan9);
635 cx_strfree(&replan10); 636 cx_strfree(&replan10);
636 cx_strfree(&replcs1); 637
637 cx_strfree(&replcs2); 638 cx_strfree_a(&alloc, &repl1_a);
639 cx_strfree_a(&alloc, &repl2_a);
640 EXPECT_TRUE(alloc.verify());
638 } 641 }
639 642
640 TEST(String, strupper) { 643 TEST(String, strupper) {
641 cxmutstr str = cx_strdup(cx_str("thIs 1s @ Te$t")); 644 cxmutstr str = cx_strdup(cx_str("thIs 1s @ Te$t"));
642 cx_strupper(str); 645 cx_strupper(str);

mercurial