741 cx_strfree(&replan9); |
741 cx_strfree(&replan9); |
742 cx_strfree(&replan10); |
742 cx_strfree(&replan10); |
743 cx_testing_allocator_destroy(&talloc); |
743 cx_testing_allocator_destroy(&talloc); |
744 } |
744 } |
745 |
745 |
746 CX_TEST(test_strupper) { |
|
747 cxmutstr str = cx_strdup(cx_str("thIs 1s @ Te$t")); |
|
748 CX_TEST_DO { |
|
749 cx_strupper(str); |
|
750 CX_TEST_ASSERT(0 == strcmp(str.ptr, "THIS 1S @ TE$T")); |
|
751 } |
|
752 cx_strfree(&str); |
|
753 } |
|
754 |
|
755 CX_TEST(test_strlower) { |
|
756 cxmutstr str = cx_strdup(cx_str("thIs 1s @ Te$t")); |
|
757 CX_TEST_DO { |
|
758 cx_strlower(str); |
|
759 CX_TEST_ASSERT(0 == strcmp(str.ptr, "this 1s @ te$t")); |
|
760 } |
|
761 cx_strfree(&str); |
|
762 } |
|
763 |
|
764 CX_TEST(test_strtok) { |
746 CX_TEST(test_strtok) { |
765 cxstring str = CX_STR("a,comma,separated,string"); |
747 cxstring str = CX_STR("a,comma,separated,string"); |
766 cxstring delim = CX_STR(","); |
748 cxstring delim = CX_STR(","); |
767 CX_TEST_DO { |
749 CX_TEST_DO { |
768 CxStrtokCtx ctx = cx_strtok(str, delim, 3); |
750 CxStrtokCtx ctx = cx_strtok(str, delim, 3); |
894 CX_TEST_ASSERT(ctx.delim_pos == 40); |
876 CX_TEST_ASSERT(ctx.delim_pos == 40); |
895 CX_TEST_ASSERT(ctx.found == 5); |
877 CX_TEST_ASSERT(ctx.found == 5); |
896 } |
878 } |
897 } |
879 } |
898 |
880 |
|
881 static void test_toupper(cxmutstr string) { |
|
882 for (size_t i = 0; i < string.length; i++) { |
|
883 if ((unsigned int)(string.ptr[i] - 'a') < 26u) { |
|
884 string.ptr[i] += 'A' - 'a'; |
|
885 } |
|
886 } |
|
887 } |
|
888 |
899 CX_TEST(test_strtok_next_advanced) { |
889 CX_TEST(test_strtok_next_advanced) { |
900 cxmutstr str = cx_strdup(cx_str("an,arbitrarily;||separated;string")); |
890 cxmutstr str = cx_strdup(cx_str("an,arbitrarily;||separated;string")); |
901 cxstring delim = CX_STR(","); |
891 cxstring delim = CX_STR(","); |
902 cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; |
892 cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; |
903 CX_TEST_DO { |
893 CX_TEST_DO { |
911 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("an"))); |
901 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("an"))); |
912 CX_TEST_ASSERT(ctx.pos == 0); |
902 CX_TEST_ASSERT(ctx.pos == 0); |
913 CX_TEST_ASSERT(ctx.next_pos == 3); |
903 CX_TEST_ASSERT(ctx.next_pos == 3); |
914 CX_TEST_ASSERT(ctx.delim_pos == 2); |
904 CX_TEST_ASSERT(ctx.delim_pos == 2); |
915 CX_TEST_ASSERT(ctx.found == 1); |
905 CX_TEST_ASSERT(ctx.found == 1); |
916 cx_strupper(tok); |
906 test_toupper(tok); |
917 |
907 |
918 ret = cx_strtok_next_m(&ctx, &tok); |
908 ret = cx_strtok_next_m(&ctx, &tok); |
919 CX_TEST_ASSERT(ret); |
909 CX_TEST_ASSERT(ret); |
920 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("arbitrarily"))); |
910 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("arbitrarily"))); |
921 CX_TEST_ASSERT(ctx.pos == 3); |
911 CX_TEST_ASSERT(ctx.pos == 3); |
922 CX_TEST_ASSERT(ctx.next_pos == 15); |
912 CX_TEST_ASSERT(ctx.next_pos == 15); |
923 CX_TEST_ASSERT(ctx.delim_pos == 14); |
913 CX_TEST_ASSERT(ctx.delim_pos == 14); |
924 CX_TEST_ASSERT(ctx.found == 2); |
914 CX_TEST_ASSERT(ctx.found == 2); |
925 cx_strupper(tok); |
915 test_toupper(tok); |
926 |
916 |
927 ret = cx_strtok_next_m(&ctx, &tok); |
917 ret = cx_strtok_next_m(&ctx, &tok); |
928 CX_TEST_ASSERT(ret); |
918 CX_TEST_ASSERT(ret); |
929 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str(""))); |
919 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str(""))); |
930 CX_TEST_ASSERT(ctx.pos == 15); |
920 CX_TEST_ASSERT(ctx.pos == 15); |
931 CX_TEST_ASSERT(ctx.next_pos == 17); |
921 CX_TEST_ASSERT(ctx.next_pos == 17); |
932 CX_TEST_ASSERT(ctx.delim_pos == 15); |
922 CX_TEST_ASSERT(ctx.delim_pos == 15); |
933 CX_TEST_ASSERT(ctx.found == 3); |
923 CX_TEST_ASSERT(ctx.found == 3); |
934 cx_strupper(tok); |
924 test_toupper(tok); |
935 |
925 |
936 ret = cx_strtok_next_m(&ctx, &tok); |
926 ret = cx_strtok_next_m(&ctx, &tok); |
937 CX_TEST_ASSERT(ret); |
927 CX_TEST_ASSERT(ret); |
938 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("separated"))); |
928 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("separated"))); |
939 CX_TEST_ASSERT(ctx.pos == 17); |
929 CX_TEST_ASSERT(ctx.pos == 17); |
940 CX_TEST_ASSERT(ctx.next_pos == 27); |
930 CX_TEST_ASSERT(ctx.next_pos == 27); |
941 CX_TEST_ASSERT(ctx.delim_pos == 26); |
931 CX_TEST_ASSERT(ctx.delim_pos == 26); |
942 CX_TEST_ASSERT(ctx.found == 4); |
932 CX_TEST_ASSERT(ctx.found == 4); |
943 cx_strupper(tok); |
933 test_toupper(tok); |
944 |
934 |
945 ret = cx_strtok_next_m(&ctx, &tok); |
935 ret = cx_strtok_next_m(&ctx, &tok); |
946 CX_TEST_ASSERT(ret); |
936 CX_TEST_ASSERT(ret); |
947 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("string"))); |
937 CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("string"))); |
948 CX_TEST_ASSERT(ctx.pos == 27); |
938 CX_TEST_ASSERT(ctx.pos == 27); |
949 CX_TEST_ASSERT(ctx.next_pos == 33); |
939 CX_TEST_ASSERT(ctx.next_pos == 33); |
950 CX_TEST_ASSERT(ctx.delim_pos == 33); |
940 CX_TEST_ASSERT(ctx.delim_pos == 33); |
951 CX_TEST_ASSERT(ctx.found == 5); |
941 CX_TEST_ASSERT(ctx.found == 5); |
952 cx_strupper(tok); |
942 test_toupper(tok); |
953 |
943 |
954 ret = cx_strtok_next_m(&ctx, &tok); |
944 ret = cx_strtok_next_m(&ctx, &tok); |
955 CX_TEST_ASSERT(!ret); |
945 CX_TEST_ASSERT(!ret); |
956 CX_TEST_ASSERT(ctx.pos == 27); |
946 CX_TEST_ASSERT(ctx.pos == 27); |
957 CX_TEST_ASSERT(ctx.next_pos == 33); |
947 CX_TEST_ASSERT(ctx.next_pos == 33); |
1274 cx_test_register(suite, test_strprefix); |
1264 cx_test_register(suite, test_strprefix); |
1275 cx_test_register(suite, test_strsuffix); |
1265 cx_test_register(suite, test_strsuffix); |
1276 cx_test_register(suite, test_strcaseprefix); |
1266 cx_test_register(suite, test_strcaseprefix); |
1277 cx_test_register(suite, test_strcasesuffix); |
1267 cx_test_register(suite, test_strcasesuffix); |
1278 cx_test_register(suite, test_strreplace); |
1268 cx_test_register(suite, test_strreplace); |
1279 cx_test_register(suite, test_strupper); |
|
1280 cx_test_register(suite, test_strlower); |
|
1281 cx_test_register(suite, test_strtok); |
1269 cx_test_register(suite, test_strtok); |
1282 cx_test_register(suite, test_strtok_delim); |
1270 cx_test_register(suite, test_strtok_delim); |
1283 cx_test_register(suite, test_strtok_next_easy); |
1271 cx_test_register(suite, test_strtok_next_easy); |
1284 cx_test_register(suite, test_strtok_next_unlimited); |
1272 cx_test_register(suite, test_strtok_next_unlimited); |
1285 cx_test_register(suite, test_strtok_next_advanced); |
1273 cx_test_register(suite, test_strtok_next_advanced); |