From bc5be67bf676a140fc542c3fb7118a2edbd2270d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 11 Mar 2025 15:20:19 +0100 Subject: [PATCH] cmdgroup parsing: parse empty wordlist --- Makefile | 1 + src/parser/cmdgroup/cmdgroup.c | 25 ++++++++++++++++++ src/parser/cmdgroup/cmdgroup.h | 25 ++++++++++++++++++ tests/Makefile | 1 + tests/test_cmdgroup_parsing.c | 46 ++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 src/parser/cmdgroup/cmdgroup.c create mode 100644 src/parser/cmdgroup/cmdgroup.h create mode 100644 tests/test_cmdgroup_parsing.c diff --git a/Makefile b/Makefile index 3c50bc9..77e2fee 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ srcs = \ src/executing/here_doc/strip_newline.c \ src/ft_errno.c \ src/get_command.c \ + src/parser/cmdgroup/cmdgroup.c \ src/parser/command_list/command_list_builder.c \ src/parser/command_list/command_list.c \ src/parser/command_list/operator.c \ diff --git a/src/parser/cmdgroup/cmdgroup.c b/src/parser/cmdgroup/cmdgroup.c new file mode 100644 index 0000000..bc1ff1a --- /dev/null +++ b/src/parser/cmdgroup/cmdgroup.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cmdgroup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/11 15:18:02 by khais #+# #+# */ +/* Updated: 2025/03/11 15:18:59 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cmdgroup.h" +#include + +t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words) +{ + (void)words; + return (NULL); +} + +void cmdgroup_destroy(t_cmdgroup *cmd) +{ + (void)cmd; +} diff --git a/src/parser/cmdgroup/cmdgroup.h b/src/parser/cmdgroup/cmdgroup.h new file mode 100644 index 0000000..082c600 --- /dev/null +++ b/src/parser/cmdgroup/cmdgroup.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cmdgroup.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/11 15:11:57 by khais #+# #+# */ +/* Updated: 2025/03/11 15:17:22 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CMDGROUP_H +# define CMDGROUP_H + +# include "../wordlist/wordlist.h" + +typedef struct s_cmdgroup +{ +} t_cmdgroup; + +t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words); +void cmdgroup_destroy(t_cmdgroup *cmd); + +#endif // CMDGROUP_H diff --git a/tests/Makefile b/tests/Makefile index 5c35dbd..56f3606 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -2,6 +2,7 @@ # file are prefixed with test_ rawtests = \ expansion \ + test_cmdgroup_parsing \ test_here_doc \ test_wordlist_idx \ test_redirection_parsing \ diff --git a/tests/test_cmdgroup_parsing.c b/tests/test_cmdgroup_parsing.c new file mode 100644 index 0000000..a5acd9e --- /dev/null +++ b/tests/test_cmdgroup_parsing.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test_cmdgroup_parsing.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/11 15:07:23 by khais #+# #+# */ +/* Updated: 2025/03/11 15:20:17 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "testutil.h" +#include +#include "libft.h" +#include "../src/parser/cmdgroup/cmdgroup.h" +#include "../src/parser/wordsplit/wordsplit.h" + +static t_cmdgroup *parse_cmdgroup(char *input) +{ + ft_dprintf(STDERR_FILENO, "Now checking command group with input [%s]\n", input); + t_wordlist *words = minishell_wordsplit(input); + t_cmdgroup *cmd = cmdgroup_from_wordlist(words); + wordlist_destroy(words); + return (cmd); +} + +static void test_cmdgroup_parsing_empty(void) +{ + t_cmdgroup *cmd; + + // arange + ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); + cmd = parse_cmdgroup(""); + // assert + assert(NULL == cmd); + // cleanup + cmdgroup_destroy(cmd); + do_leak_check(); +} + +int main(void) +{ + test_cmdgroup_parsing_empty(); + return (0); +}