diff --git a/src/parser/command_list/command_list.c b/src/parser/command_list/command_list.c index 133d552..a24c7e0 100644 --- a/src/parser/command_list/command_list.c +++ b/src/parser/command_list/command_list.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:49:46 by khais #+# #+# */ -/* Updated: 2025/02/25 13:29:39 by khais ### ########.fr */ +/* Updated: 2025/02/25 13:33:53 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,8 @@ static t_operator match_op(char *op) { if (ft_strcmp("&&", op) == 0) return (OP_AND); + if (ft_strcmp("||", op) == 0) + return (OP_OR); return (OP_INVALID); } diff --git a/tests/parse_command_lists.c b/tests/parse_command_lists.c index 1f14f4e..64eaa51 100644 --- a/tests/parse_command_lists.c +++ b/tests/parse_command_lists.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:40:48 by khais #+# #+# */ -/* Updated: 2025/02/25 13:26:14 by khais ### ########.fr */ +/* Updated: 2025/02/25 13:32:27 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ static t_command_list *parse_command_list(char *input) { + ft_dprintf(STDERR_FILENO, "Now checking command list with input [%s]\n", input); t_wordlist *words = minishell_wordsplit(input); t_command_list *cmd = command_list_from_wordlist(words); return (cmd); @@ -98,10 +99,22 @@ static void test_parse_command_list_simple_and(void) command_list_destroy(cmd); } +static void test_parse_command_list_simple_or(void) +{ + t_command_list *cmd = parse_command_list("echo this | cat -e || echo works | wc -c"); + assert(cmd != NULL); + assert_pipelineequal("echo this | cat -e", cmd, 0); + assert_pipelineequal("echo works | wc -c", cmd, 1); + assert(cmd->operator == OP_OR); + assert(cmd->num_pipelines == 2); + command_list_destroy(cmd); +} + int main(void) { test_parse_command_list_empty(); test_parse_command_list_single_pipeline(); test_parse_command_list_simple_and(); + test_parse_command_list_simple_or(); return (0); }