Simplify dbl list API (#11)

Reviewed-on: #11
Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com>
Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit was merged in pull request #11.
This commit is contained in:
2026-01-11 18:22:54 +00:00
committed by Abdelrahman Said
parent b88cb71aa8
commit cff418b9e9
13 changed files with 455 additions and 533 deletions

View File

@@ -25,15 +25,16 @@ DBL_LIST_ALLOC_RETURN:
return list; return list;
} }
GenericNode *_dbl_list_node_alloc(const Allocator *allocator, u64 item_size) { GenericNode *_dbl_list_node_alloc(const Allocator *allocator, void *item, u64 item_size) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL"); wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
GenericNode *node = wapp_mem_allocator_alloc(allocator, sizeof(GenericNode)); GenericNode *node = wapp_mem_allocator_alloc(allocator, sizeof(GenericNode));
if (!node) { goto DBL_LIST_NODE_ALLOC_RETURN; } if (!node) { goto DBL_LIST_NODE_ALLOC_RETURN; }
memset((void *)node, 0, sizeof(GenericNode)); memset((void *)node, 0, sizeof(GenericNode));
node->magic = WAPP_DBL_NODE_MAGIC; node->item = item;
node->item_size = item_size; node->header.magic = WAPP_DBL_NODE_MAGIC;
node->header.item_size = item_size;
DBL_LIST_NODE_ALLOC_RETURN: DBL_LIST_NODE_ALLOC_RETURN:
return node; return node;
@@ -47,7 +48,7 @@ GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size) {
GenericNode *output = NULL; GenericNode *output = NULL;
GenericNode *current = list->first; GenericNode *current = list->first;
for (u64 i = 1; i <= index; ++i) { for (u64 i = 1; i <= index; ++i) {
current = current->next; current = current->header.next;
} }
output = current; output = current;
@@ -71,11 +72,11 @@ void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size) {
GenericNode *first = list->first; GenericNode *first = list->first;
if (first) { if (first) {
first->prev = node_list.last; first->header.prev = node_list.last;
} }
list->first = node_list.first; list->first = node_list.first;
node_list.last->next = first; node_list.last->header.next = first;
} }
void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) { void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
@@ -94,11 +95,11 @@ void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
GenericNode *last = list->last; GenericNode *last = list->last;
if (last) { if (last) {
last->next = node_list.first; last->header.next = node_list.first;
} }
list->last = node_list.last; list->last = node_list.last;
node_list.first->prev = last; node_list.first->header.prev = last;
} }
void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_size) { void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_size) {
@@ -123,72 +124,78 @@ void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_
list->node_count += node_list.node_count; list->node_count += node_list.node_count;
GenericNode *prev = dst_node->prev; GenericNode *prev = dst_node->header.prev;
dst_node->prev = node_list.last; dst_node->header.prev = node_list.last;
prev->next = node_list.first; prev->header.next = node_list.first;
node_list.first->prev = prev; node_list.first->header.prev = prev;
node_list.last->next = dst_node; node_list.last->header.next = dst_node;
} }
GenericNode *_dbl_list_pop_front(GenericList *list, u64 item_size) { void *_dbl_list_pop_front(GenericList *list, u64 item_size) {
wapp_debug_assert(list != NULL, "`list` should not be NULL"); wapp_debug_assert(list != NULL, "`list` should not be NULL");
_dbl_list_validate(list, item_size); _dbl_list_validate(list, item_size);
GenericNode *output = NULL; void *output = NULL;
if (list->node_count == 0) { if (list->node_count == 0) {
goto RETURN_LIST_POP_FRONT; goto RETURN_LIST_POP_FRONT;
} }
output = list->first; GenericNode *node = list->first;
if (list->node_count == 1) { if (list->node_count == 1) {
*list = (GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = item_size}; *list = (GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = item_size};
goto RETURN_LIST_POP_FRONT; goto LIST_POP_FRONT_RETRIEVE_NODE_ITEM;
} }
--(list->node_count); --(list->node_count);
list->first = output->next; list->first = node->header.next;
output->prev = output->next = NULL; node->header.prev = node->header.next = NULL;
LIST_POP_FRONT_RETRIEVE_NODE_ITEM:
output = node->item;
RETURN_LIST_POP_FRONT: RETURN_LIST_POP_FRONT:
return output; return output;
} }
GenericNode *_dbl_list_pop_back(GenericList *list, u64 item_size) { void *_dbl_list_pop_back(GenericList *list, u64 item_size) {
wapp_debug_assert(list != NULL, "`list` should not be NULL"); wapp_debug_assert(list != NULL, "`list` should not be NULL");
_dbl_list_validate(list, item_size); _dbl_list_validate(list, item_size);
GenericNode *output = NULL; void *output = NULL;
if (list->node_count == 0) { if (list->node_count == 0) {
goto RETURN_LIST_POP_BACK; goto RETURN_LIST_POP_BACK;
} }
output = list->last; GenericNode *node = list->last;
if (list->node_count == 1) { if (list->node_count == 1) {
*list = (GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = item_size}; *list = (GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = item_size};
goto RETURN_LIST_POP_BACK; goto LIST_POP_BACK_RETRIEVE_NODE_ITEM;
} }
--(list->node_count); --(list->node_count);
list->last = output->prev; list->last = node->header.prev;
output->prev = output->next = NULL; node->header.prev = node->header.next = NULL;
LIST_POP_BACK_RETRIEVE_NODE_ITEM:
output = node->item;
RETURN_LIST_POP_BACK: RETURN_LIST_POP_BACK:
return output; return output;
} }
GenericNode *_dbl_list_remove(GenericList *list, u64 index, u64 item_size) { void *_dbl_list_remove(GenericList *list, u64 index, u64 item_size) {
wapp_debug_assert(list != NULL, "`list` should not be NULL"); wapp_debug_assert(list != NULL, "`list` should not be NULL");
_dbl_list_validate(list, item_size); _dbl_list_validate(list, item_size);
GenericNode *output = NULL; void *output = NULL;
if (index == 0) { if (index == 0) {
output = _dbl_list_pop_front(list, item_size); output = _dbl_list_pop_front(list, item_size);
@@ -198,17 +205,19 @@ GenericNode *_dbl_list_remove(GenericList *list, u64 index, u64 item_size) {
goto RETURN_LIST_REMOVE; goto RETURN_LIST_REMOVE;
} }
output = _dbl_list_get(list, index, item_size); GenericNode *node = _dbl_list_get(list, index, item_size);
if (!output) { if (!node) {
goto RETURN_LIST_REMOVE; goto RETURN_LIST_REMOVE;
} }
output->prev->next = output->next; node->header.prev->header.next = node->header.next;
output->next->prev = output->prev; node->header.next->header.prev = node->header.prev;
--(list->node_count); --(list->node_count);
output->prev = output->next = NULL; node->header.prev = node->header.next = NULL;
output = node->item;
RETURN_LIST_REMOVE: RETURN_LIST_REMOVE:
return output; return output;
@@ -233,13 +242,13 @@ wapp_intern GenericList _node_to_list(GenericNode *node, u64 item_size) {
.item_size = item_size, .item_size = item_size,
}; };
while (output.first->prev != NULL) { while (output.first->header.prev != NULL) {
output.first = output.first->prev; output.first = output.first->header.prev;
++(output.node_count); ++(output.node_count);
} }
while (output.last->next != NULL) { while (output.last->header.next != NULL) {
output.last = output.last->next; output.last = output.last->header.next;
++(output.node_count); ++(output.node_count);
} }
@@ -252,7 +261,7 @@ wapp_intern inline void _dbl_list_validate(const GenericList *list, u64 item_siz
} }
wapp_intern inline void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size) { wapp_intern inline void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size) {
wapp_runtime_assert(node->magic == WAPP_DBL_NODE_MAGIC, "`node` isn't a valid wapp node type"); wapp_runtime_assert(node->header.magic == WAPP_DBL_NODE_MAGIC, "`node` isn't a valid wapp node type");
wapp_runtime_assert(list->item_size == node->item_size, "Mismatched `list` and `node` types"); wapp_runtime_assert(list->item_size == node->header.item_size, "Mismatched `list` and `node` types");
wapp_runtime_assert(node->item_size == item_size, "Invalid item provided"); wapp_runtime_assert(node->header.item_size == item_size, "Invalid item provided");
} }

