Add tests for find and rfind

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

View File

@@ -78,26 +78,26 @@ TestFuncResult test_str8_buf(void) {
TestFuncResult test_str8_get_index_within_bounds(void) {
bool result;
Str8 s1 = wapp_str8_lit("Hello world");
result = wapp_str8_get(&s1, 4) == 'o';
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");
result = result && wapp_str8_get(&s2, 0) == 'D';
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");
result = result && wapp_str8_get(&s3, 13) == ' ';
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");
result = result && wapp_str8_get(&s4, 20) == 'n';
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");
result = result && wapp_str8_get(&s5, 11) == ',';
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");
result = result && wapp_str8_get(&s6, 25) == 'y';
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");
result = result && wapp_str8_get(&s7, 16) == 's';
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);
}