Add tests for find and rfind

This commit is contained in:
Abdelrahman Said 2025-02-09 16:35:42 +00:00
parent 093d0daf6f
commit 4642361969
3 changed files with 72 additions and 21 deletions

View File

@ -78,25 +78,25 @@ TestFuncResult test_str8_buf(void) {
TestFuncResult test_str8_get_index_within_bounds(void) {
bool result;
Str8 s1 = wapp_str8_lit("Hello world");
Str8RO s1 = wapp_str8_lit_ro("Hello world");
result = wapp_str8_get(&s1, 4) == 'o';
Str8 s2 = wapp_str8_lit("Different strokes for different folks");
Str8RO s2 = wapp_str8_lit_ro("Different strokes for different folks");
result = result && wapp_str8_get(&s2, 0) == 'D';
Str8 s3 = wapp_str8_lit("Discretion is the better part of valour");
Str8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour");
result = result && wapp_str8_get(&s3, 13) == ' ';
Str8 s4 = wapp_str8_lit("Distance lends enchantment to the view");
Str8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view");
result = result && wapp_str8_get(&s4, 20) == 'n';
Str8 s5 = wapp_str8_lit("Do as I say, not as I do");
Str8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do");
result = result && wapp_str8_get(&s5, 11) == ',';
Str8 s6 = wapp_str8_lit("Do as you would be done by");
Str8RO s6 = wapp_str8_lit_ro("Do as you would be done by");
result = result && wapp_str8_get(&s6, 25) == 'y';
Str8 s7 = wapp_str8_lit("Do unto others as you would have them do to you");
Str8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you");
result = result && wapp_str8_get(&s7, 16) == 's';
return wapp_tester_result(result);
@ -141,3 +141,35 @@ TestFuncResult test_str8_set(void) {
return wapp_tester_result(result);
}
TestFuncResult test_str8_find(void) {
bool result = true;
Str8RO s = wapp_str8_lit("Do as I say, not as I do");
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("d")) != -1);
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("not")) != -1);
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("as I say")) != -1);
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("f")) == -1);
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("hello")) == -1);
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("not sa I")) == -1);
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("Do unto others as you would have them do to you")) == -1);
return wapp_tester_result(result);
}
TestFuncResult test_str8_rfind(void) {
bool result = true;
Str8RO s = wapp_str8_lit("Do as I say, not as I do");
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("d")) != -1);
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("not")) != -1);
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("as I say")) != -1);
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("f")) == -1);
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("hello")) == -1);
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("not sa I")) == -1);
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("Do unto others as you would have them do to you")) == -1);
return wapp_tester_result(result);
}

View File

@ -13,6 +13,8 @@ TestFuncResult test_str8_buf(void);
TestFuncResult test_str8_get_index_within_bounds(void);
TestFuncResult test_str8_get_index_out_of_bounds(void);
TestFuncResult test_str8_set(void);
TestFuncResult test_str8_find(void);
TestFuncResult test_str8_rfind(void);
#ifdef __cplusplus
END_C_LINKAGE

View File

@ -9,13 +9,30 @@
int main(void) {
wapp_tester_run_tests(test_arena_allocator, test_arena_init, test_arena_init_succeeds_when_reserving_very_large_size,
test_str8_lit, test_str8_lit_ro, test_str8_buf, test_str8_get_index_within_bounds,
test_str8_get_index_out_of_bounds, test_str8_set, test_cpath_join_path, test_cpath_dirname,
test_cpath_dirup, test_arena_alloc_succeeds_when_within_capacity, test_arena_alloc_fails_when_over_capacity,
test_arena_realloc_bigger_size, test_arena_realloc_smaller_size, test_arena_clear,
test_arena_destroy, test_commander_cmd_success, test_commander_cmd_failure,
test_commander_cmd_out_buf_success, test_commander_cmd_out_buf_failure);
wapp_tester_run_tests(test_arena_allocator,
test_arena_init,
test_arena_init_succeeds_when_reserving_very_large_size,
test_str8_lit,
test_str8_lit_ro,
test_str8_buf,
test_str8_get_index_within_bounds,
test_str8_get_index_out_of_bounds,
test_str8_set,
test_str8_find,
test_str8_rfind,
test_cpath_join_path,
test_cpath_dirname,
test_cpath_dirup,
test_arena_alloc_succeeds_when_within_capacity,
test_arena_alloc_fails_when_over_capacity,
test_arena_realloc_bigger_size,
test_arena_realloc_smaller_size,
test_arena_clear,
test_arena_destroy,
test_commander_cmd_success,
test_commander_cmd_failure,
test_commander_cmd_out_buf_success,
test_commander_cmd_out_buf_failure);
return EXIT_SUCCESS;
}