View File

@@ -14,96 +14,110 @@ BEGIN_C_LINKAGE
#define WAPP_DBL_LIST_MAGIC (u64)0x57415f444c5354 #define WAPP_DBL_LIST_MAGIC (u64)0x57415f444c5354
#define WAPP_DBL_NODE_MAGIC (u64)0x57415f444e44 #define WAPP_DBL_NODE_MAGIC (u64)0x57415f444e44
#define WAPP_DEF_DBL_LIST_TYPE(T, NODE_NAME, LIST_NAME) \ typedef struct GenericNode GenericNode;
typedef struct NODE_NAME NODE_NAME; \
struct NODE_NAME { \ typedef struct {
u64 magic; \ u64 magic;
T *item; \ u64 item_size;
NODE_NAME *prev; \ GenericNode *prev;
NODE_NAME *next; \ GenericNode *next;
u64 item_size; \ } NodeHeader;
}; \
\ struct GenericNode {
typedef struct { \ NodeHeader header;
u64 magic; \ void *item;
NODE_NAME *first; \ };
NODE_NAME *last; \
u64 node_count; \ typedef struct {
u64 item_size; \ u64 magic;
} LIST_NAME u64 node_count;
u64 item_size;
GenericNode *first;
GenericNode *last;
} GenericList;
// NOTE (Abdelrahman): Typedefs for readability
typedef GenericList VoidPtrList;
typedef GenericList C8List;
typedef GenericList C16List;
typedef GenericList C32List;
typedef GenericList U8List;
typedef GenericList U16List;
typedef GenericList U32List;
typedef GenericList U64List;
typedef GenericList B8List;
typedef GenericList I8List;
typedef GenericList I16List;
typedef GenericList I32List;
typedef GenericList I64List;
typedef GenericList F32List;
typedef GenericList F64List;
typedef GenericList F128List;
typedef GenericList UptrList;
typedef GenericList IptrList;
typedef GenericList Str8List;
#ifdef WAPP_PLATFORM_CPP #ifdef WAPP_PLATFORM_CPP
#define wapp_dbl_list(ELEM_TYPE, LIST_TYPE) \ #define wapp_dbl_list(TYPE) \
LIST_TYPE{WAPP_DBL_LIST_MAGIC, nullptr, nullptr, 0, sizeof(ELEM_TYPE)} GenericList{WAPP_DBL_LIST_MAGIC, 0, sizeof(TYPE), nullptr, nullptr}
#define wapp_dbl_list_node(ELEM_TYPE, NODE_TYPE, ELEM_PTR) \ #define _dbl_list_node(TYPE, ITEM_PTR) ([&]() { \
NODE_TYPE{WAPP_DBL_NODE_MAGIC, ELEM_PTR, nullptr, nullptr, sizeof(ELEM_TYPE)} wapp_persist GenericNode node = { \
NodeHeader{WAPP_DBL_NODE_MAGIC, sizeof(TYPE), nullptr, nullptr}, \
ITEM_PTR, \
}; \
\
return &node; \
}())
#else #else
#define wapp_dbl_list(ELEM_TYPE, LIST_TYPE) ( \ #define wapp_dbl_list(TYPE) ( \
(LIST_TYPE){.magic = WAPP_DBL_LIST_MAGIC, .item_size = sizeof(ELEM_TYPE)} \ (GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = sizeof(TYPE)} \
) )
#define wapp_dbl_list_node(ELEM_TYPE, NODE_TYPE, ELEM_PTR) ( \ #define _dbl_list_node(TYPE, ITEM_PTR) ( \
(NODE_TYPE){.magic = WAPP_DBL_NODE_MAGIC, .item = ELEM_PTR, .item_size = sizeof(ELEM_TYPE)} \ &((GenericNode){.header = {.magic = WAPP_DBL_NODE_MAGIC, .item_size = sizeof(TYPE)}, \
.item = ITEM_PTR}) \
) )
#endif // !WAPP_PLATFORM_CPP #endif // !WAPP_PLATFORM_CPP
#define wapp_dbl_list_alloc(ELEM_TYPE, LIST_TYPE, ALLOCATOR) \ #define wapp_dbl_list_alloc(TYPE, ALLOCATOR) \
((LIST_TYPE *)_dbl_list_alloc(ALLOCATOR, sizeof(ELEM_TYPE))) (_dbl_list_alloc(ALLOCATOR, sizeof(TYPE)))
#define wapp_dbl_list_node_alloc(ELEM_TYPE, NODE_TYPE, ALLOCATOR) \ #define wapp_dbl_list_get(TYPE, LIST_PTR, ITEM_INDEX) \
((NODE_TYPE *)_dbl_list_node_alloc(ALLOCATOR, sizeof(ELEM_TYPE))) ((TYPE *)(_dbl_list_get(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item))
#define wapp_dbl_list_get(ELEM_TYPE, NODE_TYPE, LIST_PTR, ELEM_INDEX) \ #define wapp_dbl_list_push_front(TYPE, LIST_PTR, ITEM_PTR) \
((NODE_TYPE *)_dbl_list_get((GenericList *)LIST_PTR, ELEM_INDEX, sizeof(ELEM_TYPE))) (_dbl_list_push_front(LIST_PTR, _dbl_list_node(TYPE, ITEM_PTR), sizeof(TYPE)))
#define wapp_dbl_list_push_front(ELEM_TYPE, LIST_PTR, NODE_PTR) \ #define wapp_dbl_list_push_back(TYPE, LIST_PTR, ITEM_PTR) \
(_dbl_list_push_front((GenericList *)LIST_PTR, (GenericNode *)NODE_PTR, sizeof(ELEM_TYPE))) (_dbl_list_push_back(LIST_PTR, _dbl_list_node(TYPE, ITEM_PTR), sizeof(TYPE)))
#define wapp_dbl_list_push_back(ELEM_TYPE, LIST_PTR, NODE_PTR) \ #define wapp_dbl_list_insert(TYPE, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
(_dbl_list_push_back((GenericList *)LIST_PTR, (GenericNode *)NODE_PTR, sizeof(ELEM_TYPE))) (_dbl_list_insert(LIST_PTR, _dbl_list_node(TYPE, ITEM_PTR), \
#define wapp_dbl_list_insert(ELEM_TYPE, LIST_PTR, NODE_PTR, ELEM_INDEX) \ ITEM_INDEX, sizeof(TYPE)))
(_dbl_list_insert((GenericList *)LIST_PTR, (GenericNode *)NODE_PTR, \ #define wapp_dbl_list_push_front_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
ELEM_INDEX, sizeof(ELEM_TYPE))) (_dbl_list_push_front(LIST_PTR, _dbl_list_node_alloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
#define wapp_dbl_list_pop_front(ELEM_TYPE, NODE_TYPE, LIST_PTR) \ sizeof(TYPE)))
((NODE_TYPE *)_dbl_list_pop_front((GenericList *)LIST_PTR, sizeof(ELEM_TYPE))) #define wapp_dbl_list_push_back_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
#define wapp_dbl_list_pop_back(ELEM_TYPE, NODE_TYPE, LIST_PTR) \ (_dbl_list_push_back(LIST_PTR, _dbl_list_node_alloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
((NODE_TYPE *)_dbl_list_pop_back((GenericList *)LIST_PTR, sizeof(ELEM_TYPE))) sizeof(TYPE)))
#define wapp_dbl_list_remove(ELEM_TYPE, NODE_TYPE, LIST_PTR, ELEM_INDEX) \ #define wapp_dbl_list_insert_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
((NODE_TYPE *)_dbl_list_remove((GenericList *)LIST_PTR, ELEM_INDEX, sizeof(ELEM_TYPE))) (_dbl_list_insert(LIST_PTR, _dbl_list_node_alloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
#define wapp_dbl_list_empty(ELEM_TYPE, LIST_PTR) \ ITEM_INDEX, sizeof(TYPE)))
(_dbl_list_empty((GenericList *)LIST_PTR, sizeof(ELEM_TYPE))) #define wapp_dbl_list_pop_front(TYPE, LIST_PTR) \
((TYPE *)_dbl_list_pop_front(LIST_PTR, sizeof(TYPE)))
WAPP_DEF_DBL_LIST_TYPE(void, GenericNode, GenericList); #define wapp_dbl_list_pop_back(TYPE, LIST_PTR) \
((TYPE *)_dbl_list_pop_back(LIST_PTR, sizeof(TYPE)))
#define wapp_dbl_list_remove(TYPE, LIST_PTR, ITEM_INDEX) \
((TYPE *)_dbl_list_remove(LIST_PTR, ITEM_INDEX, sizeof(TYPE)))
#define wapp_dbl_list_empty(TYPE, LIST_PTR) \
(_dbl_list_empty(LIST_PTR, sizeof(TYPE)))
GenericList *_dbl_list_alloc(const Allocator *allocator, u64 item_size); GenericList *_dbl_list_alloc(const Allocator *allocator, u64 item_size);
GenericNode *_dbl_list_node_alloc(const Allocator *allocator, u64 item_size); GenericNode *_dbl_list_node_alloc(const Allocator *allocator, void *item, u64 item_size);
GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size); GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size);
void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size); void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size);
void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size); void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size);
void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_size); void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_size);
GenericNode *_dbl_list_pop_front(GenericList *list, u64 item_size); void *_dbl_list_pop_front(GenericList *list, u64 item_size);
GenericNode *_dbl_list_pop_back(GenericList *list, u64 item_size); void *_dbl_list_pop_back(GenericList *list, u64 item_size);
GenericNode *_dbl_list_remove(GenericList *list, u64 index, u64 item_size); void *_dbl_list_remove(GenericList *list, u64 index, u64 item_size);
void _dbl_list_empty(GenericList *list, u64 item_size); void _dbl_list_empty(GenericList *list, u64 item_size);
// Base list types
typedef struct Str8 Str8;
WAPP_DEF_DBL_LIST_TYPE(void *, VoidPtrNode, VoidPtrList);
WAPP_DEF_DBL_LIST_TYPE(c8 , C8Node , C8List);
WAPP_DEF_DBL_LIST_TYPE(c16 , C16Node , C16List);
WAPP_DEF_DBL_LIST_TYPE(c32 , C32Node , C32List);
WAPP_DEF_DBL_LIST_TYPE(u8 , U8Node , U8List);
WAPP_DEF_DBL_LIST_TYPE(u16 , U16Node , U16List);
WAPP_DEF_DBL_LIST_TYPE(u32 , U32Node , U32List);
WAPP_DEF_DBL_LIST_TYPE(u64 , U64Node , U64List);
WAPP_DEF_DBL_LIST_TYPE(b8 , B8Node , B8List);
WAPP_DEF_DBL_LIST_TYPE(i8 , I8Node , I8List);
WAPP_DEF_DBL_LIST_TYPE(i16 , I16Node , I16List);
WAPP_DEF_DBL_LIST_TYPE(i32 , I32Node , I32List);
WAPP_DEF_DBL_LIST_TYPE(i64 , I64Node , I64List);
WAPP_DEF_DBL_LIST_TYPE(f32 , F32Node , F32List);
WAPP_DEF_DBL_LIST_TYPE(f64 , F64Node , F64List);
WAPP_DEF_DBL_LIST_TYPE(f128 , F128Node , F128List);
WAPP_DEF_DBL_LIST_TYPE(uptr , UptrNode , UptrList);
WAPP_DEF_DBL_LIST_TYPE(iptr , IptrNode , IptrList);
WAPP_DEF_DBL_LIST_TYPE(Str8 , Str8Node , Str8List);
#ifdef WAPP_PLATFORM_CPP #ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP #endif // !WAPP_PLATFORM_CPP

