Implement read-only string literals

This commit is contained in:
2025-02-09 14:29:54 +00:00
parent 7657ad1b58
commit bbf38499ca
4 changed files with 48 additions and 15 deletions

View File

@@ -7,25 +7,52 @@ TestFuncResult test_str8_lit(void) {
bool result;
Str8 s1 = wapp_str8_lit("Hello world");
result = s1.capacity == 11 && s1.capacity == s1.size;
result = s1.capacity == 22 && s1.capacity != s1.size;
Str8 s2 = wapp_str8_lit("Different strokes for different folks");
result = result && s2.capacity == 37 && s2.capacity == s2.size;
result = result && s2.capacity == 74 && s2.capacity != s2.size;
Str8 s3 = wapp_str8_lit("Discretion is the better part of valour");
result = result && s3.capacity == 39 && s3.capacity == s3.size;
result = result && s3.capacity == 78 && s3.capacity != s3.size;
Str8 s4 = wapp_str8_lit("Distance lends enchantment to the view");
result = result && s4.capacity == 38 && s4.capacity == s4.size;
result = result && s4.capacity == 76 && s4.capacity != s4.size;
Str8 s5 = wapp_str8_lit("Do as I say, not as I do");
result = result && s5.capacity == 24 && s5.capacity == s5.size;
result = result && s5.capacity == 48 && s5.capacity != s5.size;
Str8 s6 = wapp_str8_lit("Do as you would be done by");
result = result && s6.capacity == 26 && s6.capacity == s6.size;
result = result && s6.capacity == 52 && s6.capacity != s6.size;
Str8 s7 = wapp_str8_lit("Do unto others as you would have them do to you");
result = result && s7.capacity == 47 && s7.capacity == s7.size;
result = result && s7.capacity == 94 && s7.capacity != s7.size;
return wapp_tester_result(result);
}
TestFuncResult test_str8_lit_ro(void) {
bool result;
Str8RO s1 = wapp_str8_lit_ro("Hello world");
result = s1.capacity == 11 && s1.capacity == s1.size;
Str8RO s2 = wapp_str8_lit_ro("Different strokes for different folks");
result = result && s2.capacity == 37 && s2.capacity == s2.size;
Str8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour");
result = result && s3.capacity == 39 && s3.capacity == s3.size;
Str8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view");
result = result && s4.capacity == 38 && s4.capacity == s4.size;
Str8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do");
result = result && s5.capacity == 24 && s5.capacity == s5.size;
Str8RO s6 = wapp_str8_lit_ro("Do as you would be done by");
result = result && s6.capacity == 26 && s6.capacity == s6.size;
Str8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you");
result = result && s7.capacity == 47 && s7.capacity == s7.size;
return wapp_tester_result(result);
}

View File

@@ -8,6 +8,7 @@ BEGIN_C_LINKAGE
#endif // __cplusplus
TestFuncResult test_str8_lit(void);
TestFuncResult test_str8_lit_ro(void);
TestFuncResult test_str8_buf(void);
TestFuncResult test_str8_get_index_within_bounds(void);
TestFuncResult test_str8_get_index_out_of_bounds(void);