Add str8_copy functions

This commit is contained in:
2025-02-16 17:34:48 +00:00
parent 6078e54087
commit 0569fca193
5 changed files with 66 additions and 0 deletions

View File

@@ -278,6 +278,41 @@ TestFuncResult test_str8_concat_capped(void) {
return wapp_tester_result(result);
}
TestFuncResult test_str8_copy_cstr_capped(void) {
bool result;
Str8 buf = wapp_str8_buf(32);
const char *src1 = "Hello world";
const char *src2 = "Hello world from the Wizard Apprentice standard library";
Str8RO src1_cp = wapp_str8_lit_ro("Hello world");
Str8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr");
wapp_str8_copy_cstr_capped(&buf, src1);
result = buf.size == src1_cp.size && wapp_str8_equal(&buf, &src1_cp);
wapp_str8_copy_cstr_capped(&buf, src2);
result = result && buf.size == src2_cp.size && buf.size == buf.capacity && wapp_str8_equal(&buf, &src2_cp);
return wapp_tester_result(result);
}
TestFuncResult test_str8_copy_str8_capped(void) {
bool result;
Str8 buf = wapp_str8_buf(32);
Str8RO src1 = wapp_str8_lit_ro("Hello world");
Str8RO src2 = wapp_str8_lit_ro("Hello world from the Wizard Apprentice standard library");
Str8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr");
wapp_str8_copy_str8_capped(&buf, &src1);
result = buf.size == src1.size && wapp_str8_equal(&buf, &src1);
wapp_str8_copy_str8_capped(&buf, &src2);
result = result && buf.size < src2.size && buf.size == buf.capacity && wapp_str8_equal(&buf, &src2_cp);
return wapp_tester_result(result);
}
TestFuncResult test_str8_find(void) {
bool result;
Str8RO s = wapp_str8_lit("Do as I say, not as I do");