View File

@@ -333,14 +333,12 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL"); wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
Str8List *output = wapp_dbl_list_alloc(Str8, Str8List, allocator); Str8List *output = wapp_dbl_list_alloc(Str8, allocator);
if (delimiter->size > str->size) { if (delimiter->size > str->size) {
Str8 *full = wapp_str8_alloc_str8(allocator, str); Str8 *full = wapp_str8_alloc_str8(allocator, str);
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator); if (full) {
if (node) { wapp_dbl_list_push_back_alloc(Str8, allocator, output, full);
node->item = full;
wapp_dbl_list_push_back(Str8, output, node);
} }
goto RETURN_STR8_SPLIT; goto RETURN_STR8_SPLIT;
@@ -358,10 +356,8 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
} }
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end); before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator); if (before_str) {
if (node && before_str) { wapp_dbl_list_push_back_alloc(Str8, allocator, output, before_str);
node->item = before_str;
wapp_dbl_list_push_back(Str8, output, node);
} }
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8)); wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
@@ -372,11 +368,9 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
} }
// Ensure the last part of the string after the delimiter is added to the list // 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 = wapp_str8_alloc_substr(allocator, str, start, str->size);
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator); if (rest) {
if (node && rest) { wapp_dbl_list_push_back_alloc(Str8, allocator, output, rest);
node->item = rest;
wapp_dbl_list_push_back(Str8, output, node);
} }
RETURN_STR8_SPLIT: RETURN_STR8_SPLIT:
@@ -386,14 +380,12 @@ RETURN_STR8_SPLIT:
Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL"); wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
Str8List *output = wapp_dbl_list_alloc(Str8, Str8List, allocator); Str8List *output = wapp_dbl_list_alloc(Str8, allocator);
if (delimiter->size > str->size) { if (delimiter->size > str->size) {
Str8 *full = wapp_str8_alloc_str8(allocator, str); Str8 *full = wapp_str8_alloc_str8(allocator, str);
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator); if (full) {
if (node && full) { wapp_dbl_list_push_back_alloc(Str8, allocator, output, full);
node->item = full;
wapp_dbl_list_push_back(Str8, output, node);
} }
goto RETURN_STR8_SPLIT; goto RETURN_STR8_SPLIT;
@@ -410,10 +402,8 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
} }
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size); after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator); if (after_str) {
if (node) { wapp_dbl_list_push_front_alloc(Str8, allocator, output, after_str);
node->item = after_str;
wapp_dbl_list_push_front(Str8, output, node);
} }
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8)); wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
@@ -422,11 +412,9 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
++splits; ++splits;
} }
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size); rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator); if (rest) {
if (node && rest) { wapp_dbl_list_push_front_alloc(Str8, allocator, output, rest);
node->item = rest;
wapp_dbl_list_push_front(Str8, output, node);
} }
RETURN_STR8_SPLIT: RETURN_STR8_SPLIT:
@@ -441,16 +429,16 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
Str8Node *node; Str8 *node;
u64 node_index = 0; u64 node_index = 0;
b8 running = node_index < list->node_count; b8 running = node_index < list->node_count;
while (running) { while (running) {
node = wapp_dbl_list_get(Str8, Str8Node, list, node_index); node = wapp_dbl_list_get(Str8, list, node_index);
if (!node) { if (!node) {
break; break;
} }
wapp_str8_concat_capped(output, node->item); wapp_str8_concat_capped(output, node);
// NOTE (Abdelrahman): Comparison extracted to variable to silence // NOTE (Abdelrahman): Comparison extracted to variable to silence
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
@@ -473,17 +461,17 @@ u64 wapp_str8_list_total_size(const Str8List *list) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
Str8Node* node; Str8 *node;
u64 node_index = 0; u64 node_index = 0;
u64 output = 0; u64 output = 0;
b8 running = node_index < list->node_count; b8 running = node_index < list->node_count;
while (running) { while (running) {
node = wapp_dbl_list_get(Str8, Str8Node, list, node_index); node = wapp_dbl_list_get(Str8, list, node_index);
if (!node) { if (!node) {
break; break;
} }
output += node->item->size; output += node->size;
++node_index; ++node_index;
running = node_index < list->node_count; running = node_index < list->node_count;
} }

View File

@@ -125,27 +125,6 @@ u64 wapp_str8_list_total_size(const Str8List *list);
#ifdef WAPP_PLATFORM_CPP #ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE END_C_LINKAGE
#include <type_traits>
template <typename T>
constexpr bool is_lvalue(T&&) {
return std::is_lvalue_reference<T>{};
}
#define wapp_str8_node_from_cstr(STRING) wapp_dbl_list_node(Str8, Str8Node, [&]() { \
wapp_persist Str8 str = wapp_str8_lit(STRING); \
return &str; \
}())
#define wapp_str8_node_from_str8(STRING) wapp_dbl_list_node(Str8, Str8Node, [&]() { \
if (is_lvalue(STRING)) { return &STRING; } \
\
wapp_persist Str8 str = STRING; \
return &str; \
}())
#else
#define wapp_str8_node_from_cstr(STRING) wapp_dbl_list_node(Str8, Str8Node, &wapp_str8_lit(STRING))
#define wapp_str8_node_from_str8(STRING) wapp_dbl_list_node(Str8, Str8Node, &(STRING))
#endif // !WAPP_PLATFORM_CPP #endif // !WAPP_PLATFORM_CPP
#endif // !STR8_H #endif // !STR8_H

