command list parse: handle triple pipeline separated with ||

This commit is contained in:
Khaïs COLIN 2025-02-25 13:46:11 +01:00 committed by Khaïs COLIN
parent e6dd1d6a56
commit 1c00020c86
2 changed files with 42 additions and 11 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:40:48 by khais #+# #+# */
/* Updated: 2025/02/25 13:32:27 by khais ### ########.fr */
/* Updated: 2025/02/25 15:02:03 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -60,6 +60,13 @@ static void assert_pipelineequal(char *expected, t_command_list *cmd, int idx)
ft_dprintf(STDERR_FILENO, "Expected pipeline %p to equal [%s]\n", got, expected);
t_pipeline *expected_pipeline = parse_pipeline(expected);
assert(expected_pipeline == got || expected_pipeline != NULL);
int j = 0;
while (j < got->num_cmd)
{
ft_dprintf(STDERR_FILENO, "Got pipeline cmd %d: ", j);
wordlist_debug(got->cmds[j]->words);
j++;
}
ft_dprintf(STDERR_FILENO, "Expected pipeline to have %d commands, got pipeline with %d\n", expected_pipeline->num_cmd, got->num_cmd);
assert(expected_pipeline->num_cmd == got->num_cmd);
int i = 0;
@ -110,11 +117,24 @@ static void test_parse_command_list_simple_or(void)
command_list_destroy(cmd);
}
static void test_parse_command_list_triple_or(void)
{
t_command_list *cmd = parse_command_list("echo this | cat -e || echo works | wc -c || echo as well | cut -d' ' -f1");
assert(cmd != NULL);
assert_pipelineequal("echo this | cat -e", cmd, 0);
assert_pipelineequal("echo works | wc -c", cmd, 1);
assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2);
assert(cmd->operator == OP_OR);
assert(cmd->num_pipelines == 3);
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();
test_parse_command_list_triple_or();
return (0);
}