From 9d35ddb703d7ba22bdd6cdbaaf3b5c992ec79025 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 24 Oct 2025 15:14:07 -0500 Subject: add list copy --- lichen.test.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lichen.test.c') diff --git a/lichen.test.c b/lichen.test.c index 622f480..946e0be 100644 --- a/lichen.test.c +++ b/lichen.test.c @@ -146,6 +146,35 @@ LILY_TEST("mix prepends and appends") { #include LILY_PUSH_TEST() +void * copy_int(void *n) { + int *copy = malloc(sizeof(int)); + *copy = *((int*)n); + return copy; +} +LILY_TEST("copy a list") { + struct li_ll_t *list_a = li_alloc_ll(); + list_a->tag = 8; + int a = 1; int b = 2; int c = 3; + li_ll_append(list_a, &a); + li_ll_append(list_a, &b); + li_ll_append(list_a, &c); + + struct li_ll_t *list_b; + li_copy_list(&list_b, list_a, copy_int); + li_free_ll(list_a, do_nothing); + + REQUIRE_NEQ(list_b, NULL, "%p"); + CHECK_EQ(list_b->tag, 8, "%d"); + CHECK_EQ(list_b->count, 3, "%d"); + CHECK_EQ(*((int*)list_b->head->data), a, "%d"); + CHECK_EQ(*((int*)list_b->head->next->data), b, "%d"); + CHECK_EQ(*((int*)list_b->head->next->next->data), c, "%d"); + + li_free_ll(list_b, free); +} +#include LILY_PUSH_TEST() + + #define LILY_FILE_END #include LILY_REGISTER_TESTS() -- cgit v1.2.1