View File

@@ -29,23 +29,23 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
} }
// Handle first node // Handle first node
const Str8Node *first_node = wapp_dbl_list_get(Str8, Str8Node, parts, 0); Str8 *first_node = wapp_dbl_list_get(Str8, parts, 0);
wapp_str8_copy_str8_capped(dst, first_node->item); wapp_str8_copy_str8_capped(dst, first_node);
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
const Str8Node *node = first_node; Str8 *node = first_node;
u64 node_index = 1; u64 node_index = 1;
b8 running = node_index < parts->node_count; b8 running = node_index < parts->node_count;
while (running && node->next) { while (running) {
node = node->next; node = wapp_dbl_list_get(Str8, parts, node_index);
if (node->item->size == 0) { if (node->size == 0) {
continue; goto CPATH_JOIN_LOOP_END;
} }
if (dst->size > 0) { if (dst->size > 0) {
char dst_last = wapp_str8_get(dst, dst->size - 1); char dst_last = wapp_str8_get(dst, dst->size - 1);
char node_start = wapp_str8_get(node->item, 0); char node_start = wapp_str8_get(node, 0);
b8 add_path_sep = dst_last != WAPP_PATH_SEP && node_start != WAPP_PATH_SEP; b8 add_path_sep = dst_last != WAPP_PATH_SEP && node_start != WAPP_PATH_SEP;
if (add_path_sep) { if (add_path_sep) {
@@ -53,8 +53,9 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
} }
} }
wapp_str8_concat_capped(dst, node->item); wapp_str8_concat_capped(dst, node);
CPATH_JOIN_LOOP_END:
++node_index; ++node_index;
running = node_index < parts->node_count; running = node_index < parts->node_count;
} }
@@ -106,7 +107,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
wapp_str8_push_back(output, absolute ? WAPP_PATH_SEP : '.'); wapp_str8_push_back(output, absolute ? WAPP_PATH_SEP : '.');
} else { } else {
for (u64 i = 0; i < levels; ++i) { for (u64 i = 0; i < levels; ++i) {
wapp_dbl_list_pop_back(Str8, Str8Node, parts); wapp_dbl_list_pop_back(Str8, parts);
} }
u64 alignment = sizeof(void *) * 2; u64 alignment = sizeof(void *) * 2;

View File

@@ -16,16 +16,16 @@ TestFuncResult test_cpath_join_path(void) {
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP); wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP);
Str8List parts = wapp_dbl_list(Str8, Str8List); Str8List parts = wapp_dbl_list(Str8);
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_str8(tmp)); wapp_dbl_list_push_back(Str8, &parts, &tmp);
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("home")); wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit("home"));
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("abdelrahman")); wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit("abdelrahman"));
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("Documents")); wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit("Documents"));
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = wapp_str8_equal(&out, &expected); result = wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_front(Str8, Str8Node, &parts); wapp_dbl_list_pop_front(Str8, &parts);
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
@@ -33,8 +33,8 @@ TestFuncResult test_cpath_join_path(void) {
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("home")); wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("home"));
wapp_dbl_list_pop_front(Str8, Str8Node, &parts); wapp_dbl_list_pop_front(Str8, &parts);
wapp_dbl_list_push_front(Str8, &parts, &wapp_str8_node_from_str8(tmp)); wapp_dbl_list_push_front(Str8, &parts, &tmp);
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
@@ -42,8 +42,8 @@ TestFuncResult test_cpath_join_path(void) {
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_str8_format(&tmp, "home%c", WAPP_PATH_SEP); wapp_str8_format(&tmp, "home%c", WAPP_PATH_SEP);
wapp_dbl_list_pop_front(Str8, Str8Node, &parts); wapp_dbl_list_pop_front(Str8, &parts);
wapp_dbl_list_push_front(Str8, &parts, &wapp_str8_node_from_cstr("home")); wapp_dbl_list_push_front(Str8, &parts, &wapp_str8_lit("home"));
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
@@ -53,24 +53,24 @@ TestFuncResult test_cpath_join_path(void) {
wapp_dbl_list_empty(Str8, &parts); wapp_dbl_list_empty(Str8, &parts);
wapp_str8_format(&tmp, "%chome", WAPP_PATH_SEP); wapp_str8_format(&tmp, "%chome", WAPP_PATH_SEP);
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_str8(tmp)); wapp_dbl_list_push_back(Str8, &parts, &tmp);
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("")); wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit(""));
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_front(Str8, Str8Node, &parts); wapp_dbl_list_pop_front(Str8, &parts);
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("")); wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit(""));
wapp_str8_format(&expected, "%s", ""); wapp_str8_format(&expected, "%s", "");
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_back(Str8, Str8Node, &parts); wapp_dbl_list_pop_back(Str8, &parts);
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("home")); wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit("home"));
wapp_str8_copy_cstr_capped(&expected, "home"); wapp_str8_copy_cstr_capped(&expected, "home");

View File

