2025-03-10 14:22:58 +01:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* test_wordlist_idx.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2025/03/10 14:59:19 by khais #+# #+# */
|
2025-04-08 16:36:11 +02:00
|
|
|
/* Updated: 2025/04/08 16:35:12 by khais ### ########.fr */
|
2025-03-10 14:22:58 +01:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "testutil.h"
|
|
|
|
|
#include "libft.h"
|
|
|
|
|
#include "../src/parser/wordlist/wordlist.h"
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
static void test_wordlist_idx_pop_null(void)
|
|
|
|
|
{
|
|
|
|
|
t_wordlist *list;
|
|
|
|
|
|
|
|
|
|
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
|
|
|
|
assert(NULL == wordlist_pop_idx(NULL, 10));
|
|
|
|
|
list = NULL;
|
|
|
|
|
assert(NULL == wordlist_pop_idx(&list, 10));
|
|
|
|
|
do_leak_check();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_wordlist_idx_pop_single_elem(void)
|
|
|
|
|
{
|
|
|
|
|
t_wordlist *list;
|
|
|
|
|
t_worddesc *got;
|
|
|
|
|
|
|
|
|
|
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
2025-04-08 16:36:11 +02:00
|
|
|
list = wordlist_create(worddesc_create(ft_strdup("hello"), 0, ft_strdup(""), WORD_TOKEN));
|
2025-03-10 14:22:58 +01:00
|
|
|
assert(NULL == wordlist_pop_idx(&list, 1));
|
|
|
|
|
got = wordlist_pop_idx(&list, 0);
|
|
|
|
|
assert(NULL != got);
|
|
|
|
|
assert(NULL == list);
|
|
|
|
|
assert_strequal("hello", got->word);
|
|
|
|
|
assert(NULL == wordlist_pop_idx(&list, 0));
|
|
|
|
|
do_leak_check();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_wordlist_idx_pop_second_then_first(void)
|
|
|
|
|
{
|
|
|
|
|
t_wordlist *list;
|
|
|
|
|
t_worddesc *got;
|
|
|
|
|
|
|
|
|
|
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
2025-04-08 16:36:11 +02:00
|
|
|
list = wordlist_create(worddesc_create(ft_strdup("hello"), 0, NULL, WORD_TOKEN));
|
|
|
|
|
list = wordlist_push(list, worddesc_create(ft_strdup("world"), 0, NULL, WORD_TOKEN));
|
2025-03-10 14:22:58 +01:00
|
|
|
wordlist_debug(list);
|
|
|
|
|
got = wordlist_pop_idx(&list, 1);
|
|
|
|
|
assert(NULL != got);
|
|
|
|
|
assert(NULL != list);
|
|
|
|
|
assert_strequal("world", got->word);
|
|
|
|
|
got = wordlist_pop_idx(&list, 0);
|
|
|
|
|
assert(NULL != got);
|
|
|
|
|
assert(NULL == list);
|
|
|
|
|
assert_strequal("hello", got->word);
|
|
|
|
|
do_leak_check();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
test_wordlist_idx_pop_null();
|
|
|
|
|
test_wordlist_idx_pop_single_elem();
|
|
|
|
|
test_wordlist_idx_pop_second_then_first();
|
|
|
|
|
return (0);
|
|
|
|
|
}
|