From e2b57d4aba3d5c510462a0b2c06bf74cb405a9d9 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Fri, 26 Jun 2026 16:18:46 +0100 Subject: [PATCH] Rename Str8 --- src/base/strings/str8/str8.c | 108 ++--- src/base/strings/str8/str8.h | 98 ++--- src/log/log.c | 26 +- src/os/cpath/cpath.c | 44 +- src/os/shell/commander/commander.c | 10 +- .../shell/termcolour/posix/termcolour_posix.c | 34 +- src/os/shell/termcolour/termcolour.c | 2 +- src/testing/tester/tester.c | 6 +- src/testing/tester/tester.h | 4 +- src/uuid/uuid.c | 2 +- src/uuid/uuid.h | 4 +- tests/array/test_str8_array.c | 6 +- tests/array/test_str8_array.cc | 10 +- tests/cpath/test_cpath.c | 122 +++--- tests/cpath/test_cpath.cc | 124 +++--- tests/file/test_file.c | 4 +- tests/file/test_file.cc | 4 +- tests/shell_commander/test_shell_commander.c | 30 +- tests/shell_commander/test_shell_commander.cc | 30 +- tests/str8/test_str8.c | 400 ++++++++--------- tests/str8/test_str8.cc | 402 +++++++++--------- tests/str8/test_str8_list.c | 132 +++--- tests/str8/test_str8_list.cc | 132 +++--- 23 files changed, 867 insertions(+), 867 deletions(-) diff --git a/src/base/strings/str8/str8.c b/src/base/strings/str8/str8.c index 6808a81..700956b 100644 --- a/src/base/strings/str8/str8.c +++ b/src/base/strings/str8/str8.c @@ -13,7 +13,7 @@ #define STR8_BUF_ALLOC_SIZE(CAPACITY) (sizeof(WpStr8) + sizeof(c8) * CAPACITY) -WpStr8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity) { +WpStr8 *wpStr8AllocBuf(const Allocator *allocator, u64 capacity) { wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); WpStr8 *str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity)); @@ -29,8 +29,8 @@ RETURN_STR8: return str; } -WpStr8 *wapp_str8_alloc_and_fill_buf(const Allocator *allocator, u64 capacity) { - WpStr8 *out = wapp_str8_alloc_buf(allocator, capacity); +WpStr8 *wpStr8AllocAndFillBuf(const Allocator *allocator, u64 capacity) { + WpStr8 *out = wpStr8AllocBuf(allocator, capacity); if (out) { memset(out->buf, 0, capacity); out->size = capacity; @@ -38,11 +38,11 @@ WpStr8 *wapp_str8_alloc_and_fill_buf(const Allocator *allocator, u64 capacity) { return out; } -WpStr8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str) { +WpStr8 *wpStr8AllocCstr(const Allocator *allocator, const char *str) { wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); u64 length = strlen(str); - WpStr8 *output = wapp_str8_alloc_buf(allocator, length * 2); + WpStr8 *output = wpStr8AllocBuf(allocator, length * 2); if (!output) { goto RETURN_ALLOC_CSTR; } @@ -54,10 +54,10 @@ RETURN_ALLOC_CSTR: return output; } -WpStr8 *wapp_str8_alloc_str8(const Allocator *allocator, WpStr8RO *str) { +WpStr8 *wpStr8AllocStr8(const Allocator *allocator, WpStr8RO *str) { wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); - WpStr8 *output = wapp_str8_alloc_buf(allocator, str->capacity); + WpStr8 *output = wpStr8AllocBuf(allocator, str->capacity); if (!output) { goto RETURN_ALLOC_STR8; } @@ -69,7 +69,7 @@ RETURN_ALLOC_STR8: return output; } -WpStr8 *wapp_str8_alloc_substr(const Allocator *allocator, WpStr8RO *str, u64 start, u64 end) { +WpStr8 *wpStr8AllocSubstr(const Allocator *allocator, WpStr8RO *str, u64 start, u64 end) { wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); WpStr8 *output = NULL; @@ -82,7 +82,7 @@ WpStr8 *wapp_str8_alloc_substr(const Allocator *allocator, WpStr8RO *str, u64 st end = str->size; } - output = wapp_str8_alloc_buf(allocator, str->capacity); + output = wpStr8AllocBuf(allocator, str->capacity); if (!output) { goto RETURN_ALLOC_SUBSTR; } @@ -94,12 +94,12 @@ RETURN_ALLOC_SUBSTR: return output; } -void wapp_str8_dealloc_buf(const Allocator *allocator, WpStr8 **str) { +void wpStr8DeallocBuf(const Allocator *allocator, WpStr8 **str) { wpDebugAssert(allocator != NULL && str != NULL && (*str) != NULL, "Either `allocator` is NULL or `str` is an invalid double pointer"); wapp_mem_allocator_free(allocator, (void **)str, STR8_BUF_ALLOC_SIZE((*str)->capacity)); } -c8 wapp_str8_get(const WpStr8 *str, u64 index) { +c8 wpStr8Get(const WpStr8 *str, u64 index) { if (index >= str->size) { return '\0'; } @@ -107,7 +107,7 @@ c8 wapp_str8_get(const WpStr8 *str, u64 index) { return str->buf[index]; } -void wapp_str8_set(WpStr8 *str, u64 index, c8 c) { +void wpStr8Set(WpStr8 *str, u64 index, c8 c) { if (index >= str->size) { return; } @@ -115,24 +115,24 @@ void wapp_str8_set(WpStr8 *str, u64 index, c8 c) { str->buf[index] = c; } -void wapp_str8_push_back(WpStr8 *str, c8 c) { +void wpStr8PushBack(WpStr8 *str, c8 c) { if (!(str->size < str->capacity)) { return; } u64 index = (str->size)++; - wapp_str8_set(str, index, c); + wpStr8Set(str, index, c); } -b8 wapp_str8_equal(WpStr8RO *s1, WpStr8RO *s2) { +b8 wpStr8Equal(WpStr8RO *s1, WpStr8RO *s2) { if (s1->size != s2->size) { return false; } - return wapp_str8_equal_to_count(s1, s2, s1->size); + return wpStr8EqualToCount(s1, s2, s1->size); } -b8 wapp_str8_equal_to_count(WpStr8RO* s1, WpStr8RO* s2, u64 count) { +b8 wpStr8EqualToCount(WpStr8RO* s1, WpStr8RO* s2, u64 count) { if (!s1 || !s2) { return false; } @@ -140,7 +140,7 @@ b8 wapp_str8_equal_to_count(WpStr8RO* s1, WpStr8RO* s2, u64 count) { return memcmp(s1->buf, s2->buf, count) == 0; } -WpStr8 wapp_str8_slice(WpStr8RO *str, u64 start, u64 end) { +WpStr8 wpStr8Slice(WpStr8RO *str, u64 start, u64 end) { if (start >= str->size || start >= end) { start = str->size; end = str->size; @@ -157,7 +157,7 @@ WpStr8 wapp_str8_slice(WpStr8RO *str, u64 start, u64 end) { }; } -WpStr8 *wapp_str8_alloc_concat(const Allocator *allocator, WpStr8 *dst, WpStr8RO *src) { +WpStr8 *wpStr8AllocConcat(const Allocator *allocator, WpStr8 *dst, WpStr8RO *src) { wpDebugAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL"); WpStr8 *output = NULL; @@ -169,21 +169,21 @@ WpStr8 *wapp_str8_alloc_concat(const Allocator *allocator, WpStr8 *dst, WpStr8RO u64 capacity = dst->capacity + src->size; - output = wapp_str8_alloc_buf(allocator, capacity); + output = wpStr8AllocBuf(allocator, capacity); if (!output) { goto RETURN_STR8_CONCAT; } - wapp_str8_concat_capped(output, dst); + wpStr8ConcatCapped(output, dst); SOURCE_STRING_STR8_CONCAT: - wapp_str8_concat_capped(output, src); + wpStr8ConcatCapped(output, src); RETURN_STR8_CONCAT: return output; } -void wapp_str8_concat_capped(WpStr8 *dst, WpStr8RO *src) { +void wpStr8ConcatCapped(WpStr8 *dst, WpStr8RO *src) { wpDebugAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL"); u64 remaining = dst->capacity - dst->size; @@ -193,7 +193,7 @@ void wapp_str8_concat_capped(WpStr8 *dst, WpStr8RO *src) { dst->size += to_copy; } -void wapp_str8_copy_cstr_capped(WpStr8 *dst, const char *src) { +void wpStr8CopyCstrCapped(WpStr8 *dst, const char *src) { wpDebugAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL"); u64 length = strlen(src); @@ -204,7 +204,7 @@ void wapp_str8_copy_cstr_capped(WpStr8 *dst, const char *src) { dst->size = to_copy; } -void wapp_str8_copy_str8_capped(WpStr8 *dst, WpStr8RO *src) { +void wpStr8CopyStr8Capped(WpStr8 *dst, WpStr8RO *src) { wpDebugAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL"); u64 to_copy = src->size <= dst->capacity ? src->size : dst->capacity; @@ -214,7 +214,7 @@ void wapp_str8_copy_str8_capped(WpStr8 *dst, WpStr8RO *src) { dst->size = to_copy; } -void wapp_str8_copy_to_cstr(char *dst, WpStr8RO *src, u64 dst_capacity) { +void wpStr8CopyToCstr(char *dst, WpStr8RO *src, u64 dst_capacity) { wpDebugAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL"); u64 to_copy = src->size < dst_capacity ? src->size : dst_capacity - 1; @@ -223,7 +223,7 @@ void wapp_str8_copy_to_cstr(char *dst, WpStr8RO *src, u64 dst_capacity) { memcpy(dst, src->buf, to_copy); } -void wapp_str8_format(WpStr8 *dst, const char *format, ...) { +void wpStr8Format(WpStr8 *dst, const char *format, ...) { wpDebugAssert(dst != NULL && format != NULL, "`dst` and `format` should not be NULL"); va_list args1; @@ -241,7 +241,7 @@ void wapp_str8_format(WpStr8 *dst, const char *format, ...) { va_end(args2); } -void wapp_str8_to_lower(WpStr8 *dst, WpStr8RO *src) { +void wpStr8ToLower(WpStr8 *dst, WpStr8RO *src) { wpDebugAssert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL"); wpDebugAssert(dst->capacity >= src->capacity, "`dst` does not have enough capacity"); @@ -252,13 +252,13 @@ void wapp_str8_to_lower(WpStr8 *dst, WpStr8RO *src) { u64 index = 0; b8 running = true; while (running) { - wapp_str8_set(dst, index, (u8)tolower(wapp_str8_get(src, index))); + wpStr8Set(dst, index, (u8)tolower(wpStr8Get(src, index))); ++index; running = index < src->size; } } -void wapp_str8_to_upper(WpStr8 *dst, WpStr8RO *src) { +void wpStr8ToUpper(WpStr8 *dst, WpStr8RO *src) { wpDebugAssert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL"); wpDebugAssert(dst->capacity >= src->capacity, "`dst` does not have enough capacity"); @@ -269,13 +269,13 @@ void wapp_str8_to_upper(WpStr8 *dst, WpStr8RO *src) { u64 index = 0; b8 running = true; while (running) { - wapp_str8_set(dst, index, (u8)toupper(wapp_str8_get(src, index))); + wpStr8Set(dst, index, (u8)toupper(wpStr8Get(src, index))); ++index; running = index < src->size; } } -void wapp_str8_from_bytes(WpStr8 *dst, const U8Array src) { +void wpStr8FromBytes(WpStr8 *dst, const U8Array src) { wpDebugAssert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL"); u64 size = wapp_array_count(src) * wapp_array_item_size(src); @@ -286,7 +286,7 @@ void wapp_str8_from_bytes(WpStr8 *dst, const U8Array src) { memcpy(dst->buf, src, size); } -i64 wapp_str8_find(WpStr8RO *str, WpStr8RO substr) { +i64 wpStr8Find(WpStr8RO *str, WpStr8RO substr) { if (!str || substr.size > str->size) { return -1; } @@ -308,7 +308,7 @@ i64 wapp_str8_find(WpStr8RO *str, WpStr8RO substr) { return -1; } -i64 wapp_str8_rfind(WpStr8RO *str, WpStr8RO substr) { +i64 wpStr8Rfind(WpStr8RO *str, WpStr8RO substr) { if (!str || substr.size > str->size) { return -1; } @@ -330,13 +330,13 @@ i64 wapp_str8_rfind(WpStr8RO *str, WpStr8RO substr) { return -1; } -WpStr8List *wapp_str8_split_with_max(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) { +WpStr8List *wpStr8SplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) { wpDebugAssert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL"); WpStr8List *output = wapp_dbl_list_alloc(WpStr8, allocator); if (delimiter->size > str->size) { - WpStr8 *full = wapp_str8_alloc_str8(allocator, str); + WpStr8 *full = wpStr8AllocStr8(allocator, str); if (full) { wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, full); } @@ -347,28 +347,28 @@ WpStr8List *wapp_str8_split_with_max(const Allocator *allocator, WpStr8RO *str, i64 start = 0; i64 end = 0; i64 splits = 0; - WpStr8 *rest = wapp_str8_alloc_str8(allocator, str); + WpStr8 *rest = wpStr8AllocStr8(allocator, str); WpStr8 *before_str; - while ((end = wapp_str8_find(rest, *delimiter)) != -1) { + while ((end = wpStr8Find(rest, *delimiter)) != -1) { if (max_splits > 0 && splits >= max_splits) { break; } - before_str = wapp_str8_alloc_substr(allocator, str, start, start + end); + before_str = wpStr8AllocSubstr(allocator, str, start, start + end); if (before_str) { wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, before_str); } wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(WpStr8)); - rest = wapp_str8_alloc_substr(allocator, str, start + end + delimiter->size, str->size); + rest = wpStr8AllocSubstr(allocator, str, start + end + delimiter->size, str->size); start += end + delimiter->size; ++splits; } // Ensure the last part of the string after the delimiter is added to the list - rest = wapp_str8_alloc_substr(allocator, str, start, str->size); + rest = wpStr8AllocSubstr(allocator, str, start, str->size); if (rest) { wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, rest); } @@ -377,13 +377,13 @@ RETURN_STR8_SPLIT: return output; } -WpStr8List *wapp_str8_rsplit_with_max(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) { +WpStr8List *wpStr8RsplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) { wpDebugAssert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL"); WpStr8List *output = wapp_dbl_list_alloc(WpStr8, allocator); if (delimiter->size > str->size) { - WpStr8 *full = wapp_str8_alloc_str8(allocator, str); + WpStr8 *full = wpStr8AllocStr8(allocator, str); if (full) { wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, full); } @@ -393,26 +393,26 @@ WpStr8List *wapp_str8_rsplit_with_max(const Allocator *allocator, WpStr8RO *str, i64 end = 0; i64 splits = 0; - WpStr8 *rest = wapp_str8_alloc_str8(allocator, str); + WpStr8 *rest = wpStr8AllocStr8(allocator, str); WpStr8 *after_str; - while ((end = wapp_str8_rfind(rest, *delimiter)) != -1) { + while ((end = wpStr8Rfind(rest, *delimiter)) != -1) { if (max_splits > 0 && splits >= max_splits) { break; } - after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size); + after_str = wpStr8AllocSubstr(allocator, rest, end + delimiter->size, str->size); if (after_str) { wapp_dbl_list_push_front_alloc(WpStr8, allocator, output, after_str); } wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(WpStr8)); - rest = wapp_str8_alloc_substr(allocator, rest, 0, end); + rest = wpStr8AllocSubstr(allocator, rest, 0, end); ++splits; } - rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size); + rest = wpStr8AllocSubstr(allocator, str, 0, rest->size); if (rest) { wapp_dbl_list_push_front_alloc(WpStr8, allocator, output, rest); } @@ -421,11 +421,11 @@ RETURN_STR8_SPLIT: return output; } -WpStr8 *wapp_str8_join(const Allocator *allocator, const WpStr8List *list, WpStr8RO *delimiter) { +WpStr8 *wpStr8Join(const Allocator *allocator, const WpStr8List *list, WpStr8RO *delimiter) { wpDebugAssert(allocator != NULL && list != NULL && delimiter != NULL, "`allocator`, `list` and `delimiter` should not be NULL"); - u64 capacity = wapp_str8_list_total_size(list) + (delimiter->size * (list->node_count - 1)); - WpStr8 *output = wapp_str8_alloc_buf(allocator, capacity * 2); + u64 capacity = wpStr8ListTotalSize(list) + (delimiter->size * (list->node_count - 1)); + WpStr8 *output = wpStr8AllocBuf(allocator, capacity * 2); // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings @@ -438,13 +438,13 @@ WpStr8 *wapp_str8_join(const Allocator *allocator, const WpStr8List *list, WpStr break; } - wapp_str8_concat_capped(output, node); + wpStr8ConcatCapped(output, node); // NOTE (Abdelrahman): Comparison extracted to variable to silence // MSVC Spectre mitigation warnings b8 not_last = node_index + 1 < list->node_count; if (not_last) { - wapp_str8_concat_capped(output, delimiter); + wpStr8ConcatCapped(output, delimiter); } ++node_index; @@ -454,7 +454,7 @@ WpStr8 *wapp_str8_join(const Allocator *allocator, const WpStr8List *list, WpStr return output; } -u64 wapp_str8_list_total_size(const WpStr8List *list) { +u64 wpStr8ListTotalSize(const WpStr8List *list) { if (!list) { return 0; } diff --git a/src/base/strings/str8/str8.h b/src/base/strings/str8/str8.h index 054d114..feff37c 100644 --- a/src/base/strings/str8/str8.h +++ b/src/base/strings/str8/str8.h @@ -36,92 +36,92 @@ typedef const WpStr8 WpStr8RO; #ifdef WP_PLATFORM_CPP // Uses a lambda to achieve the same behaviour achieved by the C macro -#define wapp_str8_buf(CAPACITY) ([&](){ \ - wp_persist c8 buf[CAPACITY] = {}; \ - memset(buf, 0, CAPACITY); \ - return WpStr8{CAPACITY, 0, buf}; \ +#define wpStr8Buf(CAPACITY) ([&](){ \ + wp_persist c8 buf[CAPACITY] = {}; \ + memset(buf, 0, CAPACITY); \ + return WpStr8{CAPACITY, 0, buf}; \ }()) // Uses a lambda to achieve the same behaviour achieved by the C macro -#define wapp_str8_lit(STRING) ([&]() { \ - wp_persist c8 buf[sizeof(STRING) * 2] = {}; \ - memcpy(buf, STRING, sizeof(STRING)); \ - return WpStr8{(sizeof(STRING) - 1) * 2, sizeof(STRING) - 1, buf}; \ +#define wpStr8Lit(STRING) ([&]() { \ + wp_persist c8 buf[sizeof(STRING) * 2] = {}; \ + memcpy(buf, STRING, sizeof(STRING)); \ + return WpStr8{(sizeof(STRING) - 1) * 2, sizeof(STRING) - 1, buf}; \ }()) -#define wapp_str8_lit_ro(STRING) WpStr8RO{sizeof(STRING) - 1, sizeof(STRING) - 1, (c8 *)STRING} -#define wapp_str8_lit_ro_initialiser_list(STRING) {sizeof(STRING) - 1, sizeof(STRING) - 1, (c8 *)STRING} +#define wpStr8LitRo(STRING) WpStr8RO{sizeof(STRING) - 1, sizeof(STRING) - 1, (c8 *)STRING} +#define wpStr8LitRoInitialiserList(STRING) {sizeof(STRING) - 1, sizeof(STRING) - 1, (c8 *)STRING} #else -#define wapp_str8_buf(CAPACITY) ((WpStr8){.capacity = CAPACITY, .size = 0, .buf = (c8[CAPACITY]){0}}) +#define wpStr8Buf(CAPACITY) ((WpStr8){.capacity = CAPACITY, .size = 0, .buf = (c8[CAPACITY]){0}}) // Utilises the fact that memcpy returns pointer to dest buffer and that getting // address of compound literals is valid in C to create a string on the stack -#define wapp_str8_lit(STRING) ((WpStr8){.capacity = (sizeof(STRING) - 1) * 2, \ - .size = sizeof(STRING) - 1, \ - .buf = memcpy(&((c8 [sizeof(STRING) * 2]){0}), \ - STRING, \ +#define wpStr8Lit(STRING) ((WpStr8){.capacity = (sizeof(STRING) - 1) * 2, \ + .size = sizeof(STRING) - 1, \ + .buf = memcpy(&((c8 [sizeof(STRING) * 2]){0}), \ + STRING, \ sizeof(STRING))}) -#define wapp_str8_lit_ro(STRING) ((WpStr8RO){.capacity = sizeof(STRING) - 1, \ - .size = sizeof(STRING) - 1, \ +#define wpStr8LitRo(STRING) ((WpStr8RO){.capacity = sizeof(STRING) - 1, \ + .size = sizeof(STRING) - 1, \ .buf = (c8 *)STRING}) // To be used only when initialising a static storage variable in compilers that don't support -// initialisers with the syntax of wapp_str8_lit_ro (e.g. gcc). Should only be used when necessary +// initialisers with the syntax of wpStr8LitRo (e.g. gcc). Should only be used when necessary // and only be assigned to a WpStr8RO variable to avoid any attempt at modifying the string -#define wapp_str8_lit_ro_initialiser_list(STRING) {.capacity = sizeof(STRING) - 1, \ - .size = sizeof(STRING) - 1, \ +#define wpStr8LitRoInitialiserList(STRING) {.capacity = sizeof(STRING) - 1, \ + .size = sizeof(STRING) - 1, \ .buf = (c8 *)STRING} #endif // !WP_PLATFORM_CPP /** * WpStr8 allocated buffers */ -WpStr8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity); -WpStr8 *wapp_str8_alloc_and_fill_buf(const Allocator *allocator, u64 capacity); -WpStr8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str); -WpStr8 *wapp_str8_alloc_str8(const Allocator *allocator, WpStr8RO *str); -WpStr8 *wapp_str8_alloc_substr(const Allocator *allocator, WpStr8RO *str, u64 start, u64 end); -WpStr8 *wapp_str8_alloc_concat(const Allocator *allocator, WpStr8 *dst, WpStr8RO *src); +WpStr8 *wpStr8AllocBuf(const Allocator *allocator, u64 capacity); +WpStr8 *wpStr8AllocAndFillBuf(const Allocator *allocator, u64 capacity); +WpStr8 *wpStr8AllocCstr(const Allocator *allocator, const char *str); +WpStr8 *wpStr8AllocStr8(const Allocator *allocator, WpStr8RO *str); +WpStr8 *wpStr8AllocSubstr(const Allocator *allocator, WpStr8RO *str, u64 start, u64 end); +WpStr8 *wpStr8AllocConcat(const Allocator *allocator, WpStr8 *dst, WpStr8RO *src); // Only needed for allocators like malloc where each allocation has to be freed on its own. // No need to use it for allocators like Arena. -void wapp_str8_dealloc_buf(const Allocator *allocator, WpStr8 **str); +void wpStr8DeallocBuf(const Allocator *allocator, WpStr8 **str); /** * WpStr8 utilities */ -c8 wapp_str8_get(WpStr8RO *str, u64 index); -void wapp_str8_set(WpStr8 *str, u64 index, c8 c); -void wapp_str8_push_back(WpStr8 *str, c8 c); -b8 wapp_str8_equal(WpStr8RO *s1, WpStr8RO *s2); -b8 wapp_str8_equal_to_count(WpStr8RO* s1, WpStr8RO* s2, u64 count); -WpStr8 wapp_str8_slice(WpStr8RO *str, u64 start, u64 end); -void wapp_str8_concat_capped(WpStr8 *dst, WpStr8RO *src); -void wapp_str8_copy_cstr_capped(WpStr8 *dst, const char *src); -void wapp_str8_copy_str8_capped(WpStr8 *dst, WpStr8RO *src); -void wapp_str8_copy_to_cstr(char *dst, WpStr8RO *src, u64 dst_capacity); -void wapp_str8_format(WpStr8 *dst, const char *format, ...); -void wapp_str8_to_lower(WpStr8 *dst, WpStr8RO *src); -void wapp_str8_to_upper(WpStr8 *dst, WpStr8RO *src); -void wapp_str8_from_bytes(WpStr8 *dst, const U8Array src); +c8 wpStr8Get(WpStr8RO *str, u64 index); +void wpStr8Set(WpStr8 *str, u64 index, c8 c); +void wpStr8PushBack(WpStr8 *str, c8 c); +b8 wpStr8Equal(WpStr8RO *s1, WpStr8RO *s2); +b8 wpStr8EqualToCount(WpStr8RO* s1, WpStr8RO* s2, u64 count); +WpStr8 wpStr8Slice(WpStr8RO *str, u64 start, u64 end); +void wpStr8ConcatCapped(WpStr8 *dst, WpStr8RO *src); +void wpStr8CopyCstrCapped(WpStr8 *dst, const char *src); +void wpStr8CopyStr8Capped(WpStr8 *dst, WpStr8RO *src); +void wpStr8CopyToCstr(char *dst, WpStr8RO *src, u64 dst_capacity); +void wpStr8Format(WpStr8 *dst, const char *format, ...); +void wpStr8ToLower(WpStr8 *dst, WpStr8RO *src); +void wpStr8ToUpper(WpStr8 *dst, WpStr8RO *src); +void wpStr8FromBytes(WpStr8 *dst, const U8Array src); /** * WpStr8 find functions */ -i64 wapp_str8_find(WpStr8RO *str, WpStr8RO substr); -i64 wapp_str8_rfind(WpStr8RO *str, WpStr8RO substr); +i64 wpStr8Find(WpStr8RO *str, WpStr8RO substr); +i64 wpStr8Rfind(WpStr8RO *str, WpStr8RO substr); /** * WpStr8 split and join */ -#define wapp_str8_split(ALLOCATOR, STR, DELIMITER) wapp_str8_split_with_max(ALLOCATOR, STR, DELIMITER, -1) -#define wapp_str8_rsplit(ALLOCATOR, STR, DELIMITER) wapp_str8_rsplit_with_max(ALLOCATOR, STR, DELIMITER, -1) -WpStr8List *wapp_str8_split_with_max(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits); -WpStr8List *wapp_str8_rsplit_with_max(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits); -WpStr8 *wapp_str8_join(const Allocator *allocator, const WpStr8List *list, WpStr8RO *delimiter); +#define wpStr8Split(ALLOCATOR, STR, DELIMITER) wpStr8SplitWithMax(ALLOCATOR, STR, DELIMITER, -1) +#define wpStr8Rsplit(ALLOCATOR, STR, DELIMITER) wpStr8RsplitWithMax(ALLOCATOR, STR, DELIMITER, -1) +WpStr8List *wpStr8SplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits); +WpStr8List *wpStr8RsplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits); +WpStr8 *wpStr8Join(const Allocator *allocator, const WpStr8List *list, WpStr8RO *delimiter); /** * WpStr8 list utilities */ -u64 wapp_str8_list_total_size(const WpStr8List *list); +u64 wpStr8ListTotalSize(const WpStr8List *list); #ifdef WP_PLATFORM_CPP END_C_LINKAGE diff --git a/src/log/log.c b/src/log/log.c index 517f9be..68b7a85 100644 --- a/src/log/log.c +++ b/src/log/log.c @@ -11,9 +11,9 @@ #define MIN_LOG_MSG_LENGTH 32 #define TIME_BUF_CAPACITY 70 -wp_intern WpStr8RO L_BRACKET = wapp_str8_lit_ro("["); -wp_intern WpStr8RO R_BRACKET_SPACE = wapp_str8_lit_ro("] "); -wp_intern WpStr8RO R_BRACKET_NEWLINE = wapp_str8_lit_ro("]\n"); +wp_intern WpStr8RO L_BRACKET = wpStr8LitRo("["); +wp_intern WpStr8RO R_BRACKET_SPACE = wpStr8LitRo("] "); +wp_intern WpStr8RO R_BRACKET_NEWLINE = wpStr8LitRo("]\n"); typedef struct { WFile *outlog; @@ -27,12 +27,12 @@ wp_intern LogConfig LOG_CONFIG = { .level = WP_LOG_LEVEL_DEBUG, }; wp_intern WpStr8RO LOG_LEVEL_STRINGS[COUNT_LOG_LEVEL] = { - [WP_LOG_LEVEL_FATAL] = wapp_str8_lit_ro_initialiser_list("fatal "), - [WP_LOG_LEVEL_CRITICAL] = wapp_str8_lit_ro_initialiser_list("critical "), - [WP_LOG_LEVEL_ERROR] = wapp_str8_lit_ro_initialiser_list("error "), - [WP_LOG_LEVEL_WARNING] = wapp_str8_lit_ro_initialiser_list("warning "), - [WP_LOG_LEVEL_INFO] = wapp_str8_lit_ro_initialiser_list("info "), - [WP_LOG_LEVEL_DEBUG] = wapp_str8_lit_ro_initialiser_list("debug "), + [WP_LOG_LEVEL_FATAL] = wpStr8LitRoInitialiserList("fatal "), + [WP_LOG_LEVEL_CRITICAL] = wpStr8LitRoInitialiserList("critical "), + [WP_LOG_LEVEL_ERROR] = wpStr8LitRoInitialiserList("error "), + [WP_LOG_LEVEL_WARNING] = wpStr8LitRoInitialiserList("warning "), + [WP_LOG_LEVEL_INFO] = wpStr8LitRoInitialiserList("info "), + [WP_LOG_LEVEL_DEBUG] = wpStr8LitRoInitialiserList("debug "), }; wp_intern void _get_current_time_string(WpStr8 *dst); @@ -107,15 +107,15 @@ wp_intern void _get_current_time_string(WpStr8 *dst) { struct tm utc; gmtime_r(&now, &utc); strftime(buf, sizeof(buf), "%FT%TZ ", &utc); - wapp_str8_copy_cstr_capped(dst, buf); + wpStr8CopyCstrCapped(dst, buf); } wp_intern void _write_log_line(WFile *fp, const WpLogger *logger, WpStr8 msg, LogLevel level) { - WpStr8 padding = wapp_str8_buf(MIN_LOG_MSG_LENGTH); + WpStr8 padding = wpStr8Buf(MIN_LOG_MSG_LENGTH); u32 padding_size = msg.size < MIN_LOG_MSG_LENGTH ? MIN_LOG_MSG_LENGTH - msg.size + 1 : 0; - wapp_str8_format(&padding, "%-*s", padding_size, " "); + wpStr8Format(&padding, "%-*s", padding_size, " "); - WpStr8 time_str = wapp_str8_buf(TIME_BUF_CAPACITY); + WpStr8 time_str = wpStr8Buf(TIME_BUF_CAPACITY); _get_current_time_string(&time_str); WpStr8RO **strings = wapp_array( diff --git a/src/os/cpath/cpath.c b/src/os/cpath/cpath.c index bf2162b..f5df78a 100644 --- a/src/os/cpath/cpath.c +++ b/src/os/cpath/cpath.c @@ -20,17 +20,17 @@ u32 wapp_cpath_join_path(WpStr8 *dst, const WpStr8List *parts) { return CPATH_JOIN_EMPTY_PARTS; } - WpStr8 separator = wapp_str8_buf(4); - wapp_str8_push_back(&separator, WAPP_PATH_SEP); + WpStr8 separator = wpStr8Buf(4); + wpStr8PushBack(&separator, WAPP_PATH_SEP); - u64 required_capacity = parts->node_count * separator.size + wapp_str8_list_total_size(parts); + u64 required_capacity = parts->node_count * separator.size + wpStr8ListTotalSize(parts); if (dst->capacity < required_capacity) { return CPATH_JOIN_INSUFFICIENT_DST_CAPACITY; } // Handle first node WpStr8 *first_node = wapp_dbl_list_get(WpStr8, parts, 0); - wapp_str8_copy_str8_capped(dst, first_node); + wpStr8CopyStr8Capped(dst, first_node); // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings @@ -44,16 +44,16 @@ u32 wapp_cpath_join_path(WpStr8 *dst, const WpStr8List *parts) { } if (dst->size > 0) { - char dst_last = wapp_str8_get(dst, dst->size - 1); - char node_start = wapp_str8_get(node, 0); + char dst_last = wpStr8Get(dst, dst->size - 1); + char node_start = wpStr8Get(node, 0); b8 add_path_sep = dst_last != WAPP_PATH_SEP && node_start != WAPP_PATH_SEP; if (add_path_sep) { - wapp_str8_concat_capped(dst, &separator); + wpStr8ConcatCapped(dst, &separator); } } - wapp_str8_concat_capped(dst, node); + wpStr8ConcatCapped(dst, node); CPATH_JOIN_LOOP_END: ++node_index; @@ -69,22 +69,22 @@ WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels) { goto RETURN_DIRUP; } - b8 absolute = wapp_str8_get(path, 0) == WAPP_PATH_SEP; - WpStr8 separator = wapp_str8_buf(4); - wapp_str8_push_back(&separator, WAPP_PATH_SEP); + b8 absolute = wpStr8Get(path, 0) == WAPP_PATH_SEP; + WpStr8 separator = wpStr8Buf(4); + wpStr8PushBack(&separator, WAPP_PATH_SEP); if (path->size == 0) { - output = wapp_str8_alloc_buf(allocator, 16); + output = wpStr8AllocBuf(allocator, 16); if (!output) { goto RETURN_DIRUP; } - wapp_str8_push_back(output, absolute ? WAPP_PATH_SEP : '.'); + wpStr8PushBack(output, absolute ? WAPP_PATH_SEP : '.'); goto RETURN_DIRUP; } if (levels < 1) { - output = wapp_str8_alloc_str8(allocator, path); + output = wpStr8AllocStr8(allocator, path); goto RETURN_DIRUP; } @@ -93,37 +93,37 @@ WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels) { goto RETURN_DIRUP; } - WpStr8List *parts = wapp_str8_split(&tmp_arena, path, &separator); + WpStr8List *parts = wpStr8Split(&tmp_arena, path, &separator); if (!parts) { goto RETURN_DIRUP; } if (levels >= parts->node_count) { - output = wapp_str8_alloc_buf(allocator, 16); + output = wpStr8AllocBuf(allocator, 16); if (!output) { goto LIST_CLEANUP_DIRUP; } - wapp_str8_push_back(output, absolute ? WAPP_PATH_SEP : '.'); + wpStr8PushBack(output, absolute ? WAPP_PATH_SEP : '.'); } else { for (u64 i = 0; i < levels; ++i) { wapp_dbl_list_pop_back(WpStr8, parts); } u64 alignment = sizeof(void *) * 2; - u64 alloc_size = wapp_str8_list_total_size(parts) + parts->node_count * separator.size; + u64 alloc_size = wpStr8ListTotalSize(parts) + parts->node_count * separator.size; u64 modulo = alloc_size & (alignment - 1); alloc_size += alignment - modulo; - output = wapp_str8_alloc_buf(allocator, alloc_size); + output = wpStr8AllocBuf(allocator, alloc_size); if (output) { if (absolute) { - wapp_str8_push_back(output, WAPP_PATH_SEP); + wpStr8PushBack(output, WAPP_PATH_SEP); } - WpStr8 *joined = wapp_str8_join(&tmp_arena, parts, &separator); + WpStr8 *joined = wpStr8Join(&tmp_arena, parts, &separator); if (joined) { - wapp_str8_concat_capped(output, joined); + wpStr8ConcatCapped(output, joined); } } } diff --git a/src/os/shell/commander/commander.c b/src/os/shell/commander/commander.c index 66d3dfd..9d642d7 100644 --- a/src/os/shell/commander/commander.c +++ b/src/os/shell/commander/commander.c @@ -27,14 +27,14 @@ CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, WpStr8 *out_ Allocator arena = wapp_mem_arena_allocator_init(KiB(500)); - WpStr8 *cmd_str = wapp_str8_join(&arena, cmd, &wapp_str8_lit_ro(" ")); + WpStr8 *cmd_str = wpStr8Join(&arena, cmd, &wpStr8LitRo(" ")); if (!cmd_str) { wapp_mem_arena_allocator_destroy(&arena); return CMD_NO_EXIT(SHELL_ERR_ALLOCATION_FAIL); } // Redirect output - cmd_str = wapp_str8_alloc_concat(&arena, cmd_str, &wapp_str8_lit_ro(" 2>&1")); + cmd_str = wpStr8AllocConcat(&arena, cmd_str, &wpStr8LitRo(" 2>&1")); CMDResult output = execute_command(cmd_str, out_handling, out_buf); @@ -45,7 +45,7 @@ CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, WpStr8 *out_ wp_intern CMDResult execute_command(WpStr8RO *cmd, CMDOutHandling out_handling, WpStr8 *out_buf) { char cmd_buf[CMD_BUF_LEN] = {0}; - wapp_str8_copy_to_cstr(cmd_buf, cmd, CMD_BUF_LEN); + wpStr8CopyToCstr(cmd_buf, cmd, CMD_BUF_LEN); FILE *fp = wapp_shell_utils_popen(cmd_buf, "r"); if (!fp) { @@ -84,7 +84,7 @@ EXECUTE_COMMAND_CLOSE: } wp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, WpStr8 *out_buf) { - WpStr8 out = wapp_str8_buf(OUT_BUF_LEN); + WpStr8 out = wpStr8Buf(OUT_BUF_LEN); out.size = fread((void *)out.buf, sizeof(c8), out.capacity, fp); if (out_handling == SHELL_OUTPUT_CAPTURE && out_buf != NULL) { @@ -92,7 +92,7 @@ wp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, WpS return SHELL_ERR_OUT_BUF_FULL; } - wapp_str8_concat_capped(out_buf, &out); + wpStr8ConcatCapped(out_buf, &out); } else if (out_handling == SHELL_OUTPUT_PRINT) { printf(WP_STR8_SPEC, wpStr8Varg(out)); } diff --git a/src/os/shell/termcolour/posix/termcolour_posix.c b/src/os/shell/termcolour/posix/termcolour_posix.c index 8f641c6..0cc6836 100644 --- a/src/os/shell/termcolour/posix/termcolour_posix.c +++ b/src/os/shell/termcolour/posix/termcolour_posix.c @@ -10,23 +10,23 @@ #include wp_intern WpStr8RO colours[COUNT_TERM_COLOUR] = { - [WAPP_TERM_COLOUR_FG_BLACK] = wapp_str8_lit_ro_initialiser_list("\033[30m"), - [WAPP_TERM_COLOUR_FG_RED] = wapp_str8_lit_ro_initialiser_list("\033[31m"), - [WAPP_TERM_COLOUR_FG_GREEN] = wapp_str8_lit_ro_initialiser_list("\033[32m"), - [WAPP_TERM_COLOUR_FG_BLUE] = wapp_str8_lit_ro_initialiser_list("\033[34m"), - [WAPP_TERM_COLOUR_FG_CYAN] = wapp_str8_lit_ro_initialiser_list("\033[36m"), - [WAPP_TERM_COLOUR_FG_MAGENTA] = wapp_str8_lit_ro_initialiser_list("\033[35m"), - [WAPP_TERM_COLOUR_FG_YELLOW] = wapp_str8_lit_ro_initialiser_list("\033[33m"), - [WAPP_TERM_COLOUR_FG_WHITE] = wapp_str8_lit_ro_initialiser_list("\033[37m"), - [WAPP_TERM_COLOUR_FG_BR_BLACK] = wapp_str8_lit_ro_initialiser_list("\033[90m"), - [WAPP_TERM_COLOUR_FG_BR_RED] = wapp_str8_lit_ro_initialiser_list("\033[91m"), - [WAPP_TERM_COLOUR_FG_BR_GREEN] = wapp_str8_lit_ro_initialiser_list("\033[92m"), - [WAPP_TERM_COLOUR_FG_BR_BLUE] = wapp_str8_lit_ro_initialiser_list("\033[94m"), - [WAPP_TERM_COLOUR_FG_BR_CYAN] = wapp_str8_lit_ro_initialiser_list("\033[96m"), - [WAPP_TERM_COLOUR_FG_BR_MAGENTA] = wapp_str8_lit_ro_initialiser_list("\033[95m"), - [WAPP_TERM_COLOUR_FG_BR_YELLOW] = wapp_str8_lit_ro_initialiser_list("\033[93m"), - [WAPP_TERM_COLOUR_FG_BR_WHITE] = wapp_str8_lit_ro_initialiser_list("\033[97m"), - [WAPP_TERM_COLOUR_CLEAR] = wapp_str8_lit_ro_initialiser_list("\033[0m"), + [WAPP_TERM_COLOUR_FG_BLACK] = wpStr8LitRoInitialiserList("\033[30m"), + [WAPP_TERM_COLOUR_FG_RED] = wpStr8LitRoInitialiserList("\033[31m"), + [WAPP_TERM_COLOUR_FG_GREEN] = wpStr8LitRoInitialiserList("\033[32m"), + [WAPP_TERM_COLOUR_FG_BLUE] = wpStr8LitRoInitialiserList("\033[34m"), + [WAPP_TERM_COLOUR_FG_CYAN] = wpStr8LitRoInitialiserList("\033[36m"), + [WAPP_TERM_COLOUR_FG_MAGENTA] = wpStr8LitRoInitialiserList("\033[35m"), + [WAPP_TERM_COLOUR_FG_YELLOW] = wpStr8LitRoInitialiserList("\033[33m"), + [WAPP_TERM_COLOUR_FG_WHITE] = wpStr8LitRoInitialiserList("\033[37m"), + [WAPP_TERM_COLOUR_FG_BR_BLACK] = wpStr8LitRoInitialiserList("\033[90m"), + [WAPP_TERM_COLOUR_FG_BR_RED] = wpStr8LitRoInitialiserList("\033[91m"), + [WAPP_TERM_COLOUR_FG_BR_GREEN] = wpStr8LitRoInitialiserList("\033[92m"), + [WAPP_TERM_COLOUR_FG_BR_BLUE] = wpStr8LitRoInitialiserList("\033[94m"), + [WAPP_TERM_COLOUR_FG_BR_CYAN] = wpStr8LitRoInitialiserList("\033[96m"), + [WAPP_TERM_COLOUR_FG_BR_MAGENTA] = wpStr8LitRoInitialiserList("\033[95m"), + [WAPP_TERM_COLOUR_FG_BR_YELLOW] = wpStr8LitRoInitialiserList("\033[93m"), + [WAPP_TERM_COLOUR_FG_BR_WHITE] = wpStr8LitRoInitialiserList("\033[97m"), + [WAPP_TERM_COLOUR_CLEAR] = wpStr8LitRoInitialiserList("\033[0m"), }; void print_coloured_text(WpStr8RO *text, TerminalColour colour) { diff --git a/src/os/shell/termcolour/termcolour.c b/src/os/shell/termcolour/termcolour.c index 058657c..63153af 100644 --- a/src/os/shell/termcolour/termcolour.c +++ b/src/os/shell/termcolour/termcolour.c @@ -13,6 +13,6 @@ void wapp_shell_termcolour_print_text(WpStr8RO *text, TerminalColour colour) { } void wapp_shell_termcolour_clear_colour(void) { - WpStr8RO empty = wapp_str8_lit_ro(""); + WpStr8RO empty = wpStr8LitRo(""); print_coloured_text(&empty, WAPP_TERM_COLOUR_CLEAR); } diff --git a/src/testing/tester/tester.c b/src/testing/tester/tester.c index bd00463..a4229fd 100644 --- a/src/testing/tester/tester.c +++ b/src/testing/tester/tester.c @@ -34,14 +34,14 @@ void _runTests(WpTestFunc *func1, ...) { wp_intern void handleTestResult(WpTestFuncResult result) { TerminalColour colour; - WpStr8 result_text = wapp_str8_buf(64); + WpStr8 result_text = wpStr8Buf(64); if (result.passed) { colour = WAPP_TERM_COLOUR_FG_BR_GREEN; - wapp_str8_copy_cstr_capped(&result_text, "PASSED"); + wpStr8CopyCstrCapped(&result_text, "PASSED"); } else { colour = WAPP_TERM_COLOUR_FG_BR_RED; - wapp_str8_copy_cstr_capped(&result_text, "FAILED"); + wpStr8CopyCstrCapped(&result_text, "FAILED"); } printf("["); diff --git a/src/testing/tester/tester.h b/src/testing/tester/tester.h index a0ef635..5ac7d8c 100644 --- a/src/testing/tester/tester.h +++ b/src/testing/tester/tester.h @@ -10,9 +10,9 @@ #ifdef WP_PLATFORM_CPP BEGIN_C_LINKAGE -#define wpTesterResult(PASSED) (WpTestFuncResult{wapp_str8_lit_ro(__func__), PASSED, {}}) +#define wpTesterResult(PASSED) (WpTestFuncResult{wpStr8LitRo(__func__), PASSED, {}}) #else -#define wpTesterResult(PASSED) ((WpTestFuncResult){.name = wapp_str8_lit_ro(__func__), .passed = PASSED}) +#define wpTesterResult(PASSED) ((WpTestFuncResult){.name = wpStr8LitRo(__func__), .passed = PASSED}) #endif // !WP_PLATFORM_CPP #define wpTesterRun(...) _runTests(__VA_ARGS__, NULL) diff --git a/src/uuid/uuid.c b/src/uuid/uuid.c index 71dfb0f..8f50e26 100644 --- a/src/uuid/uuid.c +++ b/src/uuid/uuid.c @@ -54,5 +54,5 @@ wp_intern void uuid4_to_uuid(const UUID4* uuid4, WpUuid *uuid) { u64 group4 = uuid4->low >> 48; u64 group5 = (uuid4->low << 16) >> 16; - wapp_str8_format(&(uuid->uuid), UUID_STR_FORMAT, group1, group2, group3, group4, group5); + wpStr8Format(&(uuid->uuid), UUID_STR_FORMAT, group1, group2, group3, group4, group5); } diff --git a/src/uuid/uuid.h b/src/uuid/uuid.h index a4c9e97..51a7fdd 100644 --- a/src/uuid/uuid.h +++ b/src/uuid/uuid.h @@ -34,9 +34,9 @@ struct WpUuid { /* Low level UUID API */ #ifdef WP_PLATFORM_CPP -#define wpUuidCreate() ([&](){ return WpUuid{wapp_str8_buf(WP_UUID_BUF_LENGTH)}; }()) +#define wpUuidCreate() ([&](){ return WpUuid{wpStr8Buf(WP_UUID_BUF_LENGTH)}; }()) #else -#define wpUuidCreate() ((WpUuid){.uuid = wapp_str8_buf(WP_UUID_BUF_LENGTH)}) +#define wpUuidCreate() ((WpUuid){.uuid = wpStr8Buf(WP_UUID_BUF_LENGTH)}) #endif // Just returns the same pointer that was passed in with the UUID initialised. diff --git a/tests/array/test_str8_array.c b/tests/array/test_str8_array.c index 1985c94..937ec1f 100644 --- a/tests/array/test_str8_array.c +++ b/tests/array/test_str8_array.c @@ -5,8 +5,8 @@ WpTestFuncResult test_str8_array(void) { b8 result; - WpStr8 expected[] = {wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye")}; - WpStr8Array array = wapp_array(WpStr8, wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye")); + WpStr8 expected[] = {wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye")}; + WpStr8Array array = wapp_array(WpStr8, wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye")); result = wapp_array_count(array) == 3 && wapp_array_capacity(array) == 8; WpStr8 *item; @@ -15,7 +15,7 @@ WpTestFuncResult test_str8_array(void) { b8 running = true; while (running) { item = wapp_array_get(WpStr8, array, index); - result = result && item && (wapp_str8_equal(item, &expected[index])); + result = result && item && (wpStr8Equal(item, &expected[index])); ++index; running = index < count; diff --git a/tests/array/test_str8_array.cc b/tests/array/test_str8_array.cc index 48a76b4..718799e 100644 --- a/tests/array/test_str8_array.cc +++ b/tests/array/test_str8_array.cc @@ -5,11 +5,11 @@ WpTestFuncResult test_str8_array(void) { b8 result; - WpStr8 expected[] = {wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye")}; + WpStr8 expected[] = {wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye")}; - WpStr8 str1 = wapp_str8_lit("Hello"); - WpStr8 str2 = wapp_str8_lit("Hi"); - WpStr8 str3 = wapp_str8_lit("Bye"); + WpStr8 str1 = wpStr8Lit("Hello"); + WpStr8 str2 = wpStr8Lit("Hi"); + WpStr8 str3 = wpStr8Lit("Bye"); WpStr8Array array = wapp_array(WpStr8, str1, str2, str3); result = wapp_array_count(array) == 3 && wapp_array_capacity(array) == 8; @@ -20,7 +20,7 @@ WpTestFuncResult test_str8_array(void) { b8 running = true; while (running) { item = wapp_array_get(WpStr8, array, index); - result = result && item && (wapp_str8_equal(item, &expected[index])); + result = result && item && (wpStr8Equal(item, &expected[index])); ++index; running = index < count; diff --git a/tests/cpath/test_cpath.c b/tests/cpath/test_cpath.c index 64235a0..0006c29 100644 --- a/tests/cpath/test_cpath.c +++ b/tests/cpath/test_cpath.c @@ -9,73 +9,73 @@ WpTestFuncResult test_cpath_join_path(void) { b8 result; - WpStr8 expected = wapp_str8_buf(MAIN_BUF_SIZE); - WpStr8 out = wapp_str8_buf(MAIN_BUF_SIZE); - WpStr8 tmp = wapp_str8_buf(TMP_BUF_SIZE); + WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE); + WpStr8 out = wpStr8Buf(MAIN_BUF_SIZE); + WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE); - wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&tmp, "%c", WAPP_PATH_SEP); WpStr8List parts = wapp_dbl_list(WpStr8); wapp_dbl_list_push_back(WpStr8, &parts, &tmp); - wapp_dbl_list_push_back(WpStr8, &parts, &wapp_str8_lit("home")); - wapp_dbl_list_push_back(WpStr8, &parts, &wapp_str8_lit("abdelrahman")); - wapp_dbl_list_push_back(WpStr8, &parts, &wapp_str8_lit("Documents")); + wapp_dbl_list_push_back(WpStr8, &parts, &wpStr8Lit("home")); + wapp_dbl_list_push_back(WpStr8, &parts, &wpStr8Lit("abdelrahman")); + wapp_dbl_list_push_back(WpStr8, &parts, &wpStr8Lit("Documents")); wapp_cpath_join_path(&out, &parts); - result = wapp_str8_equal(&out, &expected); + result = wpStr8Equal(&out, &expected); wapp_dbl_list_pop_front(WpStr8, &parts); - wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); - wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("home")); + wpStr8ConcatCapped(&tmp, &wpStr8LitRo("home")); wapp_dbl_list_pop_front(WpStr8, &parts); wapp_dbl_list_push_front(WpStr8, &parts, &tmp); - wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); - wapp_str8_format(&tmp, "home%c", WAPP_PATH_SEP); + wpStr8Format(&tmp, "home%c", WAPP_PATH_SEP); wapp_dbl_list_pop_front(WpStr8, &parts); - wapp_dbl_list_push_front(WpStr8, &parts, &wapp_str8_lit("home")); + wapp_dbl_list_push_front(WpStr8, &parts, &wpStr8Lit("home")); - wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); wapp_dbl_list_empty(WpStr8, &parts); - wapp_str8_format(&tmp, "%chome", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome", WAPP_PATH_SEP); wapp_dbl_list_push_back(WpStr8, &parts, &tmp); - wapp_dbl_list_push_back(WpStr8, &parts, &wapp_str8_lit("")); + wapp_dbl_list_push_back(WpStr8, &parts, &wpStr8Lit("")); - wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome", WAPP_PATH_SEP); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); wapp_dbl_list_pop_front(WpStr8, &parts); - wapp_dbl_list_push_back(WpStr8, &parts, &wapp_str8_lit("")); + wapp_dbl_list_push_back(WpStr8, &parts, &wpStr8Lit("")); - wapp_str8_format(&expected, "%s", ""); + wpStr8Format(&expected, "%s", ""); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); wapp_dbl_list_pop_back(WpStr8, &parts); - wapp_dbl_list_push_back(WpStr8, &parts, &wapp_str8_lit("home")); + wapp_dbl_list_push_back(WpStr8, &parts, &wpStr8Lit("home")); - wapp_str8_copy_cstr_capped(&expected, "home"); + wpStr8CopyCstrCapped(&expected, "home"); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); return wpTesterResult(result); } @@ -89,39 +89,39 @@ WpTestFuncResult test_cpath_dirname(void) { b8 result; WpStr8 *output = NULL; - WpStr8 expected = wapp_str8_buf(MAIN_BUF_SIZE); - WpStr8 tmp = wapp_str8_buf(TMP_BUF_SIZE); + WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE); + WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE); // CASE 1 - wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP); - wapp_str8_format(&expected, "%c", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%c", WAPP_PATH_SEP); + wpStr8Format(&expected, "%c", WAPP_PATH_SEP); output = wapp_cpath_dirname(&arena, &tmp); - result = output != NULL && wapp_str8_equal(output, &expected); + result = output != NULL && wpStr8Equal(output, &expected); // CASE 2 - wapp_str8_format(&expected, "%s", "."); + wpStr8Format(&expected, "%s", "."); - output = wapp_cpath_dirname(&arena, &wapp_str8_lit("home")); - result = result && output != NULL && wapp_str8_equal(output, &expected); + output = wapp_cpath_dirname(&arena, &wpStr8Lit("home")); + result = result && output != NULL && wpStr8Equal(output, &expected); // CASE 3 - output = wapp_cpath_dirname(&arena, &wapp_str8_lit("")); - result = result && output != NULL && wapp_str8_equal(output, &expected); + output = wapp_cpath_dirname(&arena, &wpStr8Lit("")); + result = result && output != NULL && wpStr8Equal(output, &expected); // CASE 4 - wapp_str8_format(&tmp, "%chome%ctest", WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome%ctest", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome", WAPP_PATH_SEP); output = wapp_cpath_dirname(&arena, &tmp); - result = result && output != NULL && wapp_str8_equal(output, &expected); + result = result && output != NULL && wpStr8Equal(output, &expected); // CASE 5 - wapp_str8_format(&tmp, "%chome%ctest%c", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome%ctest%c", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome", WAPP_PATH_SEP); output = wapp_cpath_dirname(&arena, &tmp); - result = result && output != NULL && wapp_str8_equal(output, &expected); + result = result && output != NULL && wpStr8Equal(output, &expected); wapp_mem_arena_allocator_destroy(&arena); @@ -137,43 +137,43 @@ WpTestFuncResult test_cpath_dirup(void) { b8 result; WpStr8 *output = NULL; - WpStr8 expected = wapp_str8_buf(MAIN_BUF_SIZE); - WpStr8 tmp = wapp_str8_buf(TMP_BUF_SIZE); + WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE); + WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE); // CASE 1 - wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP); - wapp_str8_format(&expected, "%c", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%c", WAPP_PATH_SEP); + wpStr8Format(&expected, "%c", WAPP_PATH_SEP); output = wapp_cpath_dirup(&arena, &tmp, 3); - result = output != NULL && wapp_str8_equal(output, &expected); + result = output != NULL && wpStr8Equal(output, &expected); // CASE 2 - wapp_str8_format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&expected, "%c", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%c", WAPP_PATH_SEP); output = wapp_cpath_dirup(&arena, &tmp, 3); - result = result && output != NULL && wapp_str8_equal(output, &expected); + result = result && output != NULL && wpStr8Equal(output, &expected); // CASE 3 - wapp_str8_format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_copy_cstr_capped(&expected, "."); + wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8CopyCstrCapped(&expected, "."); output = wapp_cpath_dirup(&arena, &tmp, 3); - result = result && output != NULL && wapp_str8_equal(output, &expected); + result = result && output != NULL && wpStr8Equal(output, &expected); // CASE 4 - wapp_str8_format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome", WAPP_PATH_SEP); output = wapp_cpath_dirup(&arena, &tmp, 2); - result = result && output != NULL && wapp_str8_equal(output, &expected); + result = result && output != NULL && wpStr8Equal(output, &expected); // CASE 5 - wapp_str8_format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_copy_cstr_capped(&expected, "home"); + wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8CopyCstrCapped(&expected, "home"); output = wapp_cpath_dirup(&arena, &tmp, 2); - result = result && output != NULL && wapp_str8_equal(output, &expected); + result = result && output != NULL && wpStr8Equal(output, &expected); wapp_mem_arena_allocator_destroy(&arena); diff --git a/tests/cpath/test_cpath.cc b/tests/cpath/test_cpath.cc index 27e12b0..d9d9e1f 100644 --- a/tests/cpath/test_cpath.cc +++ b/tests/cpath/test_cpath.cc @@ -9,91 +9,91 @@ WpTestFuncResult test_cpath_join_path(void) { b8 result; - WpStr8 expected = wapp_str8_buf(MAIN_BUF_SIZE); - WpStr8 out = wapp_str8_buf(MAIN_BUF_SIZE); - WpStr8 tmp = wapp_str8_buf(TMP_BUF_SIZE); + WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE); + WpStr8 out = wpStr8Buf(MAIN_BUF_SIZE); + WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE); - wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&tmp, "%c", WAPP_PATH_SEP); WpStr8List parts = wapp_dbl_list(WpStr8); wapp_dbl_list_push_back(WpStr8, &parts, &tmp); - WpStr8 home = wapp_str8_lit("home"); + WpStr8 home = wpStr8Lit("home"); wapp_dbl_list_push_back(WpStr8, &parts, &home); - WpStr8 user = wapp_str8_lit("abdelrahman"); + WpStr8 user = wpStr8Lit("abdelrahman"); wapp_dbl_list_push_back(WpStr8, &parts, &user); - WpStr8 docs = wapp_str8_lit("Documents"); + WpStr8 docs = wpStr8Lit("Documents"); wapp_dbl_list_push_back(WpStr8, &parts, &docs); wapp_cpath_join_path(&out, &parts); - result = wapp_str8_equal(&out, &expected); + result = wpStr8Equal(&out, &expected); wapp_dbl_list_pop_front(WpStr8, &parts); - wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); - WpStr8RO str = wapp_str8_lit_ro("home"); - wapp_str8_concat_capped(&tmp, &str); + WpStr8RO str = wpStr8LitRo("home"); + wpStr8ConcatCapped(&tmp, &str); wapp_dbl_list_pop_front(WpStr8, &parts); wapp_dbl_list_push_front(WpStr8, &parts, &tmp); - wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); - wapp_str8_format(&tmp, "home%c", WAPP_PATH_SEP); + wpStr8Format(&tmp, "home%c", WAPP_PATH_SEP); wapp_dbl_list_pop_front(WpStr8, &parts); - WpStr8 home_2 = wapp_str8_lit("home"); + WpStr8 home_2 = wpStr8Lit("home"); wapp_dbl_list_push_front(WpStr8, &parts, &home_2); - wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); wapp_dbl_list_empty(WpStr8, &parts); - wapp_str8_format(&tmp, "%chome", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome", WAPP_PATH_SEP); wapp_dbl_list_push_back(WpStr8, &parts, &tmp); - WpStr8 empty = wapp_str8_lit(""); + WpStr8 empty = wpStr8Lit(""); wapp_dbl_list_push_back(WpStr8, &parts, &empty); - wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome", WAPP_PATH_SEP); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); wapp_dbl_list_pop_front(WpStr8, &parts); - WpStr8 empty_2 = wapp_str8_lit(""); + WpStr8 empty_2 = wpStr8Lit(""); wapp_dbl_list_push_back(WpStr8, &parts, &empty_2); - wapp_str8_format(&expected, "%s", ""); + wpStr8Format(&expected, "%s", ""); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); wapp_dbl_list_pop_back(WpStr8, &parts); - WpStr8 home_3 = wapp_str8_lit("home"); + WpStr8 home_3 = wpStr8Lit("home"); wapp_dbl_list_push_back(WpStr8, &parts, &home_3); - wapp_str8_copy_cstr_capped(&expected, "home"); + wpStr8CopyCstrCapped(&expected, "home"); wapp_cpath_join_path(&out, &parts); - result = result && wapp_str8_equal(&out, &expected); + result = result && wpStr8Equal(&out, &expected); return wpTesterResult(result); } @@ -107,41 +107,41 @@ WpTestFuncResult test_cpath_dirname(void) { b8 result; WpStr8 *output = nullptr; - WpStr8 expected = wapp_str8_buf(MAIN_BUF_SIZE); - WpStr8 tmp = wapp_str8_buf(TMP_BUF_SIZE); + WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE); + WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE); // CASE 1 - wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP); - wapp_str8_format(&expected, "%c", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%c", WAPP_PATH_SEP); + wpStr8Format(&expected, "%c", WAPP_PATH_SEP); output = wapp_cpath_dirname(&arena, &tmp); - result = output != nullptr && wapp_str8_equal(output, &expected); + result = output != nullptr && wpStr8Equal(output, &expected); // CASE 2 - wapp_str8_format(&expected, "%s", "."); + wpStr8Format(&expected, "%s", "."); - WpStr8 path = wapp_str8_lit("home"); + WpStr8 path = wpStr8Lit("home"); output = wapp_cpath_dirname(&arena, &path); - result = result && output != nullptr && wapp_str8_equal(output, &expected); + result = result && output != nullptr && wpStr8Equal(output, &expected); // CASE 3 - path = wapp_str8_lit(""); + path = wpStr8Lit(""); output = wapp_cpath_dirname(&arena, &path); - result = result && output != nullptr && wapp_str8_equal(output, &expected); + result = result && output != nullptr && wpStr8Equal(output, &expected); // CASE 4 - wapp_str8_format(&tmp, "%chome%ctest", WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome%ctest", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome", WAPP_PATH_SEP); output = wapp_cpath_dirname(&arena, &tmp); - result = result && output != nullptr && wapp_str8_equal(output, &expected); + result = result && output != nullptr && wpStr8Equal(output, &expected); // CASE 5 - wapp_str8_format(&tmp, "%chome%ctest%c", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome%ctest%c", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome", WAPP_PATH_SEP); output = wapp_cpath_dirname(&arena, &tmp); - result = result && output != nullptr && wapp_str8_equal(output, &expected); + result = result && output != nullptr && wpStr8Equal(output, &expected); wapp_mem_arena_allocator_destroy(&arena); @@ -157,43 +157,43 @@ WpTestFuncResult test_cpath_dirup(void) { b8 result; WpStr8 *output = nullptr; - WpStr8 expected = wapp_str8_buf(MAIN_BUF_SIZE); - WpStr8 tmp = wapp_str8_buf(TMP_BUF_SIZE); + WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE); + WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE); // CASE 1 - wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP); - wapp_str8_format(&expected, "%c", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%c", WAPP_PATH_SEP); + wpStr8Format(&expected, "%c", WAPP_PATH_SEP); output = wapp_cpath_dirup(&arena, &tmp, 3); - result = output != nullptr && wapp_str8_equal(output, &expected); + result = output != nullptr && wpStr8Equal(output, &expected); // CASE 2 - wapp_str8_format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&expected, "%c", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%c", WAPP_PATH_SEP); output = wapp_cpath_dirup(&arena, &tmp, 3); - result = result && output != nullptr && wapp_str8_equal(output, &expected); + result = result && output != nullptr && wpStr8Equal(output, &expected); // CASE 3 - wapp_str8_format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_copy_cstr_capped(&expected, "."); + wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8CopyCstrCapped(&expected, "."); output = wapp_cpath_dirup(&arena, &tmp, 3); - result = result && output != nullptr && wapp_str8_equal(output, &expected); + result = result && output != nullptr && wpStr8Equal(output, &expected); // CASE 4 - wapp_str8_format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); + wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8Format(&expected, "%chome", WAPP_PATH_SEP); output = wapp_cpath_dirup(&arena, &tmp, 2); - result = result && output != nullptr && wapp_str8_equal(output, &expected); + result = result && output != nullptr && wpStr8Equal(output, &expected); // CASE 5 - wapp_str8_format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); - wapp_str8_copy_cstr_capped(&expected, "home"); + wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); + wpStr8CopyCstrCapped(&expected, "home"); output = wapp_cpath_dirup(&arena, &tmp, 2); - result = result && output != nullptr && wapp_str8_equal(output, &expected); + result = result && output != nullptr && wpStr8Equal(output, &expected); wapp_mem_arena_allocator_destroy(&arena); diff --git a/tests/file/test_file.c b/tests/file/test_file.c index cfab56f..09aa20a 100644 --- a/tests/file/test_file.c +++ b/tests/file/test_file.c @@ -4,8 +4,8 @@ #define DST_CAPACITY 5 wp_intern Allocator arena = {0}; -wp_intern WpStr8RO test_filename = wapp_str8_lit_ro_initialiser_list("wapptest.bin"); -wp_intern WpStr8RO new_filename = wapp_str8_lit_ro_initialiser_list("wapptest2.bin"); +wp_intern WpStr8RO test_filename = wpStr8LitRoInitialiserList("wapptest.bin"); +wp_intern WpStr8RO new_filename = wpStr8LitRoInitialiserList("wapptest2.bin"); wp_intern WFile *test_fp = NULL; wp_intern I32Array src_array1 = wapp_array(i32, 0, 1, 2, 3, 4); wp_intern I32Array src_array2 = wapp_array(i32, 5, 6, 7, 8, 9); diff --git a/tests/file/test_file.cc b/tests/file/test_file.cc index 43e7008..0e61fe1 100644 --- a/tests/file/test_file.cc +++ b/tests/file/test_file.cc @@ -4,8 +4,8 @@ #define DST_CAPACITY 5 wp_intern Allocator arena = {}; -wp_intern WpStr8RO test_filename = wapp_str8_lit_ro_initialiser_list("wapptest.bin"); -wp_intern WpStr8RO new_filename = wapp_str8_lit_ro_initialiser_list("wapptest2.bin"); +wp_intern WpStr8RO test_filename = wpStr8LitRoInitialiserList("wapptest.bin"); +wp_intern WpStr8RO new_filename = wpStr8LitRoInitialiserList("wapptest2.bin"); wp_intern WFile *test_fp = NULL; wp_intern i32 dst_buf[DST_CAPACITY] = {0}; wp_intern I32Array src_array1; diff --git a/tests/shell_commander/test_shell_commander.c b/tests/shell_commander/test_shell_commander.c index 37e6693..ed1fc8d 100644 --- a/tests/shell_commander/test_shell_commander.c +++ b/tests/shell_commander/test_shell_commander.c @@ -6,8 +6,8 @@ WpTestFuncResult test_commander_cmd_success(void) { WpStr8List cmd = wapp_dbl_list(WpStr8); - wapp_dbl_list_push_back(WpStr8, &cmd, &wapp_str8_lit("echo")); - wapp_dbl_list_push_back(WpStr8, &cmd, &wapp_str8_lit("hello world")); + wapp_dbl_list_push_back(WpStr8, &cmd, &wpStr8Lit("echo")); + wapp_dbl_list_push_back(WpStr8, &cmd, &wpStr8Lit("hello world")); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS && @@ -18,7 +18,7 @@ WpTestFuncResult test_commander_cmd_success(void) { WpTestFuncResult test_commander_cmd_failure(void) { WpStr8List cmd = wapp_dbl_list(WpStr8); - wapp_dbl_list_push_back(WpStr8, &cmd, &wapp_str8_lit("grep")); + wapp_dbl_list_push_back(WpStr8, &cmd, &wpStr8Lit("grep")); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); b8 failed = result.exited && result.exit_code != EXIT_SUCCESS && @@ -28,35 +28,35 @@ WpTestFuncResult test_commander_cmd_failure(void) { } WpTestFuncResult test_commander_cmd_out_buf_success(void) { - WpStr8 buf = wapp_str8_buf(64); - WpStr8 expected = wapp_str8_buf(64); + WpStr8 buf = wpStr8Buf(64); + WpStr8 expected = wpStr8Buf(64); char msg[] = "hello world"; - wapp_str8_copy_cstr_capped(&expected, msg); + wpStr8CopyCstrCapped(&expected, msg); WpStr8List cmd = wapp_dbl_list(WpStr8); - wapp_dbl_list_push_back(WpStr8, &cmd, &wapp_str8_lit("echo")); - wapp_dbl_list_push_back(WpStr8, &cmd, &wapp_str8_lit(msg)); + wapp_dbl_list_push_back(WpStr8, &cmd, &wpStr8Lit("echo")); + wapp_dbl_list_push_back(WpStr8, &cmd, &wpStr8Lit(msg)); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS && - result.error == SHELL_ERR_NO_ERROR && wapp_str8_equal_to_count(&buf, &expected, strlen(msg)); + result.error == SHELL_ERR_NO_ERROR && wpStr8EqualToCount(&buf, &expected, strlen(msg)); return wpTesterResult(succeeded); } WpTestFuncResult test_commander_cmd_out_buf_failure(void) { - WpStr8 buf = wapp_str8_buf(4); - WpStr8 expected = wapp_str8_buf(64); + WpStr8 buf = wpStr8Buf(4); + WpStr8 expected = wpStr8Buf(64); char msg[] = "hello world"; - wapp_str8_copy_cstr_capped(&expected, msg); + wpStr8CopyCstrCapped(&expected, msg); WpStr8List cmd = wapp_dbl_list(WpStr8); - wapp_dbl_list_push_back(WpStr8, &cmd, &wapp_str8_lit("echo")); - wapp_dbl_list_push_back(WpStr8, &cmd, &wapp_str8_lit(msg)); + wapp_dbl_list_push_back(WpStr8, &cmd, &wpStr8Lit("echo")); + wapp_dbl_list_push_back(WpStr8, &cmd, &wpStr8Lit(msg)); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); b8 failed = !result.exited && result.exit_code != EXIT_SUCCESS && - result.error == SHELL_ERR_OUT_BUF_FULL && !wapp_str8_equal(&buf, &expected); + result.error == SHELL_ERR_OUT_BUF_FULL && !wpStr8Equal(&buf, &expected); return wpTesterResult(failed); } diff --git a/tests/shell_commander/test_shell_commander.cc b/tests/shell_commander/test_shell_commander.cc index 0ab2c27..2f2e870 100644 --- a/tests/shell_commander/test_shell_commander.cc +++ b/tests/shell_commander/test_shell_commander.cc @@ -6,8 +6,8 @@ WpTestFuncResult test_commander_cmd_success(void) { WpStr8List cmd = wapp_dbl_list(WpStr8); - WpStr8 echo = wapp_str8_lit("echo"); - WpStr8 msg = wapp_str8_lit("hello world"); + WpStr8 echo = wpStr8Lit("echo"); + WpStr8 msg = wpStr8Lit("hello world"); wapp_dbl_list_push_back(WpStr8, &cmd, &echo); wapp_dbl_list_push_back(WpStr8, &cmd, &msg); @@ -20,7 +20,7 @@ WpTestFuncResult test_commander_cmd_success(void) { WpTestFuncResult test_commander_cmd_failure(void) { WpStr8List cmd = wapp_dbl_list(WpStr8); - WpStr8 grep = wapp_str8_lit("grep"); + WpStr8 grep = wpStr8Lit("grep"); wapp_dbl_list_push_back(WpStr8, &cmd, &grep); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, nullptr, &cmd); @@ -31,39 +31,39 @@ WpTestFuncResult test_commander_cmd_failure(void) { } WpTestFuncResult test_commander_cmd_out_buf_success(void) { - WpStr8 buf = wapp_str8_buf(64); - WpStr8 expected = wapp_str8_buf(64); + WpStr8 buf = wpStr8Buf(64); + WpStr8 expected = wpStr8Buf(64); char msg[] = "hello world"; - wapp_str8_copy_cstr_capped(&expected, msg); + wpStr8CopyCstrCapped(&expected, msg); WpStr8List cmd = wapp_dbl_list(WpStr8); - WpStr8 echo = wapp_str8_lit("echo"); - WpStr8 arg = wapp_str8_lit(msg); + WpStr8 echo = wpStr8Lit("echo"); + WpStr8 arg = wpStr8Lit(msg); wapp_dbl_list_push_back(WpStr8, &cmd, &echo); wapp_dbl_list_push_back(WpStr8, &cmd, &arg); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS && - result.error == SHELL_ERR_NO_ERROR && wapp_str8_equal_to_count(&buf, &expected, strlen(msg)); + result.error == SHELL_ERR_NO_ERROR && wpStr8EqualToCount(&buf, &expected, strlen(msg)); return wpTesterResult(succeeded); } WpTestFuncResult test_commander_cmd_out_buf_failure(void) { - WpStr8 buf = wapp_str8_buf(4); - WpStr8 expected = wapp_str8_buf(64); + WpStr8 buf = wpStr8Buf(4); + WpStr8 expected = wpStr8Buf(64); char msg[] = "hello world"; - wapp_str8_copy_cstr_capped(&expected, msg); + wpStr8CopyCstrCapped(&expected, msg); WpStr8List cmd = wapp_dbl_list(WpStr8); - WpStr8 echo = wapp_str8_lit("echo"); - WpStr8 arg = wapp_str8_lit(msg); + WpStr8 echo = wpStr8Lit("echo"); + WpStr8 arg = wpStr8Lit(msg); wapp_dbl_list_push_back(WpStr8, &cmd, &echo); wapp_dbl_list_push_back(WpStr8, &cmd, &arg); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); b8 failed = !result.exited && result.exit_code != EXIT_SUCCESS && - result.error == SHELL_ERR_OUT_BUF_FULL && !wapp_str8_equal(&buf, &expected); + result.error == SHELL_ERR_OUT_BUF_FULL && !wpStr8Equal(&buf, &expected); return wpTesterResult(failed); } diff --git a/tests/str8/test_str8.c b/tests/str8/test_str8.c index 7f9c644..162b32c 100644 --- a/tests/str8/test_str8.c +++ b/tests/str8/test_str8.c @@ -6,25 +6,25 @@ WpTestFuncResult test_str8_lit(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("Hello world"); + WpStr8 s1 = wpStr8Lit("Hello world"); result = s1.capacity == 22 && s1.capacity != s1.size; - WpStr8 s2 = wapp_str8_lit("Different strokes for different folks"); + WpStr8 s2 = wpStr8Lit("Different strokes for different folks"); result = result && s2.capacity == 74 && s2.capacity != s2.size; - WpStr8 s3 = wapp_str8_lit("Discretion is the better part of valour"); + WpStr8 s3 = wpStr8Lit("Discretion is the better part of valour"); result = result && s3.capacity == 78 && s3.capacity != s3.size; - WpStr8 s4 = wapp_str8_lit("Distance lends enchantment to the view"); + WpStr8 s4 = wpStr8Lit("Distance lends enchantment to the view"); result = result && s4.capacity == 76 && s4.capacity != s4.size; - WpStr8 s5 = wapp_str8_lit("Do as I say, not as I do"); + WpStr8 s5 = wpStr8Lit("Do as I say, not as I do"); result = result && s5.capacity == 48 && s5.capacity != s5.size; - WpStr8 s6 = wapp_str8_lit("Do as you would be done by"); + WpStr8 s6 = wpStr8Lit("Do as you would be done by"); result = result && s6.capacity == 52 && s6.capacity != s6.size; - WpStr8 s7 = wapp_str8_lit("Do unto others as you would have them do to you"); + WpStr8 s7 = wpStr8Lit("Do unto others as you would have them do to you"); result = result && s7.capacity == 94 && s7.capacity != s7.size; return wpTesterResult(result); @@ -33,25 +33,25 @@ WpTestFuncResult test_str8_lit(void) { WpTestFuncResult test_str8_lit_ro(void) { b8 result; - WpStr8RO s1 = wapp_str8_lit_ro("Hello world"); + WpStr8RO s1 = wpStr8LitRo("Hello world"); result = s1.capacity == 11 && s1.capacity == s1.size; - WpStr8RO s2 = wapp_str8_lit_ro("Different strokes for different folks"); + WpStr8RO s2 = wpStr8LitRo("Different strokes for different folks"); result = result && s2.capacity == 37 && s2.capacity == s2.size; - WpStr8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour"); + WpStr8RO s3 = wpStr8LitRo("Discretion is the better part of valour"); result = result && s3.capacity == 39 && s3.capacity == s3.size; - WpStr8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view"); + WpStr8RO s4 = wpStr8LitRo("Distance lends enchantment to the view"); result = result && s4.capacity == 38 && s4.capacity == s4.size; - WpStr8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do"); + WpStr8RO s5 = wpStr8LitRo("Do as I say, not as I do"); result = result && s5.capacity == 24 && s5.capacity == s5.size; - WpStr8RO s6 = wapp_str8_lit_ro("Do as you would be done by"); + WpStr8RO s6 = wpStr8LitRo("Do as you would be done by"); result = result && s6.capacity == 26 && s6.capacity == s6.size; - WpStr8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you"); + WpStr8RO s7 = wpStr8LitRo("Do unto others as you would have them do to you"); result = result && s7.capacity == 47 && s7.capacity == s7.size; return wpTesterResult(result); @@ -60,16 +60,16 @@ WpTestFuncResult test_str8_lit_ro(void) { WpTestFuncResult test_str8_buf(void) { b8 result; - WpStr8 s1 = wapp_str8_buf(1024); + WpStr8 s1 = wpStr8Buf(1024); result = s1.capacity == 1024 && s1.size == 0; - WpStr8 s2 = wapp_str8_buf(2048); + WpStr8 s2 = wpStr8Buf(2048); result = result && s2.capacity == 2048 && s2.size == 0; - WpStr8 s3 = wapp_str8_buf(4096); + WpStr8 s3 = wpStr8Buf(4096); result = result && s3.capacity == 4096 && s3.size == 0; - WpStr8 s4 = wapp_str8_buf(8192); + WpStr8 s4 = wpStr8Buf(8192); result = result && s4.capacity == 8192 && s4.size == 0; return wpTesterResult(result); @@ -84,7 +84,7 @@ WpTestFuncResult test_str8_alloc_buf(void) { u64 capacity = 4096; - WpStr8 *s = wapp_str8_alloc_buf(&allocator, capacity); + WpStr8 *s = wpStr8AllocBuf(&allocator, capacity); if (!s) { result = false; goto TEST_ALLOC_BUF_CLEANUP; @@ -93,7 +93,7 @@ WpTestFuncResult test_str8_alloc_buf(void) { result = s->capacity == capacity; const char *cstr = "My name is Abdelrahman"; - wapp_str8_copy_cstr_capped(s, cstr); + wpStr8CopyCstrCapped(s, cstr); result = result && s->capacity == capacity && s->size == strlen(cstr) && memcmp(s->buf, cstr, s->size) == 0; @@ -112,7 +112,7 @@ WpTestFuncResult test_str8_alloc_cstr(void) { char *str = "Abdelrahman"; u64 length = strlen(str); - WpStr8 *s = wapp_str8_alloc_cstr(&allocator, str); + WpStr8 *s = wpStr8AllocCstr(&allocator, str); if (!s) { return wpTesterResult(false); } @@ -131,13 +131,13 @@ WpTestFuncResult test_str8_alloc_str8(void) { return wpTesterResult(false); } - WpStr8 str = wapp_str8_lit("Abdelrahman"); - WpStr8 *s = wapp_str8_alloc_str8(&allocator, &str); + WpStr8 str = wpStr8Lit("Abdelrahman"); + WpStr8 *s = wpStr8AllocStr8(&allocator, &str); if (!s) { return wpTesterResult(false); } - result = wapp_str8_equal(s, &str); + result = wpStr8Equal(s, &str); wapp_mem_arena_allocator_destroy(&allocator); @@ -151,8 +151,8 @@ WpTestFuncResult test_str8_alloc_substr(void) { return wpTesterResult(false); } - WpStr8 str = wapp_str8_lit("Abdelrahman"); - WpStr8 *s = wapp_str8_alloc_substr(&allocator, &str, 3, 8); + WpStr8 str = wpStr8Lit("Abdelrahman"); + WpStr8 *s = wpStr8AllocSubstr(&allocator, &str, 3, 8); if (!s) { return wpTesterResult(false); } @@ -167,66 +167,66 @@ WpTestFuncResult test_str8_alloc_substr(void) { WpTestFuncResult test_str8_get_index_within_bounds(void) { b8 result; - WpStr8RO s1 = wapp_str8_lit_ro("Hello world"); - result = wapp_str8_get(&s1, 4) == 'o'; + WpStr8RO s1 = wpStr8LitRo("Hello world"); + result = wpStr8Get(&s1, 4) == 'o'; - WpStr8RO s2 = wapp_str8_lit_ro("Different strokes for different folks"); - result = result && wapp_str8_get(&s2, 0) == 'D'; + WpStr8RO s2 = wpStr8LitRo("Different strokes for different folks"); + result = result && wpStr8Get(&s2, 0) == 'D'; - WpStr8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour"); - result = result && wapp_str8_get(&s3, 13) == ' '; + WpStr8RO s3 = wpStr8LitRo("Discretion is the better part of valour"); + result = result && wpStr8Get(&s3, 13) == ' '; - WpStr8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view"); - result = result && wapp_str8_get(&s4, 20) == 'n'; + WpStr8RO s4 = wpStr8LitRo("Distance lends enchantment to the view"); + result = result && wpStr8Get(&s4, 20) == 'n'; - WpStr8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do"); - result = result && wapp_str8_get(&s5, 11) == ','; + WpStr8RO s5 = wpStr8LitRo("Do as I say, not as I do"); + result = result && wpStr8Get(&s5, 11) == ','; - WpStr8RO s6 = wapp_str8_lit_ro("Do as you would be done by"); - result = result && wapp_str8_get(&s6, 25) == 'y'; + WpStr8RO s6 = wpStr8LitRo("Do as you would be done by"); + result = result && wpStr8Get(&s6, 25) == 'y'; - WpStr8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you"); - result = result && wapp_str8_get(&s7, 16) == 's'; + WpStr8RO s7 = wpStr8LitRo("Do unto others as you would have them do to you"); + result = result && wpStr8Get(&s7, 16) == 's'; return wpTesterResult(result); } WpTestFuncResult test_str8_get_index_out_of_bounds(void) { - WpStr8 s1 = wapp_str8_lit("Hello world"); - b8 result = wapp_str8_get(&s1, 20) == '\0'; + WpStr8 s1 = wpStr8Lit("Hello world"); + b8 result = wpStr8Get(&s1, 20) == '\0'; return wpTesterResult(result); } WpTestFuncResult test_str8_set(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("Hello world"); - wapp_str8_set(&s1, 4, 'f'); - result = wapp_str8_get(&s1, 4) == 'f'; + WpStr8 s1 = wpStr8Lit("Hello world"); + wpStr8Set(&s1, 4, 'f'); + result = wpStr8Get(&s1, 4) == 'f'; - WpStr8 s2 = wapp_str8_lit("Different strokes for different folks"); - wapp_str8_set(&s2, 0, 'A'); - result = result && wapp_str8_get(&s2, 0) == 'A'; + WpStr8 s2 = wpStr8Lit("Different strokes for different folks"); + wpStr8Set(&s2, 0, 'A'); + result = result && wpStr8Get(&s2, 0) == 'A'; - WpStr8 s3 = wapp_str8_lit("Discretion is the better part of valour"); - wapp_str8_set(&s3, 13, 'u'); - result = result && wapp_str8_get(&s3, 13) == 'u'; + WpStr8 s3 = wpStr8Lit("Discretion is the better part of valour"); + wpStr8Set(&s3, 13, 'u'); + result = result && wpStr8Get(&s3, 13) == 'u'; - WpStr8 s4 = wapp_str8_lit("Distance lends enchantment to the view"); - wapp_str8_set(&s4, 20, 'R'); - result = result && wapp_str8_get(&s4, 20) == 'R'; + WpStr8 s4 = wpStr8Lit("Distance lends enchantment to the view"); + wpStr8Set(&s4, 20, 'R'); + result = result && wpStr8Get(&s4, 20) == 'R'; - WpStr8 s5 = wapp_str8_lit("Do as I say, not as I do"); - wapp_str8_set(&s5, 11, '.'); - result = result && wapp_str8_get(&s5, 11) == '.'; + WpStr8 s5 = wpStr8Lit("Do as I say, not as I do"); + wpStr8Set(&s5, 11, '.'); + result = result && wpStr8Get(&s5, 11) == '.'; - WpStr8 s6 = wapp_str8_lit("Do as you would be done by"); - wapp_str8_set(&s6, 25, 'w'); - result = result && wapp_str8_get(&s6, 25) == 'w'; + WpStr8 s6 = wpStr8Lit("Do as you would be done by"); + wpStr8Set(&s6, 25, 'w'); + result = result && wpStr8Get(&s6, 25) == 'w'; - WpStr8 s7 = wapp_str8_lit("Do unto others as you would have them do to you"); - wapp_str8_set(&s7, 16, 'i'); - result = result && wapp_str8_get(&s7, 16) == 'i'; + WpStr8 s7 = wpStr8Lit("Do unto others as you would have them do to you"); + wpStr8Set(&s7, 16, 'i'); + result = result && wpStr8Get(&s7, 16) == 'i'; return wpTesterResult(result); } @@ -234,21 +234,21 @@ WpTestFuncResult test_str8_set(void) { WpTestFuncResult test_str8_push_back(void) { b8 result; - WpStr8 expected = wapp_str8_lit("Abdelrahman"); - WpStr8 buf = wapp_str8_buf(64); - wapp_str8_push_back(&buf, 'A'); - wapp_str8_push_back(&buf, 'b'); - wapp_str8_push_back(&buf, 'd'); - wapp_str8_push_back(&buf, 'e'); - wapp_str8_push_back(&buf, 'l'); - wapp_str8_push_back(&buf, 'r'); - wapp_str8_push_back(&buf, 'a'); - wapp_str8_push_back(&buf, 'h'); - wapp_str8_push_back(&buf, 'm'); - wapp_str8_push_back(&buf, 'a'); - wapp_str8_push_back(&buf, 'n'); + WpStr8 expected = wpStr8Lit("Abdelrahman"); + WpStr8 buf = wpStr8Buf(64); + wpStr8PushBack(&buf, 'A'); + wpStr8PushBack(&buf, 'b'); + wpStr8PushBack(&buf, 'd'); + wpStr8PushBack(&buf, 'e'); + wpStr8PushBack(&buf, 'l'); + wpStr8PushBack(&buf, 'r'); + wpStr8PushBack(&buf, 'a'); + wpStr8PushBack(&buf, 'h'); + wpStr8PushBack(&buf, 'm'); + wpStr8PushBack(&buf, 'a'); + wpStr8PushBack(&buf, 'n'); - result = wapp_str8_equal(&buf, &expected); + result = wpStr8Equal(&buf, &expected); return wpTesterResult(result); } @@ -256,32 +256,32 @@ WpTestFuncResult test_str8_push_back(void) { WpTestFuncResult test_str8_equal(void) { b8 result; - WpStr8RO s1 = wapp_str8_lit_ro("hello"); - WpStr8RO s2 = wapp_str8_lit_ro("hell"); - WpStr8RO s3 = wapp_str8_lit_ro("hello"); - WpStr8RO s4 = wapp_str8_lit_ro("goodbye"); + WpStr8RO s1 = wpStr8LitRo("hello"); + WpStr8RO s2 = wpStr8LitRo("hell"); + WpStr8RO s3 = wpStr8LitRo("hello"); + WpStr8RO s4 = wpStr8LitRo("goodbye"); - result = wapp_str8_equal(&s1, &s2) == false; - result = result && wapp_str8_equal(&s1, &s3) == true; - result = result && wapp_str8_equal(&s1, &s4) == false; + result = wpStr8Equal(&s1, &s2) == false; + result = result && wpStr8Equal(&s1, &s3) == true; + result = result && wpStr8Equal(&s1, &s4) == false; return wpTesterResult(result); } WpTestFuncResult test_str8_slice(void) { b8 result; - WpStr8 s = wapp_str8_lit("Different strokes for different folks"); + WpStr8 s = wpStr8Lit("Different strokes for different folks"); - WpStr8RO sub1 = wapp_str8_slice(&s, 3, 9); + WpStr8RO sub1 = wpStr8Slice(&s, 3, 9); result = sub1.size == 6 && sub1.capacity == 6; - WpStr8RO sub2 = wapp_str8_slice(&s, 18, 21); + WpStr8RO sub2 = wpStr8Slice(&s, 18, 21); result = result && sub2.size == 3 && sub2.capacity == 3; - WpStr8RO sub3 = wapp_str8_slice(&s, 5, 1); + WpStr8RO sub3 = wpStr8Slice(&s, 5, 1); result = result && sub3.size == 0 && sub3.capacity == 0; - WpStr8RO sub4 = wapp_str8_slice(&s, 70, 80); + WpStr8RO sub4 = wpStr8Slice(&s, 70, 80); result = result && sub4.size == 0 && sub4.capacity == 0; return wpTesterResult(result); @@ -291,19 +291,19 @@ WpTestFuncResult test_str8_alloc_concat(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("Hello world"); - WpStr8 suffix1 = wapp_str8_lit(" from me."); - WpStr8 suffix2 = wapp_str8_lit(" This is my code."); - WpStr8 concat1 = wapp_str8_lit("Hello world from me."); - WpStr8 concat2 = wapp_str8_lit("Hello world from me. This is my code."); + WpStr8 str = wpStr8Lit("Hello world"); + WpStr8 suffix1 = wpStr8Lit(" from me."); + WpStr8 suffix2 = wpStr8Lit(" This is my code."); + WpStr8 concat1 = wpStr8Lit("Hello world from me."); + WpStr8 concat2 = wpStr8Lit("Hello world from me. This is my code."); WpStr8 *output; - output = wapp_str8_alloc_concat(&arena, &str, &suffix1); - result = output->size == concat1.size && wapp_str8_equal(output, &concat1); + output = wpStr8AllocConcat(&arena, &str, &suffix1); + result = output->size == concat1.size && wpStr8Equal(output, &concat1); - output = wapp_str8_alloc_concat(&arena, output, &suffix2); - result = result && output->size == concat2.size && wapp_str8_equal(output, &concat2); + output = wpStr8AllocConcat(&arena, output, &suffix2); + result = result && output->size == concat2.size && wpStr8Equal(output, &concat2); wapp_mem_arena_allocator_destroy(&arena); @@ -313,17 +313,17 @@ WpTestFuncResult test_str8_alloc_concat(void) { WpTestFuncResult test_str8_concat_capped(void) { b8 result; - WpStr8 str = wapp_str8_lit("Hello world"); - WpStr8 suffix1 = wapp_str8_lit(" from me."); - WpStr8 suffix2 = wapp_str8_lit(" This is my code."); - WpStr8 concat1 = wapp_str8_lit("Hello world from me."); - WpStr8 concat2 = wapp_str8_lit("Hello world from me. T"); + WpStr8 str = wpStr8Lit("Hello world"); + WpStr8 suffix1 = wpStr8Lit(" from me."); + WpStr8 suffix2 = wpStr8Lit(" This is my code."); + WpStr8 concat1 = wpStr8Lit("Hello world from me."); + WpStr8 concat2 = wpStr8Lit("Hello world from me. T"); - wapp_str8_concat_capped(&str, &suffix1); - result = str.size == concat1.size && wapp_str8_equal(&str, &concat1); + wpStr8ConcatCapped(&str, &suffix1); + result = str.size == concat1.size && wpStr8Equal(&str, &concat1); - wapp_str8_concat_capped(&str, &suffix2); - result = result && str.size == concat2.size && wapp_str8_equal(&str, &concat2); + wpStr8ConcatCapped(&str, &suffix2); + result = result && str.size == concat2.size && wpStr8Equal(&str, &concat2); return wpTesterResult(result); } @@ -331,17 +331,17 @@ WpTestFuncResult test_str8_concat_capped(void) { WpTestFuncResult test_str8_copy_cstr_capped(void) { b8 result; - WpStr8 buf = wapp_str8_buf(32); + WpStr8 buf = wpStr8Buf(32); const char *src1 = "Hello world"; const char *src2 = "Hello world from the Wizard Apprentice standard library"; - WpStr8RO src1_cp = wapp_str8_lit_ro("Hello world"); - WpStr8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr"); + WpStr8RO src1_cp = wpStr8LitRo("Hello world"); + WpStr8RO src2_cp = wpStr8LitRo("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); + wpStr8CopyCstrCapped(&buf, src1); + result = buf.size == src1_cp.size && wpStr8Equal(&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); + wpStr8CopyCstrCapped(&buf, src2); + result = result && buf.size == src2_cp.size && buf.size == buf.capacity && wpStr8Equal(&buf, &src2_cp); return wpTesterResult(result); } @@ -349,16 +349,16 @@ WpTestFuncResult test_str8_copy_cstr_capped(void) { WpTestFuncResult test_str8_copy_str8_capped(void) { b8 result; - WpStr8 buf = wapp_str8_buf(32); - WpStr8RO src1 = wapp_str8_lit_ro("Hello world"); - WpStr8RO src2 = wapp_str8_lit_ro("Hello world from the Wizard Apprentice standard library"); - WpStr8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr"); + WpStr8 buf = wpStr8Buf(32); + WpStr8RO src1 = wpStr8LitRo("Hello world"); + WpStr8RO src2 = wpStr8LitRo("Hello world from the Wizard Apprentice standard library"); + WpStr8RO src2_cp = wpStr8LitRo("Hello world from the Wizard Appr"); - wapp_str8_copy_str8_capped(&buf, &src1); - result = buf.size == src1.size && wapp_str8_equal(&buf, &src1); + wpStr8CopyStr8Capped(&buf, &src1); + result = buf.size == src1.size && wpStr8Equal(&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); + wpStr8CopyStr8Capped(&buf, &src2); + result = result && buf.size < src2.size && buf.size == buf.capacity && wpStr8Equal(&buf, &src2_cp); return wpTesterResult(result); } @@ -366,44 +366,44 @@ WpTestFuncResult test_str8_copy_str8_capped(void) { WpTestFuncResult test_str8_format(void) { b8 result; - WpStr8 buf = wapp_str8_buf(128); - WpStr8 expected = wapp_str8_lit("My name is Abdelrahman and I am 35 years old"); + WpStr8 buf = wpStr8Buf(128); + WpStr8 expected = wpStr8Lit("My name is Abdelrahman and I am 35 years old"); - wapp_str8_format(&buf, "My name is %s and I am %u years old", "Abdelrahman", 35); + wpStr8Format(&buf, "My name is %s and I am %u years old", "Abdelrahman", 35); - result = wapp_str8_equal(&buf, &expected); + result = wpStr8Equal(&buf, &expected); return wpTesterResult(result); } WpTestFuncResult test_str8_find(void) { b8 result; - WpStr8RO s = wapp_str8_lit("Do as I say, not as I do"); + WpStr8RO s = wpStr8Lit("Do as I say, not as I do"); - 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 = wpStr8Find(&s, wpStr8LitRo("d")) != -1; + result = result && (wpStr8Find(&s, wpStr8LitRo("not")) != -1); + result = result && (wpStr8Find(&s, wpStr8LitRo("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); + result = result && (wpStr8Find(&s, wpStr8LitRo("f")) == -1); + result = result && (wpStr8Find(&s, wpStr8LitRo("hello")) == -1); + result = result && (wpStr8Find(&s, wpStr8LitRo("not sa I")) == -1); + result = result && (wpStr8Find(&s, wpStr8LitRo("Do unto others as you would have them do to you")) == -1); return wpTesterResult(result); } WpTestFuncResult test_str8_rfind(void) { b8 result; - WpStr8RO s = wapp_str8_lit("Do as I say, not as I do"); + WpStr8RO s = wpStr8Lit("Do as I say, not as I do"); - 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 = wpStr8Rfind(&s, wpStr8LitRo("d")) != -1; + result = result && (wpStr8Rfind(&s, wpStr8LitRo("not")) != -1); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("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); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("f")) == -1); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("hello")) == -1); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("not sa I")) == -1); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("Do unto others as you would have them do to you")) == -1); return wpTesterResult(result); } @@ -412,21 +412,21 @@ WpTestFuncResult test_str8_split(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim1 = wapp_str8_lit(" "); - WpStr8 delim2 = wapp_str8_lit("from"); - WpStr8List *list1 = wapp_str8_split(&arena, &str, &delim1); - WpStr8List *list2 = wapp_str8_split(&arena, &str, &delim2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim1 = wpStr8Lit(" "); + WpStr8 delim2 = wpStr8Lit("from"); + WpStr8List *list1 = wpStr8Split(&arena, &str, &delim1); + WpStr8List *list2 = wpStr8Split(&arena, &str, &delim2); WpStr8RO splits1[] = { - wapp_str8_slice(&str, 0, 5), - wapp_str8_slice(&str, 6, 11), - wapp_str8_slice(&str, 12, 16), - wapp_str8_slice(&str, 17, 19), + wpStr8Slice(&str, 0, 5), + wpStr8Slice(&str, 6, 11), + wpStr8Slice(&str, 12, 16), + wpStr8Slice(&str, 17, 19), }; WpStr8RO splits2[] = { - wapp_str8_slice(&str, 0, 12), - wapp_str8_slice(&str, 16, 19), + wpStr8Slice(&str, 0, 12), + wpStr8Slice(&str, 16, 19), }; u64 index1 = 0; @@ -437,14 +437,14 @@ WpTestFuncResult test_str8_split(void) { u64 count2 = ARRLEN(splits2); b8 running2 = true; - result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3; - result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4; + result = list1->node_count == count1 && wpStr8ListTotalSize(list1) == str.size - 3; + result = result && list2->node_count == count2 && wpStr8ListTotalSize(list2) == str.size - 4; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running1) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list1, index1); - result = result && wapp_str8_equal(node, &(splits1[index1])); + result = result && wpStr8Equal(node, &(splits1[index1])); ++index1; running1 = index1 < count1; @@ -454,7 +454,7 @@ WpTestFuncResult test_str8_split(void) { // MSVC Spectre mitigation warnings while (running2) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list2, index2); - result = result && wapp_str8_equal(node, &(splits2[index2])); + result = result && wpStr8Equal(node, &(splits2[index2])); ++index2; running2 = index2 < count2; @@ -469,27 +469,27 @@ WpTestFuncResult test_str8_split_with_max(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim = wapp_str8_lit(" "); - WpStr8List *list = wapp_str8_split_with_max(&arena, &str, &delim, 2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim = wpStr8Lit(" "); + WpStr8List *list = wpStr8SplitWithMax(&arena, &str, &delim, 2); WpStr8RO splits[] = { - wapp_str8_slice(&str, 0, 5), - wapp_str8_slice(&str, 6, 11), - wapp_str8_slice(&str, 12, 19), + wpStr8Slice(&str, 0, 5), + wpStr8Slice(&str, 6, 11), + wpStr8Slice(&str, 12, 19), }; u64 index = 0; u64 count = ARRLEN(splits); b8 running = true; - result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2; + result = list->node_count == count && wpStr8ListTotalSize(list) == str.size - 2; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list, index); - result = result && wapp_str8_equal(node, &(splits[index])); + result = result && wpStr8Equal(node, &(splits[index])); ++index; running = index < count; @@ -504,21 +504,21 @@ WpTestFuncResult test_str8_rsplit(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim1 = wapp_str8_lit(" "); - WpStr8 delim2 = wapp_str8_lit("from"); - WpStr8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1); - WpStr8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim1 = wpStr8Lit(" "); + WpStr8 delim2 = wpStr8Lit("from"); + WpStr8List *list1 = wpStr8Rsplit(&arena, &str, &delim1); + WpStr8List *list2 = wpStr8Rsplit(&arena, &str, &delim2); WpStr8RO splits1[] = { - wapp_str8_slice(&str, 0, 5), - wapp_str8_slice(&str, 6, 11), - wapp_str8_slice(&str, 12, 16), - wapp_str8_slice(&str, 17, 19), + wpStr8Slice(&str, 0, 5), + wpStr8Slice(&str, 6, 11), + wpStr8Slice(&str, 12, 16), + wpStr8Slice(&str, 17, 19), }; WpStr8RO splits2[] = { - wapp_str8_slice(&str, 0, 12), - wapp_str8_slice(&str, 16, 19), + wpStr8Slice(&str, 0, 12), + wpStr8Slice(&str, 16, 19), }; u64 index1 = 0; @@ -529,14 +529,14 @@ WpTestFuncResult test_str8_rsplit(void) { u64 count2 = ARRLEN(splits2); b8 running2 = true; - result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3; - result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4; + result = list1->node_count == count1 && wpStr8ListTotalSize(list1) == str.size - 3; + result = result && list2->node_count == count2 && wpStr8ListTotalSize(list2) == str.size - 4; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running1) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list1, index1); - result = result && wapp_str8_equal(node, &(splits1[index1])); + result = result && wpStr8Equal(node, &(splits1[index1])); ++index1; running1 = index1 < count1; @@ -546,7 +546,7 @@ WpTestFuncResult test_str8_rsplit(void) { // MSVC Spectre mitigation warnings while (running2) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list2, index2); - result = result && wapp_str8_equal(node, &(splits2[index2])); + result = result && wpStr8Equal(node, &(splits2[index2])); ++index2; running2 = index2 < count2; @@ -561,27 +561,27 @@ WpTestFuncResult test_str8_rsplit_with_max(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim = wapp_str8_lit(" "); - WpStr8List *list = wapp_str8_rsplit_with_max(&arena, &str, &delim, 2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim = wpStr8Lit(" "); + WpStr8List *list = wpStr8RsplitWithMax(&arena, &str, &delim, 2); WpStr8RO splits[] = { - wapp_str8_slice(&str, 0, 11), - wapp_str8_slice(&str, 12, 16), - wapp_str8_slice(&str, 17, 19), + wpStr8Slice(&str, 0, 11), + wpStr8Slice(&str, 12, 16), + wpStr8Slice(&str, 17, 19), }; u64 index = 0; u64 count = ARRLEN(splits); b8 running = true; - result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2; + result = list->node_count == count && wpStr8ListTotalSize(list) == str.size - 2; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list, index); - result = result && wapp_str8_equal(node, &(splits[index])); + result = result && wpStr8Equal(node, &(splits[index])); ++index; running = index < count; @@ -596,16 +596,16 @@ WpTestFuncResult test_str8_join(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim1 = wapp_str8_lit(" "); - WpStr8 delim2 = wapp_str8_lit("from"); - WpStr8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1); - WpStr8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2); - WpStr8 *join1 = wapp_str8_join(&arena, list1, &delim1); - WpStr8 *join2 = wapp_str8_join(&arena, list2, &delim2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim1 = wpStr8Lit(" "); + WpStr8 delim2 = wpStr8Lit("from"); + WpStr8List *list1 = wpStr8Rsplit(&arena, &str, &delim1); + WpStr8List *list2 = wpStr8Rsplit(&arena, &str, &delim2); + WpStr8 *join1 = wpStr8Join(&arena, list1, &delim1); + WpStr8 *join2 = wpStr8Join(&arena, list2, &delim2); - result = join1->size == str.size && wapp_str8_equal(join1, &str); - result = result && join2->size == str.size && wapp_str8_equal(join2, &str); + result = join1->size == str.size && wpStr8Equal(join1, &str); + result = result && join2->size == str.size && wpStr8Equal(join2, &str); wapp_mem_arena_allocator_destroy(&arena); @@ -615,12 +615,12 @@ WpTestFuncResult test_str8_join(void) { WpTestFuncResult test_str8_from_bytes(void) { b8 result; - WpStr8 str = wapp_str8_buf(1024); + WpStr8 str = wpStr8Buf(1024); U8Array bytes = wapp_array(u8, 'W', 'A', 'P', 'P'); - wapp_str8_from_bytes(&str, bytes); + wpStr8FromBytes(&str, bytes); result = str.size == wapp_array_count(bytes) * wapp_array_item_size(bytes); - result = result && wapp_str8_equal(&str, &wapp_str8_lit_ro("WAPP")); + result = result && wpStr8Equal(&str, &wpStr8LitRo("WAPP")); return wpTesterResult(result); } diff --git a/tests/str8/test_str8.cc b/tests/str8/test_str8.cc index 88290ab..9b3bf57 100644 --- a/tests/str8/test_str8.cc +++ b/tests/str8/test_str8.cc @@ -6,25 +6,25 @@ WpTestFuncResult test_str8_lit(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("Hello world"); + WpStr8 s1 = wpStr8Lit("Hello world"); result = s1.capacity == 22 && s1.capacity != s1.size; - WpStr8 s2 = wapp_str8_lit("Different strokes for different folks"); + WpStr8 s2 = wpStr8Lit("Different strokes for different folks"); result = result && s2.capacity == 74 && s2.capacity != s2.size; - WpStr8 s3 = wapp_str8_lit("Discretion is the better part of valour"); + WpStr8 s3 = wpStr8Lit("Discretion is the better part of valour"); result = result && s3.capacity == 78 && s3.capacity != s3.size; - WpStr8 s4 = wapp_str8_lit("Distance lends enchantment to the view"); + WpStr8 s4 = wpStr8Lit("Distance lends enchantment to the view"); result = result && s4.capacity == 76 && s4.capacity != s4.size; - WpStr8 s5 = wapp_str8_lit("Do as I say, not as I do"); + WpStr8 s5 = wpStr8Lit("Do as I say, not as I do"); result = result && s5.capacity == 48 && s5.capacity != s5.size; - WpStr8 s6 = wapp_str8_lit("Do as you would be done by"); + WpStr8 s6 = wpStr8Lit("Do as you would be done by"); result = result && s6.capacity == 52 && s6.capacity != s6.size; - WpStr8 s7 = wapp_str8_lit("Do unto others as you would have them do to you"); + WpStr8 s7 = wpStr8Lit("Do unto others as you would have them do to you"); result = result && s7.capacity == 94 && s7.capacity != s7.size; return wpTesterResult(result); @@ -33,25 +33,25 @@ WpTestFuncResult test_str8_lit(void) { WpTestFuncResult test_str8_lit_ro(void) { b8 result; - WpStr8RO s1 = wapp_str8_lit_ro("Hello world"); + WpStr8RO s1 = wpStr8LitRo("Hello world"); result = s1.capacity == 11 && s1.capacity == s1.size; - WpStr8RO s2 = wapp_str8_lit_ro("Different strokes for different folks"); + WpStr8RO s2 = wpStr8LitRo("Different strokes for different folks"); result = result && s2.capacity == 37 && s2.capacity == s2.size; - WpStr8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour"); + WpStr8RO s3 = wpStr8LitRo("Discretion is the better part of valour"); result = result && s3.capacity == 39 && s3.capacity == s3.size; - WpStr8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view"); + WpStr8RO s4 = wpStr8LitRo("Distance lends enchantment to the view"); result = result && s4.capacity == 38 && s4.capacity == s4.size; - WpStr8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do"); + WpStr8RO s5 = wpStr8LitRo("Do as I say, not as I do"); result = result && s5.capacity == 24 && s5.capacity == s5.size; - WpStr8RO s6 = wapp_str8_lit_ro("Do as you would be done by"); + WpStr8RO s6 = wpStr8LitRo("Do as you would be done by"); result = result && s6.capacity == 26 && s6.capacity == s6.size; - WpStr8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you"); + WpStr8RO s7 = wpStr8LitRo("Do unto others as you would have them do to you"); result = result && s7.capacity == 47 && s7.capacity == s7.size; return wpTesterResult(result); @@ -60,16 +60,16 @@ WpTestFuncResult test_str8_lit_ro(void) { WpTestFuncResult test_str8_buf(void) { b8 result; - WpStr8 s1 = wapp_str8_buf(1024); + WpStr8 s1 = wpStr8Buf(1024); result = s1.capacity == 1024 && s1.size == 0; - WpStr8 s2 = wapp_str8_buf(2048); + WpStr8 s2 = wpStr8Buf(2048); result = result && s2.capacity == 2048 && s2.size == 0; - WpStr8 s3 = wapp_str8_buf(4096); + WpStr8 s3 = wpStr8Buf(4096); result = result && s3.capacity == 4096 && s3.size == 0; - WpStr8 s4 = wapp_str8_buf(8192); + WpStr8 s4 = wpStr8Buf(8192); result = result && s4.capacity == 8192 && s4.size == 0; return wpTesterResult(result); @@ -84,7 +84,7 @@ WpTestFuncResult test_str8_alloc_buf(void) { u64 capacity = 4096; - WpStr8 *s = wapp_str8_alloc_buf(&allocator, capacity); + WpStr8 *s = wpStr8AllocBuf(&allocator, capacity); if (!s) { result = false; wapp_mem_arena_allocator_destroy(&allocator); @@ -94,7 +94,7 @@ WpTestFuncResult test_str8_alloc_buf(void) { result = s->capacity == capacity; const char *cstr = "My name is Abdelrahman"; - wapp_str8_copy_cstr_capped(s, cstr); + wpStr8CopyCstrCapped(s, cstr); result = result && s->capacity == capacity && s->size == strlen(cstr) && memcmp(s->buf, cstr, s->size) == 0; @@ -112,7 +112,7 @@ WpTestFuncResult test_str8_alloc_cstr(void) { const char *str = "Abdelrahman"; u64 length = strlen(str); - WpStr8 *s = wapp_str8_alloc_cstr(&allocator, str); + WpStr8 *s = wpStr8AllocCstr(&allocator, str); if (!s) { return wpTesterResult(false); } @@ -131,13 +131,13 @@ WpTestFuncResult test_str8_alloc_str8(void) { return wpTesterResult(false); } - WpStr8 str = wapp_str8_lit("Abdelrahman"); - WpStr8 *s = wapp_str8_alloc_str8(&allocator, &str); + WpStr8 str = wpStr8Lit("Abdelrahman"); + WpStr8 *s = wpStr8AllocStr8(&allocator, &str); if (!s) { return wpTesterResult(false); } - result = wapp_str8_equal(s, &str); + result = wpStr8Equal(s, &str); wapp_mem_arena_allocator_destroy(&allocator); @@ -151,8 +151,8 @@ WpTestFuncResult test_str8_alloc_substr(void) { return wpTesterResult(false); } - WpStr8 str = wapp_str8_lit("Abdelrahman"); - WpStr8 *s = wapp_str8_alloc_substr(&allocator, &str, 3, 8); + WpStr8 str = wpStr8Lit("Abdelrahman"); + WpStr8 *s = wpStr8AllocSubstr(&allocator, &str, 3, 8); if (!s) { return wpTesterResult(false); } @@ -167,66 +167,66 @@ WpTestFuncResult test_str8_alloc_substr(void) { WpTestFuncResult test_str8_get_index_within_bounds(void) { b8 result; - WpStr8RO s1 = wapp_str8_lit_ro("Hello world"); - result = wapp_str8_get(&s1, 4) == 'o'; + WpStr8RO s1 = wpStr8LitRo("Hello world"); + result = wpStr8Get(&s1, 4) == 'o'; - WpStr8RO s2 = wapp_str8_lit_ro("Different strokes for different folks"); - result = result && wapp_str8_get(&s2, 0) == 'D'; + WpStr8RO s2 = wpStr8LitRo("Different strokes for different folks"); + result = result && wpStr8Get(&s2, 0) == 'D'; - WpStr8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour"); - result = result && wapp_str8_get(&s3, 13) == ' '; + WpStr8RO s3 = wpStr8LitRo("Discretion is the better part of valour"); + result = result && wpStr8Get(&s3, 13) == ' '; - WpStr8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view"); - result = result && wapp_str8_get(&s4, 20) == 'n'; + WpStr8RO s4 = wpStr8LitRo("Distance lends enchantment to the view"); + result = result && wpStr8Get(&s4, 20) == 'n'; - WpStr8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do"); - result = result && wapp_str8_get(&s5, 11) == ','; + WpStr8RO s5 = wpStr8LitRo("Do as I say, not as I do"); + result = result && wpStr8Get(&s5, 11) == ','; - WpStr8RO s6 = wapp_str8_lit_ro("Do as you would be done by"); - result = result && wapp_str8_get(&s6, 25) == 'y'; + WpStr8RO s6 = wpStr8LitRo("Do as you would be done by"); + result = result && wpStr8Get(&s6, 25) == 'y'; - WpStr8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you"); - result = result && wapp_str8_get(&s7, 16) == 's'; + WpStr8RO s7 = wpStr8LitRo("Do unto others as you would have them do to you"); + result = result && wpStr8Get(&s7, 16) == 's'; return wpTesterResult(result); } WpTestFuncResult test_str8_get_index_out_of_bounds(void) { - WpStr8 s1 = wapp_str8_lit("Hello world"); - b8 result = wapp_str8_get(&s1, 20) == '\0'; + WpStr8 s1 = wpStr8Lit("Hello world"); + b8 result = wpStr8Get(&s1, 20) == '\0'; return wpTesterResult(result); } WpTestFuncResult test_str8_set(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("Hello world"); - wapp_str8_set(&s1, 4, 'f'); - result = wapp_str8_get(&s1, 4) == 'f'; + WpStr8 s1 = wpStr8Lit("Hello world"); + wpStr8Set(&s1, 4, 'f'); + result = wpStr8Get(&s1, 4) == 'f'; - WpStr8 s2 = wapp_str8_lit("Different strokes for different folks"); - wapp_str8_set(&s2, 0, 'A'); - result = result && wapp_str8_get(&s2, 0) == 'A'; + WpStr8 s2 = wpStr8Lit("Different strokes for different folks"); + wpStr8Set(&s2, 0, 'A'); + result = result && wpStr8Get(&s2, 0) == 'A'; - WpStr8 s3 = wapp_str8_lit("Discretion is the better part of valour"); - wapp_str8_set(&s3, 13, 'u'); - result = result && wapp_str8_get(&s3, 13) == 'u'; + WpStr8 s3 = wpStr8Lit("Discretion is the better part of valour"); + wpStr8Set(&s3, 13, 'u'); + result = result && wpStr8Get(&s3, 13) == 'u'; - WpStr8 s4 = wapp_str8_lit("Distance lends enchantment to the view"); - wapp_str8_set(&s4, 20, 'R'); - result = result && wapp_str8_get(&s4, 20) == 'R'; + WpStr8 s4 = wpStr8Lit("Distance lends enchantment to the view"); + wpStr8Set(&s4, 20, 'R'); + result = result && wpStr8Get(&s4, 20) == 'R'; - WpStr8 s5 = wapp_str8_lit("Do as I say, not as I do"); - wapp_str8_set(&s5, 11, '.'); - result = result && wapp_str8_get(&s5, 11) == '.'; + WpStr8 s5 = wpStr8Lit("Do as I say, not as I do"); + wpStr8Set(&s5, 11, '.'); + result = result && wpStr8Get(&s5, 11) == '.'; - WpStr8 s6 = wapp_str8_lit("Do as you would be done by"); - wapp_str8_set(&s6, 25, 'w'); - result = result && wapp_str8_get(&s6, 25) == 'w'; + WpStr8 s6 = wpStr8Lit("Do as you would be done by"); + wpStr8Set(&s6, 25, 'w'); + result = result && wpStr8Get(&s6, 25) == 'w'; - WpStr8 s7 = wapp_str8_lit("Do unto others as you would have them do to you"); - wapp_str8_set(&s7, 16, 'i'); - result = result && wapp_str8_get(&s7, 16) == 'i'; + WpStr8 s7 = wpStr8Lit("Do unto others as you would have them do to you"); + wpStr8Set(&s7, 16, 'i'); + result = result && wpStr8Get(&s7, 16) == 'i'; return wpTesterResult(result); } @@ -234,21 +234,21 @@ WpTestFuncResult test_str8_set(void) { WpTestFuncResult test_str8_push_back(void) { b8 result; - WpStr8 expected = wapp_str8_lit("Abdelrahman"); - WpStr8 buf = wapp_str8_buf(64); - wapp_str8_push_back(&buf, 'A'); - wapp_str8_push_back(&buf, 'b'); - wapp_str8_push_back(&buf, 'd'); - wapp_str8_push_back(&buf, 'e'); - wapp_str8_push_back(&buf, 'l'); - wapp_str8_push_back(&buf, 'r'); - wapp_str8_push_back(&buf, 'a'); - wapp_str8_push_back(&buf, 'h'); - wapp_str8_push_back(&buf, 'm'); - wapp_str8_push_back(&buf, 'a'); - wapp_str8_push_back(&buf, 'n'); + WpStr8 expected = wpStr8Lit("Abdelrahman"); + WpStr8 buf = wpStr8Buf(64); + wpStr8PushBack(&buf, 'A'); + wpStr8PushBack(&buf, 'b'); + wpStr8PushBack(&buf, 'd'); + wpStr8PushBack(&buf, 'e'); + wpStr8PushBack(&buf, 'l'); + wpStr8PushBack(&buf, 'r'); + wpStr8PushBack(&buf, 'a'); + wpStr8PushBack(&buf, 'h'); + wpStr8PushBack(&buf, 'm'); + wpStr8PushBack(&buf, 'a'); + wpStr8PushBack(&buf, 'n'); - result = wapp_str8_equal(&buf, &expected); + result = wpStr8Equal(&buf, &expected); return wpTesterResult(result); } @@ -256,32 +256,32 @@ WpTestFuncResult test_str8_push_back(void) { WpTestFuncResult test_str8_equal(void) { b8 result; - WpStr8RO s1 = wapp_str8_lit_ro("hello"); - WpStr8RO s2 = wapp_str8_lit_ro("hell"); - WpStr8RO s3 = wapp_str8_lit_ro("hello"); - WpStr8RO s4 = wapp_str8_lit_ro("goodbye"); + WpStr8RO s1 = wpStr8LitRo("hello"); + WpStr8RO s2 = wpStr8LitRo("hell"); + WpStr8RO s3 = wpStr8LitRo("hello"); + WpStr8RO s4 = wpStr8LitRo("goodbye"); - result = wapp_str8_equal(&s1, &s2) == false; - result = result && wapp_str8_equal(&s1, &s3) == (b8)true; - result = result && wapp_str8_equal(&s1, &s4) == (b8)false; + result = wpStr8Equal(&s1, &s2) == false; + result = result && wpStr8Equal(&s1, &s3) == (b8)true; + result = result && wpStr8Equal(&s1, &s4) == (b8)false; return wpTesterResult(result); } WpTestFuncResult test_str8_slice(void) { b8 result; - WpStr8 s = wapp_str8_lit("Different strokes for different folks"); + WpStr8 s = wpStr8Lit("Different strokes for different folks"); - WpStr8RO sub1 = wapp_str8_slice(&s, 3, 9); + WpStr8RO sub1 = wpStr8Slice(&s, 3, 9); result = sub1.size == 6 && sub1.capacity == 6; - WpStr8RO sub2 = wapp_str8_slice(&s, 18, 21); + WpStr8RO sub2 = wpStr8Slice(&s, 18, 21); result = result && sub2.size == 3 && sub2.capacity == 3; - WpStr8RO sub3 = wapp_str8_slice(&s, 5, 1); + WpStr8RO sub3 = wpStr8Slice(&s, 5, 1); result = result && sub3.size == 0 && sub3.capacity == 0; - WpStr8RO sub4 = wapp_str8_slice(&s, 70, 80); + WpStr8RO sub4 = wpStr8Slice(&s, 70, 80); result = result && sub4.size == 0 && sub4.capacity == 0; return wpTesterResult(result); @@ -291,19 +291,19 @@ WpTestFuncResult test_str8_alloc_concat(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("Hello world"); - WpStr8 suffix1 = wapp_str8_lit(" from me."); - WpStr8 suffix2 = wapp_str8_lit(" This is my code."); - WpStr8 concat1 = wapp_str8_lit("Hello world from me."); - WpStr8 concat2 = wapp_str8_lit("Hello world from me. This is my code."); + WpStr8 str = wpStr8Lit("Hello world"); + WpStr8 suffix1 = wpStr8Lit(" from me."); + WpStr8 suffix2 = wpStr8Lit(" This is my code."); + WpStr8 concat1 = wpStr8Lit("Hello world from me."); + WpStr8 concat2 = wpStr8Lit("Hello world from me. This is my code."); WpStr8 *output; - output = wapp_str8_alloc_concat(&arena, &str, &suffix1); - result = output->size == concat1.size && wapp_str8_equal(output, &concat1); + output = wpStr8AllocConcat(&arena, &str, &suffix1); + result = output->size == concat1.size && wpStr8Equal(output, &concat1); - output = wapp_str8_alloc_concat(&arena, output, &suffix2); - result = result && output->size == concat2.size && wapp_str8_equal(output, &concat2); + output = wpStr8AllocConcat(&arena, output, &suffix2); + result = result && output->size == concat2.size && wpStr8Equal(output, &concat2); wapp_mem_arena_allocator_destroy(&arena); @@ -313,17 +313,17 @@ WpTestFuncResult test_str8_alloc_concat(void) { WpTestFuncResult test_str8_concat_capped(void) { b8 result; - WpStr8 str = wapp_str8_lit("Hello world"); - WpStr8 suffix1 = wapp_str8_lit(" from me."); - WpStr8 suffix2 = wapp_str8_lit(" This is my code."); - WpStr8 concat1 = wapp_str8_lit("Hello world from me."); - WpStr8 concat2 = wapp_str8_lit("Hello world from me. T"); + WpStr8 str = wpStr8Lit("Hello world"); + WpStr8 suffix1 = wpStr8Lit(" from me."); + WpStr8 suffix2 = wpStr8Lit(" This is my code."); + WpStr8 concat1 = wpStr8Lit("Hello world from me."); + WpStr8 concat2 = wpStr8Lit("Hello world from me. T"); - wapp_str8_concat_capped(&str, &suffix1); - result = str.size == concat1.size && wapp_str8_equal(&str, &concat1); + wpStr8ConcatCapped(&str, &suffix1); + result = str.size == concat1.size && wpStr8Equal(&str, &concat1); - wapp_str8_concat_capped(&str, &suffix2); - result = result && str.size == concat2.size && wapp_str8_equal(&str, &concat2); + wpStr8ConcatCapped(&str, &suffix2); + result = result && str.size == concat2.size && wpStr8Equal(&str, &concat2); return wpTesterResult(result); } @@ -331,17 +331,17 @@ WpTestFuncResult test_str8_concat_capped(void) { WpTestFuncResult test_str8_copy_cstr_capped(void) { b8 result; - WpStr8 buf = wapp_str8_buf(32); + WpStr8 buf = wpStr8Buf(32); const char *src1 = "Hello world"; const char *src2 = "Hello world from the Wizard Apprentice standard library"; - WpStr8RO src1_cp = wapp_str8_lit_ro("Hello world"); - WpStr8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr"); + WpStr8RO src1_cp = wpStr8LitRo("Hello world"); + WpStr8RO src2_cp = wpStr8LitRo("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); + wpStr8CopyCstrCapped(&buf, src1); + result = buf.size == src1_cp.size && wpStr8Equal(&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); + wpStr8CopyCstrCapped(&buf, src2); + result = result && buf.size == src2_cp.size && buf.size == buf.capacity && wpStr8Equal(&buf, &src2_cp); return wpTesterResult(result); } @@ -349,16 +349,16 @@ WpTestFuncResult test_str8_copy_cstr_capped(void) { WpTestFuncResult test_str8_copy_str8_capped(void) { b8 result; - WpStr8 buf = wapp_str8_buf(32); - WpStr8RO src1 = wapp_str8_lit_ro("Hello world"); - WpStr8RO src2 = wapp_str8_lit_ro("Hello world from the Wizard Apprentice standard library"); - WpStr8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr"); + WpStr8 buf = wpStr8Buf(32); + WpStr8RO src1 = wpStr8LitRo("Hello world"); + WpStr8RO src2 = wpStr8LitRo("Hello world from the Wizard Apprentice standard library"); + WpStr8RO src2_cp = wpStr8LitRo("Hello world from the Wizard Appr"); - wapp_str8_copy_str8_capped(&buf, &src1); - result = buf.size == src1.size && wapp_str8_equal(&buf, &src1); + wpStr8CopyStr8Capped(&buf, &src1); + result = buf.size == src1.size && wpStr8Equal(&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); + wpStr8CopyStr8Capped(&buf, &src2); + result = result && buf.size < src2.size && buf.size == buf.capacity && wpStr8Equal(&buf, &src2_cp); return wpTesterResult(result); } @@ -366,44 +366,44 @@ WpTestFuncResult test_str8_copy_str8_capped(void) { WpTestFuncResult test_str8_format(void) { b8 result; - WpStr8 buf = wapp_str8_buf(128); - WpStr8 expected = wapp_str8_lit("My name is Abdelrahman and I am 35 years old"); + WpStr8 buf = wpStr8Buf(128); + WpStr8 expected = wpStr8Lit("My name is Abdelrahman and I am 35 years old"); - wapp_str8_format(&buf, "My name is %s and I am %u years old", "Abdelrahman", 35); + wpStr8Format(&buf, "My name is %s and I am %u years old", "Abdelrahman", 35); - result = wapp_str8_equal(&buf, &expected); + result = wpStr8Equal(&buf, &expected); return wpTesterResult(result); } WpTestFuncResult test_str8_find(void) { b8 result; - WpStr8RO s = wapp_str8_lit("Do as I say, not as I do"); + WpStr8RO s = wpStr8Lit("Do as I say, not as I do"); - 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 = wpStr8Find(&s, wpStr8LitRo("d")) != -1; + result = result && (wpStr8Find(&s, wpStr8LitRo("not")) != -1); + result = result && (wpStr8Find(&s, wpStr8LitRo("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); + result = result && (wpStr8Find(&s, wpStr8LitRo("f")) == -1); + result = result && (wpStr8Find(&s, wpStr8LitRo("hello")) == -1); + result = result && (wpStr8Find(&s, wpStr8LitRo("not sa I")) == -1); + result = result && (wpStr8Find(&s, wpStr8LitRo("Do unto others as you would have them do to you")) == -1); return wpTesterResult(result); } WpTestFuncResult test_str8_rfind(void) { b8 result; - WpStr8RO s = wapp_str8_lit("Do as I say, not as I do"); + WpStr8RO s = wpStr8Lit("Do as I say, not as I do"); - 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 = wpStr8Rfind(&s, wpStr8LitRo("d")) != -1; + result = result && (wpStr8Rfind(&s, wpStr8LitRo("not")) != -1); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("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); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("f")) == -1); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("hello")) == -1); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("not sa I")) == -1); + result = result && (wpStr8Rfind(&s, wpStr8LitRo("Do unto others as you would have them do to you")) == -1); return wpTesterResult(result); } @@ -412,21 +412,21 @@ WpTestFuncResult test_str8_split(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim1 = wapp_str8_lit(" "); - WpStr8 delim2 = wapp_str8_lit("from"); - WpStr8List *list1 = wapp_str8_split(&arena, &str, &delim1); - WpStr8List *list2 = wapp_str8_split(&arena, &str, &delim2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim1 = wpStr8Lit(" "); + WpStr8 delim2 = wpStr8Lit("from"); + WpStr8List *list1 = wpStr8Split(&arena, &str, &delim1); + WpStr8List *list2 = wpStr8Split(&arena, &str, &delim2); WpStr8RO splits1[] = { - wapp_str8_slice(&str, 0, 5), - wapp_str8_slice(&str, 6, 11), - wapp_str8_slice(&str, 12, 16), - wapp_str8_slice(&str, 17, 19), + wpStr8Slice(&str, 0, 5), + wpStr8Slice(&str, 6, 11), + wpStr8Slice(&str, 12, 16), + wpStr8Slice(&str, 17, 19), }; WpStr8RO splits2[] = { - wapp_str8_slice(&str, 0, 12), - wapp_str8_slice(&str, 16, 19), + wpStr8Slice(&str, 0, 12), + wpStr8Slice(&str, 16, 19), }; u64 index1 = 0; @@ -437,14 +437,14 @@ WpTestFuncResult test_str8_split(void) { u64 count2 = ARRLEN(splits2); b8 running2 = true; - result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3; - result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4; + result = list1->node_count == count1 && wpStr8ListTotalSize(list1) == str.size - 3; + result = result && list2->node_count == count2 && wpStr8ListTotalSize(list2) == str.size - 4; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running1) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list1, index1); - result = result && wapp_str8_equal(node, &(splits1[index1])); + result = result && wpStr8Equal(node, &(splits1[index1])); ++index1; running1 = index1 < count1; @@ -454,7 +454,7 @@ WpTestFuncResult test_str8_split(void) { // MSVC Spectre mitigation warnings while (running2) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list2, index2); - result = result && wapp_str8_equal(node, &(splits2[index2])); + result = result && wpStr8Equal(node, &(splits2[index2])); ++index2; running2 = index2 < count2; @@ -469,27 +469,27 @@ WpTestFuncResult test_str8_split_with_max(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim = wapp_str8_lit(" "); - WpStr8List *list = wapp_str8_split_with_max(&arena, &str, &delim, 2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim = wpStr8Lit(" "); + WpStr8List *list = wpStr8SplitWithMax(&arena, &str, &delim, 2); WpStr8RO splits[] = { - wapp_str8_slice(&str, 0, 5), - wapp_str8_slice(&str, 6, 11), - wapp_str8_slice(&str, 12, 19), + wpStr8Slice(&str, 0, 5), + wpStr8Slice(&str, 6, 11), + wpStr8Slice(&str, 12, 19), }; u64 index = 0; u64 count = ARRLEN(splits); b8 running = true; - result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2; + result = list->node_count == count && wpStr8ListTotalSize(list) == str.size - 2; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list, index); - result = result && wapp_str8_equal(node, &(splits[index])); + result = result && wpStr8Equal(node, &(splits[index])); ++index; running = index < count; @@ -504,21 +504,21 @@ WpTestFuncResult test_str8_rsplit(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim1 = wapp_str8_lit(" "); - WpStr8 delim2 = wapp_str8_lit("from"); - WpStr8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1); - WpStr8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim1 = wpStr8Lit(" "); + WpStr8 delim2 = wpStr8Lit("from"); + WpStr8List *list1 = wpStr8Rsplit(&arena, &str, &delim1); + WpStr8List *list2 = wpStr8Rsplit(&arena, &str, &delim2); WpStr8RO splits1[] = { - wapp_str8_slice(&str, 0, 5), - wapp_str8_slice(&str, 6, 11), - wapp_str8_slice(&str, 12, 16), - wapp_str8_slice(&str, 17, 19), + wpStr8Slice(&str, 0, 5), + wpStr8Slice(&str, 6, 11), + wpStr8Slice(&str, 12, 16), + wpStr8Slice(&str, 17, 19), }; WpStr8RO splits2[] = { - wapp_str8_slice(&str, 0, 12), - wapp_str8_slice(&str, 16, 19), + wpStr8Slice(&str, 0, 12), + wpStr8Slice(&str, 16, 19), }; u64 index1 = 0; @@ -529,14 +529,14 @@ WpTestFuncResult test_str8_rsplit(void) { u64 count2 = ARRLEN(splits2); b8 running2 = true; - result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3; - result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4; + result = list1->node_count == count1 && wpStr8ListTotalSize(list1) == str.size - 3; + result = result && list2->node_count == count2 && wpStr8ListTotalSize(list2) == str.size - 4; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running1) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list1, index1); - result = result && wapp_str8_equal(node, &(splits1[index1])); + result = result && wpStr8Equal(node, &(splits1[index1])); ++index1; running1 = index1 < count1; @@ -546,7 +546,7 @@ WpTestFuncResult test_str8_rsplit(void) { // MSVC Spectre mitigation warnings while (running2) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list2, index2); - result = result && wapp_str8_equal(node, &(splits2[index2])); + result = result && wpStr8Equal(node, &(splits2[index2])); ++index2; running2 = index2 < count2; @@ -561,27 +561,27 @@ WpTestFuncResult test_str8_rsplit_with_max(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim = wapp_str8_lit(" "); - WpStr8List *list = wapp_str8_rsplit_with_max(&arena, &str, &delim, 2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim = wpStr8Lit(" "); + WpStr8List *list = wpStr8RsplitWithMax(&arena, &str, &delim, 2); WpStr8RO splits[] = { - wapp_str8_slice(&str, 0, 11), - wapp_str8_slice(&str, 12, 16), - wapp_str8_slice(&str, 17, 19), + wpStr8Slice(&str, 0, 11), + wpStr8Slice(&str, 12, 16), + wpStr8Slice(&str, 17, 19), }; u64 index = 0; u64 count = ARRLEN(splits); b8 running = true; - result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2; + result = list->node_count == count && wpStr8ListTotalSize(list) == str.size - 2; // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings while (running) { WpStr8 *node = wapp_dbl_list_get(WpStr8, list, index); - result = result && wapp_str8_equal(node, &(splits[index])); + result = result && wpStr8Equal(node, &(splits[index])); ++index; running = index < count; @@ -596,16 +596,16 @@ WpTestFuncResult test_str8_join(void) { b8 result; Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); - WpStr8 str = wapp_str8_lit("hello world from me"); - WpStr8 delim1 = wapp_str8_lit(" "); - WpStr8 delim2 = wapp_str8_lit("from"); - WpStr8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1); - WpStr8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2); - WpStr8 *join1 = wapp_str8_join(&arena, list1, &delim1); - WpStr8 *join2 = wapp_str8_join(&arena, list2, &delim2); + WpStr8 str = wpStr8Lit("hello world from me"); + WpStr8 delim1 = wpStr8Lit(" "); + WpStr8 delim2 = wpStr8Lit("from"); + WpStr8List *list1 = wpStr8Rsplit(&arena, &str, &delim1); + WpStr8List *list2 = wpStr8Rsplit(&arena, &str, &delim2); + WpStr8 *join1 = wpStr8Join(&arena, list1, &delim1); + WpStr8 *join2 = wpStr8Join(&arena, list2, &delim2); - result = join1->size == str.size && wapp_str8_equal(join1, &str); - result = result && join2->size == str.size && wapp_str8_equal(join2, &str); + result = join1->size == str.size && wpStr8Equal(join1, &str); + result = result && join2->size == str.size && wpStr8Equal(join2, &str); wapp_mem_arena_allocator_destroy(&arena); @@ -615,13 +615,13 @@ WpTestFuncResult test_str8_join(void) { WpTestFuncResult test_str8_from_bytes(void) { b8 result; - WpStr8 str = wapp_str8_buf(1024); - WpStr8 expected = wapp_str8_lit_ro("WAPP"); + WpStr8 str = wpStr8Buf(1024); + WpStr8 expected = wpStr8LitRo("WAPP"); U8Array bytes = wapp_array(u8, 'W', 'A', 'P', 'P'); - wapp_str8_from_bytes(&str, bytes); + wpStr8FromBytes(&str, bytes); result = str.size == wapp_array_count(bytes) * wapp_array_item_size(bytes); - result = result && wapp_str8_equal(&str, &expected); + result = result && wpStr8Equal(&str, &expected); return wpTesterResult(result); } diff --git a/tests/str8/test_str8_list.c b/tests/str8/test_str8_list.c index 0cbdb8e..ecc6da7 100644 --- a/tests/str8/test_str8_list.c +++ b/tests/str8/test_str8_list.c @@ -4,11 +4,11 @@ WpTestFuncResult test_str8_list_get(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -19,19 +19,19 @@ WpTestFuncResult test_str8_list_get(void) { wapp_dbl_list_push_back(WpStr8, &list, &s5); WpStr8 *node = wapp_dbl_list_get(WpStr8, &list, 0); - result = node == &s1 && wapp_str8_equal(node, &s1); + result = node == &s1 && wpStr8Equal(node, &s1); node = wapp_dbl_list_get(WpStr8, &list, 1); - result = result && node == &s2 && wapp_str8_equal(node, &s2); + result = result && node == &s2 && wpStr8Equal(node, &s2); node = wapp_dbl_list_get(WpStr8, &list, 2); - result = result && node == &s3 && wapp_str8_equal(node, &s3); + result = result && node == &s3 && wpStr8Equal(node, &s3); node = wapp_dbl_list_get(WpStr8, &list, 3); - result = result && node == &s4 && wapp_str8_equal(node, &s4); + result = result && node == &s4 && wpStr8Equal(node, &s4); node = wapp_dbl_list_get(WpStr8, &list, 4); - result = result && node == &s5 && wapp_str8_equal(node, &s5); + result = result && node == &s5 && wpStr8Equal(node, &s5); return wpTesterResult(result); } @@ -39,20 +39,20 @@ WpTestFuncResult test_str8_list_get(void) { WpTestFuncResult test_str8_list_push_front(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); WpStr8List list = wapp_dbl_list(WpStr8); wapp_dbl_list_push_front(WpStr8, &list, &s1); - result = list.first == list.last && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = list.first == list.last && list.first->item == &s1 && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; wapp_dbl_list_push_front(WpStr8, &list, &s2); - result = result && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && list.first->item == &s2 && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; wapp_dbl_list_push_front(WpStr8, &list, &s3); - result = result && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && list.first->item == &s3 && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; return wpTesterResult(result); } @@ -60,20 +60,20 @@ WpTestFuncResult test_str8_list_push_front(void) { WpTestFuncResult test_str8_list_push_back(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); WpStr8List list = wapp_dbl_list(WpStr8); wapp_dbl_list_push_back(WpStr8, &list, &s1); - result = list.first == list.last && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = list.first == list.last && list.last->item == &s1 && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; wapp_dbl_list_push_back(WpStr8, &list, &s2); - result = result && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && list.last->item == &s2 && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; wapp_dbl_list_push_back(WpStr8, &list, &s3); - result = result && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && list.last->item == &s3 && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; return wpTesterResult(result); } @@ -81,13 +81,13 @@ WpTestFuncResult test_str8_list_push_back(void) { WpTestFuncResult test_str8_list_insert(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); - WpStr8 s6 = wapp_str8_lit("6"); - WpStr8 s7 = wapp_str8_lit("7"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); + WpStr8 s6 = wpStr8Lit("6"); + WpStr8 s7 = wpStr8Lit("7"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -100,10 +100,10 @@ WpTestFuncResult test_str8_list_insert(void) { WpStr8 *node; wapp_dbl_list_insert(WpStr8, &list, &s6, 2); node = wapp_dbl_list_get(WpStr8, &list, 2); - result = node != NULL && node == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6; + result = node != NULL && node == &s6 && wpStr8ListTotalSize(&list) == 6 && list.node_count == 6; wapp_dbl_list_insert(WpStr8, &list, &s7, 5); node = wapp_dbl_list_get(WpStr8, &list, 5); - result = result && node != NULL && node == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7; + result = result && node != NULL && node == &s7 && wpStr8ListTotalSize(&list) == 7 && list.node_count == 7; return wpTesterResult(result); } @@ -111,11 +111,11 @@ WpTestFuncResult test_str8_list_insert(void) { WpTestFuncResult test_str8_list_pop_front(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -126,19 +126,19 @@ WpTestFuncResult test_str8_list_pop_front(void) { wapp_dbl_list_push_back(WpStr8, &list, &s5); WpStr8 *node = wapp_dbl_list_pop_front(WpStr8, &list); - result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; + result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4; node = wapp_dbl_list_pop_front(WpStr8, &list); - result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; node = wapp_dbl_list_pop_front(WpStr8, &list); - result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; node = wapp_dbl_list_pop_front(WpStr8, &list); - result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; node = wapp_dbl_list_pop_front(WpStr8, &list); - result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; + result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0; return wpTesterResult(result); } @@ -146,11 +146,11 @@ WpTestFuncResult test_str8_list_pop_front(void) { WpTestFuncResult test_str8_list_pop_back(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -161,19 +161,19 @@ WpTestFuncResult test_str8_list_pop_back(void) { wapp_dbl_list_push_front(WpStr8, &list, &s5); WpStr8 *node = wapp_dbl_list_pop_back(WpStr8, &list); - result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; + result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4; node = wapp_dbl_list_pop_back(WpStr8, &list); - result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; node = wapp_dbl_list_pop_back(WpStr8, &list); - result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; node = wapp_dbl_list_pop_back(WpStr8, &list); - result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; node = wapp_dbl_list_pop_back(WpStr8, &list); - result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; + result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0; return wpTesterResult(result); } @@ -181,11 +181,11 @@ WpTestFuncResult test_str8_list_pop_back(void) { WpTestFuncResult test_str8_list_remove(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -196,19 +196,19 @@ WpTestFuncResult test_str8_list_remove(void) { wapp_dbl_list_push_back(WpStr8, &list, &s5); WpStr8 *node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; + result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4; node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; + result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0; return wpTesterResult(result); } @@ -217,14 +217,14 @@ WpTestFuncResult test_str8_list_empty(void) { b8 result; WpStr8List list = wapp_dbl_list(WpStr8); - wapp_dbl_list_push_back(WpStr8, &list, &wapp_str8_lit("Hello")); - wapp_dbl_list_push_back(WpStr8, &list, &wapp_str8_lit("from")); - wapp_dbl_list_push_back(WpStr8, &list, &wapp_str8_lit("wizapp")); - wapp_dbl_list_push_back(WpStr8, &list, &wapp_str8_lit("stdlib")); + wapp_dbl_list_push_back(WpStr8, &list, &wpStr8Lit("Hello")); + wapp_dbl_list_push_back(WpStr8, &list, &wpStr8Lit("from")); + wapp_dbl_list_push_back(WpStr8, &list, &wpStr8Lit("wizapp")); + wapp_dbl_list_push_back(WpStr8, &list, &wpStr8Lit("stdlib")); wapp_dbl_list_empty(WpStr8, &list); - result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0; + result = list.first == NULL && list.last == NULL && list.node_count == 0 && wpStr8ListTotalSize(&list) == 0; return wpTesterResult(result); } diff --git a/tests/str8/test_str8_list.cc b/tests/str8/test_str8_list.cc index 12e769d..a349719 100644 --- a/tests/str8/test_str8_list.cc +++ b/tests/str8/test_str8_list.cc @@ -4,11 +4,11 @@ WpTestFuncResult test_str8_list_get(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -19,19 +19,19 @@ WpTestFuncResult test_str8_list_get(void) { wapp_dbl_list_push_back(WpStr8, &list, &s5); WpStr8 *node = wapp_dbl_list_get(WpStr8, &list, 0); - result = node == &s1 && wapp_str8_equal(node, &s1); + result = node == &s1 && wpStr8Equal(node, &s1); node = wapp_dbl_list_get(WpStr8, &list, 1); - result = result && node == &s2 && wapp_str8_equal(node, &s2); + result = result && node == &s2 && wpStr8Equal(node, &s2); node = wapp_dbl_list_get(WpStr8, &list, 2); - result = result && node == &s3 && wapp_str8_equal(node, &s3); + result = result && node == &s3 && wpStr8Equal(node, &s3); node = wapp_dbl_list_get(WpStr8, &list, 3); - result = result && node == &s4 && wapp_str8_equal(node, &s4); + result = result && node == &s4 && wpStr8Equal(node, &s4); node = wapp_dbl_list_get(WpStr8, &list, 4); - result = result && node == &s5 && wapp_str8_equal(node, &s5); + result = result && node == &s5 && wpStr8Equal(node, &s5); return wpTesterResult(result); } @@ -39,20 +39,20 @@ WpTestFuncResult test_str8_list_get(void) { WpTestFuncResult test_str8_list_push_front(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); WpStr8List list = wapp_dbl_list(WpStr8); wapp_dbl_list_push_front(WpStr8, &list, &s1); - result = list.first == list.last && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = list.first == list.last && list.first->item == &s1 && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; wapp_dbl_list_push_front(WpStr8, &list, &s2); - result = result && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && list.first->item == &s2 && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; wapp_dbl_list_push_front(WpStr8, &list, &s3); - result = result && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && list.first->item == &s3 && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; return wpTesterResult(result); } @@ -60,20 +60,20 @@ WpTestFuncResult test_str8_list_push_front(void) { WpTestFuncResult test_str8_list_push_back(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); WpStr8List list = wapp_dbl_list(WpStr8); wapp_dbl_list_push_back(WpStr8, &list, &s1); - result = list.first == list.last && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = list.first == list.last && list.last->item == &s1 && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; wapp_dbl_list_push_back(WpStr8, &list, &s2); - result = result && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && list.last->item == &s2 && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; wapp_dbl_list_push_back(WpStr8, &list, &s3); - result = result && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && list.last->item == &s3 && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; return wpTesterResult(result); } @@ -81,13 +81,13 @@ WpTestFuncResult test_str8_list_push_back(void) { WpTestFuncResult test_str8_list_insert(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); - WpStr8 s6 = wapp_str8_lit("6"); - WpStr8 s7 = wapp_str8_lit("7"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); + WpStr8 s6 = wpStr8Lit("6"); + WpStr8 s7 = wpStr8Lit("7"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -100,10 +100,10 @@ WpTestFuncResult test_str8_list_insert(void) { WpStr8 *node; wapp_dbl_list_insert(WpStr8, &list, &s6, 2); node = wapp_dbl_list_get(WpStr8, &list, 2); - result = node != NULL && node == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6; + result = node != NULL && node == &s6 && wpStr8ListTotalSize(&list) == 6 && list.node_count == 6; wapp_dbl_list_insert(WpStr8, &list, &s7, 5); node = wapp_dbl_list_get(WpStr8, &list, 5); - result = result && node != NULL && node == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7; + result = result && node != NULL && node == &s7 && wpStr8ListTotalSize(&list) == 7 && list.node_count == 7; return wpTesterResult(result); } @@ -111,11 +111,11 @@ WpTestFuncResult test_str8_list_insert(void) { WpTestFuncResult test_str8_list_pop_front(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -126,19 +126,19 @@ WpTestFuncResult test_str8_list_pop_front(void) { wapp_dbl_list_push_back(WpStr8, &list, &s5); WpStr8 *node = wapp_dbl_list_pop_front(WpStr8, &list); - result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; + result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4; node = wapp_dbl_list_pop_front(WpStr8, &list); - result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; node = wapp_dbl_list_pop_front(WpStr8, &list); - result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; node = wapp_dbl_list_pop_front(WpStr8, &list); - result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; node = wapp_dbl_list_pop_front(WpStr8, &list); - result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; + result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0; return wpTesterResult(result); } @@ -146,11 +146,11 @@ WpTestFuncResult test_str8_list_pop_front(void) { WpTestFuncResult test_str8_list_pop_back(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -161,19 +161,19 @@ WpTestFuncResult test_str8_list_pop_back(void) { wapp_dbl_list_push_front(WpStr8, &list, &s5); WpStr8 *node = wapp_dbl_list_pop_back(WpStr8, &list); - result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; + result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4; node = wapp_dbl_list_pop_back(WpStr8, &list); - result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; node = wapp_dbl_list_pop_back(WpStr8, &list); - result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; node = wapp_dbl_list_pop_back(WpStr8, &list); - result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; node = wapp_dbl_list_pop_back(WpStr8, &list); - result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; + result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0; return wpTesterResult(result); } @@ -181,11 +181,11 @@ WpTestFuncResult test_str8_list_pop_back(void) { WpTestFuncResult test_str8_list_remove(void) { b8 result; - WpStr8 s1 = wapp_str8_lit("1"); - WpStr8 s2 = wapp_str8_lit("2"); - WpStr8 s3 = wapp_str8_lit("3"); - WpStr8 s4 = wapp_str8_lit("4"); - WpStr8 s5 = wapp_str8_lit("5"); + WpStr8 s1 = wpStr8Lit("1"); + WpStr8 s2 = wpStr8Lit("2"); + WpStr8 s3 = wpStr8Lit("3"); + WpStr8 s4 = wpStr8Lit("4"); + WpStr8 s5 = wpStr8Lit("5"); WpStr8List list = wapp_dbl_list(WpStr8); @@ -196,19 +196,19 @@ WpTestFuncResult test_str8_list_remove(void) { wapp_dbl_list_push_back(WpStr8, &list, &s5); WpStr8 *node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; + result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4; node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; + result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3; node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; + result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2; node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; + result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1; node = wapp_dbl_list_remove(WpStr8, &list, 0); - result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; + result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0; return wpTesterResult(result); } @@ -218,21 +218,21 @@ WpTestFuncResult test_str8_list_empty(void) { WpStr8List list = wapp_dbl_list(WpStr8); - WpStr8 hello = wapp_str8_lit("Hello"); + WpStr8 hello = wpStr8Lit("Hello"); wapp_dbl_list_push_back(WpStr8, &list, &hello); - WpStr8 from = wapp_str8_lit("from"); + WpStr8 from = wpStr8Lit("from"); wapp_dbl_list_push_back(WpStr8, &list, &from); - WpStr8 wizapp = wapp_str8_lit("wizapp"); + WpStr8 wizapp = wpStr8Lit("wizapp"); wapp_dbl_list_push_back(WpStr8, &list, &wizapp); - WpStr8 stdlib = wapp_str8_lit("stdlib"); + WpStr8 stdlib = wpStr8Lit("stdlib"); wapp_dbl_list_push_back(WpStr8, &list, &stdlib); wapp_dbl_list_empty(WpStr8, &list); - result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0; + result = list.first == NULL && list.last == NULL && list.node_count == 0 && wpStr8ListTotalSize(&list) == 0; return wpTesterResult(result); }