@@ -16,24 +16,23 @@ TestFuncResult test_cpath_join_path(void) {
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP); wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP);
Str8List parts = wapp_dbl_list(Str8, Str8List); Str8List parts = wapp_dbl_list(Str8);
Str8Node tmp_node = wapp_str8_node_from_str8(tmp); wapp_dbl_list_push_back(Str8, &parts, &tmp);
wapp_dbl_list_push_back(Str8, &parts, &tmp_node);
Str8Node home_node = wapp_str8_node_from_cstr("home"); Str8 home = wapp_str8_lit("home");
wapp_dbl_list_push_back(Str8, &parts, &home_node); wapp_dbl_list_push_back(Str8, &parts, &home);
Str8Node user_node = wapp_str8_node_from_cstr("abdelrahman"); Str8 user = wapp_str8_lit("abdelrahman");
wapp_dbl_list_push_back(Str8, &parts, &user_node); wapp_dbl_list_push_back(Str8, &parts, &user);
Str8Node docs_node = wapp_str8_node_from_cstr("Documents"); Str8 docs = wapp_str8_lit("Documents");
wapp_dbl_list_push_back(Str8, &parts, &docs_node); wapp_dbl_list_push_back(Str8, &parts, &docs);
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = wapp_str8_equal(&out, &expected); result = wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_front(Str8, Str8Node, &parts); wapp_dbl_list_pop_front(Str8, &parts);
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
@@ -42,10 +41,9 @@ TestFuncResult test_cpath_join_path(void) {
Str8RO str = wapp_str8_lit_ro("home"); Str8RO str = wapp_str8_lit_ro("home");
wapp_str8_concat_capped(&tmp, &str); wapp_str8_concat_capped(&tmp, &str);
wapp_dbl_list_pop_front(Str8, Str8Node, &parts); wapp_dbl_list_pop_front(Str8, &parts);
Str8Node tmp_node_2 = wapp_str8_node_from_str8(tmp); wapp_dbl_list_push_front(Str8, &parts, &tmp);
wapp_dbl_list_push_front(Str8, &parts, &tmp_node_2);
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
@@ -53,10 +51,10 @@ TestFuncResult test_cpath_join_path(void) {
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_str8_format(&tmp, "home%c", WAPP_PATH_SEP); wapp_str8_format(&tmp, "home%c", WAPP_PATH_SEP);
wapp_dbl_list_pop_front(Str8, Str8Node, &parts); wapp_dbl_list_pop_front(Str8, &parts);
Str8Node home_node_2 = wapp_str8_node_from_cstr("home"); Str8 home_2 = wapp_str8_lit("home");
wapp_dbl_list_push_front(Str8, &parts, &home_node_2); wapp_dbl_list_push_front(Str8, &parts, &home_2);
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP); wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
@@ -67,31 +65,30 @@ TestFuncResult test_cpath_join_path(void) {
wapp_str8_format(&tmp, "%chome", WAPP_PATH_SEP); wapp_str8_format(&tmp, "%chome", WAPP_PATH_SEP);
Str8Node tmp_node_3 = wapp_str8_node_from_str8(tmp); wapp_dbl_list_push_back(Str8, &parts, &tmp);
wapp_dbl_list_push_back(Str8, &parts, &tmp_node_3);
Str8Node empty_node = wapp_str8_node_from_cstr(""); Str8 empty = wapp_str8_lit("");
wapp_dbl_list_push_back(Str8, &parts, &empty_node); wapp_dbl_list_push_back(Str8, &parts, &empty);
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP); wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_front(Str8, Str8Node, &parts); wapp_dbl_list_pop_front(Str8, &parts);
Str8Node empty_node_2 = wapp_str8_node_from_cstr(""); Str8 empty_2 = wapp_str8_lit("");
wapp_dbl_list_push_back(Str8, &parts, &empty_node_2); wapp_dbl_list_push_back(Str8, &parts, &empty_2);
wapp_str8_format(&expected, "%s", ""); wapp_str8_format(&expected, "%s", "");
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_back(Str8, Str8Node, &parts); wapp_dbl_list_pop_back(Str8, &parts);
Str8Node home_node_3 = wapp_str8_node_from_cstr("home"); Str8 home_3 = wapp_str8_lit("home");
wapp_dbl_list_push_back(Str8, &parts, &home_node_3); wapp_dbl_list_push_back(Str8, &parts, &home_3);
wapp_str8_copy_cstr_capped(&expected, "home"); wapp_str8_copy_cstr_capped(&expected, "home");

View File

@@ -5,9 +5,9 @@
#include <string.h> #include <string.h>
TestFuncResult test_commander_cmd_success(void) { TestFuncResult test_commander_cmd_success(void) {
Str8List cmd = wapp_dbl_list(Str8, Str8List); Str8List cmd = wapp_dbl_list(Str8);
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("echo")); wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("echo"));
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("hello world")); wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("hello world"));
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS && b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
@@ -17,8 +17,8 @@ TestFuncResult test_commander_cmd_success(void) {
} }
TestFuncResult test_commander_cmd_failure(void) { TestFuncResult test_commander_cmd_failure(void) {
Str8List cmd = wapp_dbl_list(Str8, Str8List); Str8List cmd = wapp_dbl_list(Str8);
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("grep")); wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("grep"));
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
b8 failed = result.exited && result.exit_code != EXIT_SUCCESS && b8 failed = result.exited && result.exit_code != EXIT_SUCCESS &&
@@ -33,9 +33,9 @@ TestFuncResult test_commander_cmd_out_buf_success(void) {
char msg[] = "hello world"; char msg[] = "hello world";
wapp_str8_copy_cstr_capped(&expected, msg); wapp_str8_copy_cstr_capped(&expected, msg);
Str8List cmd = wapp_dbl_list(Str8, Str8List); Str8List cmd = wapp_dbl_list(Str8);
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("echo")); wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("echo"));
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr(msg)); wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit(msg));
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS && b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
@@ -50,9 +50,9 @@ TestFuncResult test_commander_cmd_out_buf_failure(void) {
char msg[] = "hello world"; char msg[] = "hello world";
wapp_str8_copy_cstr_capped(&expected, msg); wapp_str8_copy_cstr_capped(&expected, msg);
Str8List cmd = wapp_dbl_list(Str8, Str8List); Str8List cmd = wapp_dbl_list(Str8);
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("echo")); wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("echo"));
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr(msg)); wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit(msg));
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
b8 failed = !result.exited && result.exit_code != EXIT_SUCCESS && b8 failed = !result.exited && result.exit_code != EXIT_SUCCESS &&

View File

@@ -5,27 +5,27 @@
#include <string.h> #include <string.h>
TestFuncResult test_commander_cmd_success(void) { TestFuncResult test_commander_cmd_success(void) {
Str8List cmd = wapp_dbl_list(Str8, Str8List); Str8List cmd = wapp_dbl_list(Str8);
Str8Node echo = wapp_str8_node_from_cstr("echo"); Str8 echo = wapp_str8_lit("echo");
Str8Node msg = wapp_str8_node_from_cstr("hello world"); Str8 msg = wapp_str8_lit("hello world");
wapp_dbl_list_push_back(Str8, &cmd, &echo); wapp_dbl_list_push_back(Str8, &cmd, &echo);
wapp_dbl_list_push_back(Str8, &cmd, &msg); wapp_dbl_list_push_back(Str8, &cmd, &msg);
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, nullptr, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, nullptr, &cmd);
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS && b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
result.error == SHELL_ERR_NO_ERROR; result.error == SHELL_ERR_NO_ERROR;
return wapp_tester_result(succeeded); return wapp_tester_result(succeeded);
} }
TestFuncResult test_commander_cmd_failure(void) { TestFuncResult test_commander_cmd_failure(void) {
Str8List cmd = wapp_dbl_list(Str8, Str8List); Str8List cmd = wapp_dbl_list(Str8);
Str8Node grep = wapp_str8_node_from_cstr("grep"); Str8 grep = wapp_str8_lit("grep");
wapp_dbl_list_push_back(Str8, &cmd, &grep); wapp_dbl_list_push_back(Str8, &cmd, &grep);
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, nullptr, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, nullptr, &cmd);
b8 failed = result.exited && result.exit_code != EXIT_SUCCESS && b8 failed = result.exited && result.exit_code != EXIT_SUCCESS &&
result.error == SHELL_ERR_NO_ERROR; result.error == SHELL_ERR_NO_ERROR;
return wapp_tester_result(failed); return wapp_tester_result(failed);
} }
@@ -36,15 +36,15 @@ TestFuncResult test_commander_cmd_out_buf_success(void) {
char msg[] = "hello world"; char msg[] = "hello world";
wapp_str8_copy_cstr_capped(&expected, msg); wapp_str8_copy_cstr_capped(&expected, msg);
Str8List cmd = wapp_dbl_list(Str8, Str8List); Str8List cmd = wapp_dbl_list(Str8);
Str8Node echo = wapp_str8_node_from_cstr("echo"); Str8 echo = wapp_str8_lit("echo");
Str8Node arg = wapp_str8_node_from_cstr(msg); Str8 arg = wapp_str8_lit(msg);
wapp_dbl_list_push_back(Str8, &cmd, &echo); wapp_dbl_list_push_back(Str8, &cmd, &echo);
wapp_dbl_list_push_back(Str8, &cmd, &arg); wapp_dbl_list_push_back(Str8, &cmd, &arg);
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS && 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 && wapp_str8_equal_to_count(&buf, &expected, strlen(msg));
return wapp_tester_result(succeeded); return wapp_tester_result(succeeded);
} }
@@ -55,15 +55,15 @@ TestFuncResult test_commander_cmd_out_buf_failure(void) {
char msg[] = "hello world"; char msg[] = "hello world";
wapp_str8_copy_cstr_capped(&expected, msg); wapp_str8_copy_cstr_capped(&expected, msg);
Str8List cmd = wapp_dbl_list(Str8, Str8List); Str8List cmd = wapp_dbl_list(Str8);
Str8Node echo = wapp_str8_node_from_cstr("echo"); Str8 echo = wapp_str8_lit("echo");
Str8Node arg = wapp_str8_node_from_cstr(msg); Str8 arg = wapp_str8_lit(msg);
wapp_dbl_list_push_back(Str8, &cmd, &echo); wapp_dbl_list_push_back(Str8, &cmd, &echo);
wapp_dbl_list_push_back(Str8, &cmd, &arg); wapp_dbl_list_push_back(Str8, &cmd, &arg);
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
b8 failed = !result.exited && result.exit_code != EXIT_SUCCESS && 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 && !wapp_str8_equal(&buf, &expected);
return wapp_tester_result(failed); return wapp_tester_result(failed);
} }

