tests/test_string.c

changeset 1127
1fd31909a3f8
parent 1126
20c9212b3a47
equal deleted inserted replaced
1126:20c9212b3a47 1127:1fd31909a3f8
777 CX_TEST_ASSERT(ctx.delim_more == NULL); 777 CX_TEST_ASSERT(ctx.delim_more == NULL);
778 CX_TEST_ASSERT(ctx.delim_more_count == 0); 778 CX_TEST_ASSERT(ctx.delim_more_count == 0);
779 } 779 }
780 } 780 }
781 781
782 CX_TEST(test_strtok_m) {
783 cxmutstr str = cx_strdup(cx_str("a,comma,separated,string"));
784 cxstring delim = CX_STR(",");
785 CX_TEST_DO {
786 CxStrtokCtx ctx = cx_strtok_m(str, delim, 3);
787 CX_TEST_ASSERT(ctx.str.ptr == str.ptr);
788 CX_TEST_ASSERT(ctx.str.length == str.length);
789 CX_TEST_ASSERT(ctx.delim.ptr == delim.ptr);
790 CX_TEST_ASSERT(ctx.delim.length == delim.length);
791 CX_TEST_ASSERT(ctx.limit == 3);
792 CX_TEST_ASSERT(ctx.found == 0);
793 CX_TEST_ASSERT(ctx.pos == 0);
794 CX_TEST_ASSERT(ctx.next_pos == 0);
795 CX_TEST_ASSERT(ctx.delim_more == NULL);
796 CX_TEST_ASSERT(ctx.delim_more_count == 0);
797 }
798 cx_strfree(&str);
799 }
800
801 CX_TEST(test_strtok_delim) { 782 CX_TEST(test_strtok_delim) {
802 cxstring str = CX_STR("an,arbitrarily|separated;string"); 783 cxstring str = CX_STR("an,arbitrarily|separated;string");
803 cxstring delim = CX_STR(","); 784 cxstring delim = CX_STR(",");
804 cxstring delim_more[2] = {CX_STR("|"), CX_STR(";")}; 785 cxstring delim_more[2] = {CX_STR("|"), CX_STR(";")};
805 CX_TEST_DO { 786 CX_TEST_DO {
918 CX_TEST(test_strtok_next_advanced) { 899 CX_TEST(test_strtok_next_advanced) {
919 cxmutstr str = cx_strdup(cx_str("an,arbitrarily;||separated;string")); 900 cxmutstr str = cx_strdup(cx_str("an,arbitrarily;||separated;string"));
920 cxstring delim = CX_STR(","); 901 cxstring delim = CX_STR(",");
921 cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; 902 cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")};
922 CX_TEST_DO { 903 CX_TEST_DO {
923 CxStrtokCtx ctx = cx_strtok_m(str, delim, 10); 904 CxStrtokCtx ctx = cx_strtok(str, delim, 10);
924 cx_strtok_delim(&ctx, delim_more, 2); 905 cx_strtok_delim(&ctx, delim_more, 2);
925 bool ret; 906 bool ret;
926 cxmutstr tok; 907 cxmutstr tok;
927 908
928 ret = cx_strtok_next_m(&ctx, &tok); 909 ret = cx_strtok_next_m(&ctx, &tok);
1270 cx_test_register(suite, test_strcasesuffix); 1251 cx_test_register(suite, test_strcasesuffix);
1271 cx_test_register(suite, test_strreplace); 1252 cx_test_register(suite, test_strreplace);
1272 cx_test_register(suite, test_strupper); 1253 cx_test_register(suite, test_strupper);
1273 cx_test_register(suite, test_strlower); 1254 cx_test_register(suite, test_strlower);
1274 cx_test_register(suite, test_strtok); 1255 cx_test_register(suite, test_strtok);
1275 cx_test_register(suite, test_strtok_m);
1276 cx_test_register(suite, test_strtok_delim); 1256 cx_test_register(suite, test_strtok_delim);
1277 cx_test_register(suite, test_strtok_next_easy); 1257 cx_test_register(suite, test_strtok_next_easy);
1278 cx_test_register(suite, test_strtok_next_unlimited); 1258 cx_test_register(suite, test_strtok_next_unlimited);
1279 cx_test_register(suite, test_strtok_next_advanced); 1259 cx_test_register(suite, test_strtok_next_advanced);
1280 1260

mercurial