tests/test_string.c

changeset 1668
3ffdfe1776b4
parent 1667
608cc0b25352
child 1671
cf19b7820ff0
equal deleted inserted replaced
1667:608cc0b25352 1668:3ffdfe1776b4
215 CX_TEST_ASSERT(0 == cx_strcmp(sub, cx_str("string"))); 215 CX_TEST_ASSERT(0 == cx_strcmp(sub, cx_str("string")));
216 216
217 // just for coverage, call the _m variant 217 // just for coverage, call the _m variant
218 cxmutstr m = cx_strsubs_m(cx_mutstrn(NULL, 0), 0); 218 cxmutstr m = cx_strsubs_m(cx_mutstrn(NULL, 0), 0);
219 CX_TEST_ASSERT(0 == cx_strcmp(m, "")); 219 CX_TEST_ASSERT(0 == cx_strcmp(m, ""));
220 }
221 }
222
223 CX_TEST(test_strat) {
224 cxstring str = cx_str("Hello, World!");
225
226 CX_TEST_DO {
227 // the entire string
228 for (size_t i = 0; i < str.length; i++) {
229 CX_TEST_ASSERT(cx_strat(str, i) == str.ptr[i]);
230 }
231 // the entire string backwards
232 for (off_t i = 1; i <= (off_t) str.length; i++) {
233 CX_TEST_ASSERT(cx_strat(str, -i) == str.ptr[str.length-i]);
234 }
235 // out of bounds (positive)
236 CX_TEST_ASSERT(cx_strat(str, 12) == '!');
237 CX_TEST_ASSERT(cx_strat(str, 13) == '\0');
238 CX_TEST_ASSERT(cx_strat(str, 14) == '\0');
239 CX_TEST_ASSERT(cx_strat(str, 651273) == '\0');
240 // out of bounds (negative)
241 CX_TEST_ASSERT(cx_strat(str, -13) == 'H');
242 CX_TEST_ASSERT(cx_strat(str, -14) == '\0');
243 CX_TEST_ASSERT(cx_strat(str, -15) == '\0');
244 CX_TEST_ASSERT(cx_strat(str, -651273) == '\0');
220 } 245 }
221 } 246 }
222 247
223 CX_TEST(test_strchr) { 248 CX_TEST(test_strchr) {
224 cxstring str = cx_str("I will find you - and I will kill you"); 249 cxstring str = cx_str("I will find you - and I will kill you");
1509 cx_test_register(suite, test_strdup); 1534 cx_test_register(suite, test_strdup);
1510 cx_test_register(suite, test_strdup_shortened); 1535 cx_test_register(suite, test_strdup_shortened);
1511 cx_test_register(suite, test_strcpy); 1536 cx_test_register(suite, test_strcpy);
1512 cx_test_register(suite, test_strlen); 1537 cx_test_register(suite, test_strlen);
1513 cx_test_register(suite, test_strsubs); 1538 cx_test_register(suite, test_strsubs);
1539 cx_test_register(suite, test_strat);
1514 cx_test_register(suite, test_strchr); 1540 cx_test_register(suite, test_strchr);
1515 cx_test_register(suite, test_strrchr); 1541 cx_test_register(suite, test_strrchr);
1516 cx_test_register(suite, test_strstr); 1542 cx_test_register(suite, test_strstr);
1517 cx_test_register(suite, test_strcmp); 1543 cx_test_register(suite, test_strcmp);
1518 cx_test_register(suite, test_strcasecmp); 1544 cx_test_register(suite, test_strcasecmp);

mercurial