View File

@@ -443,8 +443,8 @@ TestFuncResult test_str8_split(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running1) { while (running1) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list1, index1); Str8 *node = wapp_dbl_list_get(Str8, list1, index1);
result = result && wapp_str8_equal(node->item, &(splits1[index1])); result = result && wapp_str8_equal(node, &(splits1[index1]));
++index1; ++index1;
running1 = index1 < count1; running1 = index1 < count1;
@@ -453,8 +453,8 @@ TestFuncResult test_str8_split(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running2) { while (running2) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list2, index2); Str8 *node = wapp_dbl_list_get(Str8, list2, index2);
result = result && wapp_str8_equal(node->item, &(splits2[index2])); result = result && wapp_str8_equal(node, &(splits2[index2]));
++index2; ++index2;
running2 = index2 < count2; running2 = index2 < count2;
@@ -488,8 +488,8 @@ TestFuncResult test_str8_split_with_max(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running) { while (running) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list, index); Str8 *node = wapp_dbl_list_get(Str8, list, index);
result = result && wapp_str8_equal(node->item, &(splits[index])); result = result && wapp_str8_equal(node, &(splits[index]));
++index; ++index;
running = index < count; running = index < count;
@@ -535,8 +535,8 @@ TestFuncResult test_str8_rsplit(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running1) { while (running1) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list1, index1); Str8 *node = wapp_dbl_list_get(Str8, list1, index1);
result = result && wapp_str8_equal(node->item, &(splits1[index1])); result = result && wapp_str8_equal(node, &(splits1[index1]));
++index1; ++index1;
running1 = index1 < count1; running1 = index1 < count1;
@@ -545,8 +545,8 @@ TestFuncResult test_str8_rsplit(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running2) { while (running2) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list2, index2); Str8 *node = wapp_dbl_list_get(Str8, list2, index2);
result = result && wapp_str8_equal(node->item, &(splits2[index2])); result = result && wapp_str8_equal(node, &(splits2[index2]));
++index2; ++index2;
running2 = index2 < count2; running2 = index2 < count2;
@@ -580,8 +580,8 @@ TestFuncResult test_str8_rsplit_with_max(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running) { while (running) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list, index); Str8 *node = wapp_dbl_list_get(Str8, list, index);
result = result && wapp_str8_equal(node->item, &(splits[index])); result = result && wapp_str8_equal(node, &(splits[index]));
++index; ++index;
running = index < count; running = index < count;

View File

@@ -443,8 +443,8 @@ TestFuncResult test_str8_split(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running1) { while (running1) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list1, index1); Str8 *node = wapp_dbl_list_get(Str8, list1, index1);
result = result && wapp_str8_equal(node->item, &(splits1[index1])); result = result && wapp_str8_equal(node, &(splits1[index1]));
++index1; ++index1;
running1 = index1 < count1; running1 = index1 < count1;
@@ -453,8 +453,8 @@ TestFuncResult test_str8_split(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running2) { while (running2) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list2, index2); Str8 *node = wapp_dbl_list_get(Str8, list2, index2);
result = result && wapp_str8_equal(node->item, &(splits2[index2])); result = result && wapp_str8_equal(node, &(splits2[index2]));
++index2; ++index2;
running2 = index2 < count2; running2 = index2 < count2;
@@ -488,8 +488,8 @@ TestFuncResult test_str8_split_with_max(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running) { while (running) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list, index); Str8 *node = wapp_dbl_list_get(Str8, list, index);
result = result && wapp_str8_equal(node->item, &(splits[index])); result = result && wapp_str8_equal(node, &(splits[index]));
++index; ++index;
running = index < count; running = index < count;
@@ -535,8 +535,8 @@ TestFuncResult test_str8_rsplit(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running1) { while (running1) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list1, index1); Str8 *node = wapp_dbl_list_get(Str8, list1, index1);
result = result && wapp_str8_equal(node->item, &(splits1[index1])); result = result && wapp_str8_equal(node, &(splits1[index1]));
++index1; ++index1;
running1 = index1 < count1; running1 = index1 < count1;
@@ -545,8 +545,8 @@ TestFuncResult test_str8_rsplit(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running2) { while (running2) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list2, index2); Str8 *node = wapp_dbl_list_get(Str8, list2, index2);
result = result && wapp_str8_equal(node->item, &(splits2[index2])); result = result && wapp_str8_equal(node, &(splits2[index2]));
++index2; ++index2;
running2 = index2 < count2; running2 = index2 < count2;
@@ -580,8 +580,8 @@ TestFuncResult test_str8_rsplit_with_max(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running) { while (running) {
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, list, index); Str8 *node = wapp_dbl_list_get(Str8, list, index);
result = result && wapp_str8_equal(node->item, &(splits[index])); result = result && wapp_str8_equal(node, &(splits[index]));
++index; ++index;
running = index < count; running = index < count;

View File

@@ -10,33 +10,28 @@ TestFuncResult test_str8_list_get(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
wapp_dbl_list_push_back(Str8, &list, &n4); wapp_dbl_list_push_back(Str8, &list, &s4);
wapp_dbl_list_push_back(Str8, &list, &n5); wapp_dbl_list_push_back(Str8, &list, &s5);
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, &list, 0); Str8 *node = wapp_dbl_list_get(Str8, &list, 0);
result = node->item == &s1 && wapp_str8_equal(node->item, &s1); result = node == &s1 && wapp_str8_equal(node, &s1);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 1); node = wapp_dbl_list_get(Str8, &list, 1);
result = result && node->item == &s2 && wapp_str8_equal(node->item, &s2); result = result && node == &s2 && wapp_str8_equal(node, &s2);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 2); node = wapp_dbl_list_get(Str8, &list, 2);
result = result && node->item == &s3 && wapp_str8_equal(node->item, &s3); result = result && node == &s3 && wapp_str8_equal(node, &s3);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 3); node = wapp_dbl_list_get(Str8, &list, 3);
result = result && node->item == &s4 && wapp_str8_equal(node->item, &s4); result = result && node == &s4 && wapp_str8_equal(node, &s4);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 4); node = wapp_dbl_list_get(Str8, &list, 4);
result = result && node->item == &s5 && wapp_str8_equal(node->item, &s5); result = result && node == &s5 && wapp_str8_equal(node, &s5);
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -48,19 +43,16 @@ TestFuncResult test_str8_list_push_front(void) {
Str8 s2 = wapp_str8_lit("2"); Str8 s2 = wapp_str8_lit("2");
Str8 s3 = wapp_str8_lit("3"); Str8 s3 = wapp_str8_lit("3");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
wapp_dbl_list_push_front(Str8, &list, &n1); wapp_dbl_list_push_front(Str8, &list, &s1);
result = list.first == list.last && list.first == &n1 && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = list.first == list.last && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
wapp_dbl_list_push_front(Str8, &list, &n2); wapp_dbl_list_push_front(Str8, &list, &s2);
result = result && list.first == &n2 && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
wapp_dbl_list_push_front(Str8, &list, &n3); wapp_dbl_list_push_front(Str8, &list, &s3);
result = result && list.first == &n3 && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -72,19 +64,16 @@ TestFuncResult test_str8_list_push_back(void) {
Str8 s2 = wapp_str8_lit("2"); Str8 s2 = wapp_str8_lit("2");
Str8 s3 = wapp_str8_lit("3"); Str8 s3 = wapp_str8_lit("3");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
result = list.first == list.last && list.last == &n1 && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = list.first == list.last && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
result = result && list.last == &n2 && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
result = result && list.last == &n3 && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -100,28 +89,21 @@ TestFuncResult test_str8_list_insert(void) {
Str8 s6 = wapp_str8_lit("6"); Str8 s6 = wapp_str8_lit("6");
Str8 s7 = wapp_str8_lit("7"); Str8 s7 = wapp_str8_lit("7");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
Str8Node n6 = wapp_str8_node_from_str8(s6);
Str8Node n7 = wapp_str8_node_from_str8(s7);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
wapp_dbl_list_push_back(Str8, &list, &n4); wapp_dbl_list_push_back(Str8, &list, &s4);
wapp_dbl_list_push_back(Str8, &list, &n5); wapp_dbl_list_push_back(Str8, &list, &s5);
Str8Node *node; Str8 *node;
wapp_dbl_list_insert(Str8, &list, &n6, 2); wapp_dbl_list_insert(Str8, &list, &s6, 2);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 2); node = wapp_dbl_list_get(Str8, &list, 2);
result = node != NULL && node->item == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6; result = node != NULL && node == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6;
wapp_dbl_list_insert(Str8, &list, &n7, 5); wapp_dbl_list_insert(Str8, &list, &s7, 5);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 5); node = wapp_dbl_list_get(Str8, &list, 5);
result = result && node != NULL && node->item == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7; result = result && node != NULL && node == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -135,33 +117,28 @@ TestFuncResult test_str8_list_pop_front(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
wapp_dbl_list_push_back(Str8, &list, &n4); wapp_dbl_list_push_back(Str8, &list, &s4);
wapp_dbl_list_push_back(Str8, &list, &n5); wapp_dbl_list_push_back(Str8, &list, &s5);
Str8Node *node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); Str8 *node = wapp_dbl_list_pop_front(Str8, &list);
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); node = wapp_dbl_list_pop_front(Str8, &list);
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); node = wapp_dbl_list_pop_front(Str8, &list);
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); node = wapp_dbl_list_pop_front(Str8, &list);
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); node = wapp_dbl_list_pop_front(Str8, &list);
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -175,33 +152,28 @@ TestFuncResult test_str8_list_pop_back(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
wapp_dbl_list_push_front(Str8, &list, &n1); wapp_dbl_list_push_front(Str8, &list, &s1);
wapp_dbl_list_push_front(Str8, &list, &n2); wapp_dbl_list_push_front(Str8, &list, &s2);
wapp_dbl_list_push_front(Str8, &list, &n3); wapp_dbl_list_push_front(Str8, &list, &s3);
wapp_dbl_list_push_front(Str8, &list, &n4); wapp_dbl_list_push_front(Str8, &list, &s4);
wapp_dbl_list_push_front(Str8, &list, &n5); wapp_dbl_list_push_front(Str8, &list, &s5);
Str8Node *node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); Str8 *node = wapp_dbl_list_pop_back(Str8, &list);
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); node = wapp_dbl_list_pop_back(Str8, &list);
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); node = wapp_dbl_list_pop_back(Str8, &list);
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); node = wapp_dbl_list_pop_back(Str8, &list);
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); node = wapp_dbl_list_pop_back(Str8, &list);
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -215,33 +187,28 @@ TestFuncResult test_str8_list_remove(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
wapp_dbl_list_push_back(Str8, &list, &n4); wapp_dbl_list_push_back(Str8, &list, &s4);
wapp_dbl_list_push_back(Str8, &list, &n5); wapp_dbl_list_push_back(Str8, &list, &s5);
Str8Node *node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); Str8 *node = wapp_dbl_list_remove(Str8, &list, 0);
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); node = wapp_dbl_list_remove(Str8, &list, 0);
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); node = wapp_dbl_list_remove(Str8, &list, 0);
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); node = wapp_dbl_list_remove(Str8, &list, 0);
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); node = wapp_dbl_list_remove(Str8, &list, 0);
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -249,11 +216,11 @@ TestFuncResult test_str8_list_remove(void) {
TestFuncResult test_str8_list_empty(void) { TestFuncResult test_str8_list_empty(void) {
b8 result; b8 result;
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
wapp_dbl_list_push_back(Str8, &list, &wapp_str8_node_from_cstr("Hello")); wapp_dbl_list_push_back(Str8, &list, &wapp_str8_lit("Hello"));
wapp_dbl_list_push_back(Str8, &list, &wapp_str8_node_from_cstr("from")); wapp_dbl_list_push_back(Str8, &list, &wapp_str8_lit("from"));
wapp_dbl_list_push_back(Str8, &list, &wapp_str8_node_from_cstr("wizapp")); wapp_dbl_list_push_back(Str8, &list, &wapp_str8_lit("wizapp"));
wapp_dbl_list_push_back(Str8, &list, &wapp_str8_node_from_cstr("stdlib")); wapp_dbl_list_push_back(Str8, &list, &wapp_str8_lit("stdlib"));
wapp_dbl_list_empty(Str8, &list); wapp_dbl_list_empty(Str8, &list);

View File

@@ -10,33 +10,28 @@ TestFuncResult test_str8_list_get(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
wapp_dbl_list_push_back(Str8, &list, &n4); wapp_dbl_list_push_back(Str8, &list, &s4);
wapp_dbl_list_push_back(Str8, &list, &n5); wapp_dbl_list_push_back(Str8, &list, &s5);
Str8Node *node = wapp_dbl_list_get(Str8, Str8Node, &list, 0); Str8 *node = wapp_dbl_list_get(Str8, &list, 0);
result = node->item == &s1 && wapp_str8_equal(node->item, &s1); result = node == &s1 && wapp_str8_equal(node, &s1);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 1); node = wapp_dbl_list_get(Str8, &list, 1);
result = result && node->item == &s2 && wapp_str8_equal(node->item, &s2); result = result && node == &s2 && wapp_str8_equal(node, &s2);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 2); node = wapp_dbl_list_get(Str8, &list, 2);
result = result && node->item == &s3 && wapp_str8_equal(node->item, &s3); result = result && node == &s3 && wapp_str8_equal(node, &s3);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 3); node = wapp_dbl_list_get(Str8, &list, 3);
result = result && node->item == &s4 && wapp_str8_equal(node->item, &s4); result = result && node == &s4 && wapp_str8_equal(node, &s4);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 4); node = wapp_dbl_list_get(Str8, &list, 4);
result = result && node->item == &s5 && wapp_str8_equal(node->item, &s5); result = result && node == &s5 && wapp_str8_equal(node, &s5);
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -48,19 +43,16 @@ TestFuncResult test_str8_list_push_front(void) {
Str8 s2 = wapp_str8_lit("2"); Str8 s2 = wapp_str8_lit("2");
Str8 s3 = wapp_str8_lit("3"); Str8 s3 = wapp_str8_lit("3");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
wapp_dbl_list_push_front(Str8, &list, &n1); wapp_dbl_list_push_front(Str8, &list, &s1);
result = list.first == list.last && list.first == &n1 && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = list.first == list.last && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
wapp_dbl_list_push_front(Str8, &list, &n2); wapp_dbl_list_push_front(Str8, &list, &s2);
result = result && list.first == &n2 && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
wapp_dbl_list_push_front(Str8, &list, &n3); wapp_dbl_list_push_front(Str8, &list, &s3);
result = result && list.first == &n3 && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -72,19 +64,16 @@ TestFuncResult test_str8_list_push_back(void) {
Str8 s2 = wapp_str8_lit("2"); Str8 s2 = wapp_str8_lit("2");
Str8 s3 = wapp_str8_lit("3"); Str8 s3 = wapp_str8_lit("3");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
result = list.first == list.last && list.last == &n1 && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = list.first == list.last && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
result = result && list.last == &n2 && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
result = result && list.last == &n3 && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -100,28 +89,21 @@ TestFuncResult test_str8_list_insert(void) {
Str8 s6 = wapp_str8_lit("6"); Str8 s6 = wapp_str8_lit("6");
Str8 s7 = wapp_str8_lit("7"); Str8 s7 = wapp_str8_lit("7");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
Str8Node n6 = wapp_str8_node_from_str8(s6);
Str8Node n7 = wapp_str8_node_from_str8(s7);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
wapp_dbl_list_push_back(Str8, &list, &n4); wapp_dbl_list_push_back(Str8, &list, &s4);
wapp_dbl_list_push_back(Str8, &list, &n5); wapp_dbl_list_push_back(Str8, &list, &s5);
Str8Node *node; Str8 *node;
wapp_dbl_list_insert(Str8, &list, &n6, 2); wapp_dbl_list_insert(Str8, &list, &s6, 2);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 2); node = wapp_dbl_list_get(Str8, &list, 2);
result = node != NULL && node->item == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6; result = node != NULL && node == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6;
wapp_dbl_list_insert(Str8, &list, &n7, 5); wapp_dbl_list_insert(Str8, &list, &s7, 5);
node = wapp_dbl_list_get(Str8, Str8Node, &list, 5); node = wapp_dbl_list_get(Str8, &list, 5);
result = result && node != NULL && node->item == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7; result = result && node != NULL && node == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -135,33 +117,28 @@ TestFuncResult test_str8_list_pop_front(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
wapp_dbl_list_push_back(Str8, &list, &n4); wapp_dbl_list_push_back(Str8, &list, &s4);
wapp_dbl_list_push_back(Str8, &list, &n5); wapp_dbl_list_push_back(Str8, &list, &s5);
Str8Node *node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); Str8 *node = wapp_dbl_list_pop_front(Str8, &list);
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); node = wapp_dbl_list_pop_front(Str8, &list);
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); node = wapp_dbl_list_pop_front(Str8, &list);
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); node = wapp_dbl_list_pop_front(Str8, &list);
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
node = wapp_dbl_list_pop_front(Str8, Str8Node, &list); node = wapp_dbl_list_pop_front(Str8, &list);
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -175,33 +152,28 @@ TestFuncResult test_str8_list_pop_back(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
wapp_dbl_list_push_front(Str8, &list, &n1); wapp_dbl_list_push_front(Str8, &list, &s1);
wapp_dbl_list_push_front(Str8, &list, &n2); wapp_dbl_list_push_front(Str8, &list, &s2);
wapp_dbl_list_push_front(Str8, &list, &n3); wapp_dbl_list_push_front(Str8, &list, &s3);
wapp_dbl_list_push_front(Str8, &list, &n4); wapp_dbl_list_push_front(Str8, &list, &s4);
wapp_dbl_list_push_front(Str8, &list, &n5); wapp_dbl_list_push_front(Str8, &list, &s5);
Str8Node *node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); Str8 *node = wapp_dbl_list_pop_back(Str8, &list);
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); node = wapp_dbl_list_pop_back(Str8, &list);
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); node = wapp_dbl_list_pop_back(Str8, &list);
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); node = wapp_dbl_list_pop_back(Str8, &list);
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
node = wapp_dbl_list_pop_back(Str8, Str8Node, &list); node = wapp_dbl_list_pop_back(Str8, &list);
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -215,33 +187,28 @@ TestFuncResult test_str8_list_remove(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node n1 = wapp_str8_node_from_str8(s1);
Str8Node n2 = wapp_str8_node_from_str8(s2);
Str8Node n3 = wapp_str8_node_from_str8(s3);
Str8Node n4 = wapp_str8_node_from_str8(s4);
Str8Node n5 = wapp_str8_node_from_str8(s5);
wapp_dbl_list_push_back(Str8, &list, &n1); wapp_dbl_list_push_back(Str8, &list, &s1);
wapp_dbl_list_push_back(Str8, &list, &n2); wapp_dbl_list_push_back(Str8, &list, &s2);
wapp_dbl_list_push_back(Str8, &list, &n3); wapp_dbl_list_push_back(Str8, &list, &s3);
wapp_dbl_list_push_back(Str8, &list, &n4); wapp_dbl_list_push_back(Str8, &list, &s4);
wapp_dbl_list_push_back(Str8, &list, &n5); wapp_dbl_list_push_back(Str8, &list, &s5);
Str8Node *node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); Str8 *node = wapp_dbl_list_remove(Str8, &list, 0);
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); node = wapp_dbl_list_remove(Str8, &list, 0);
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); node = wapp_dbl_list_remove(Str8, &list, 0);
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); node = wapp_dbl_list_remove(Str8, &list, 0);
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
node = wapp_dbl_list_remove(Str8, Str8Node, &list, 0); node = wapp_dbl_list_remove(Str8, &list, 0);
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0; result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
return wapp_tester_result(result); return wapp_tester_result(result);
} }
@@ -249,18 +216,18 @@ TestFuncResult test_str8_list_remove(void) {
TestFuncResult test_str8_list_empty(void) { TestFuncResult test_str8_list_empty(void) {
b8 result; b8 result;
Str8List list = wapp_dbl_list(Str8, Str8List); Str8List list = wapp_dbl_list(Str8);
Str8Node hello = wapp_str8_node_from_cstr("Hello"); Str8 hello = wapp_str8_lit("Hello");
wapp_dbl_list_push_back(Str8, &list, &hello); wapp_dbl_list_push_back(Str8, &list, &hello);
Str8Node from = wapp_str8_node_from_cstr("from"); Str8 from = wapp_str8_lit("from");
wapp_dbl_list_push_back(Str8, &list, &from); wapp_dbl_list_push_back(Str8, &list, &from);
Str8Node wizapp = wapp_str8_node_from_cstr("wizapp"); Str8 wizapp = wapp_str8_lit("wizapp");
wapp_dbl_list_push_back(Str8, &list, &wizapp); wapp_dbl_list_push_back(Str8, &list, &wizapp);
Str8Node stdlib = wapp_str8_node_from_cstr("stdlib"); Str8 stdlib = wapp_str8_lit("stdlib");
wapp_dbl_list_push_back(Str8, &list, &stdlib); wapp_dbl_list_push_back(Str8, &list, &stdlib);
wapp_dbl_list_empty(Str8, &list); wapp_dbl_list_empty(Str8, &list);