mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
command list parse: handle single pipeline
This commit is contained in:
parent
3b36a77d34
commit
36fa53131a
3 changed files with 111 additions and 27 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 17:40:48 by khais #+# #+# */
|
||||
/* Updated: 2025/02/25 12:34:07 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/25 13:26:14 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -51,8 +51,11 @@ static void assert_simple_commandequal(t_simple_cmd *expected, t_simple_cmd *got
|
|||
assert(got_word == NULL);
|
||||
}
|
||||
|
||||
static void assert_pipelineequal(char *expected, t_pipeline *got)
|
||||
static void assert_pipelineequal(char *expected, t_command_list *cmd, int idx)
|
||||
{
|
||||
ft_printf("Expected command list %p to have at least %d pipelines, and got %d\n", cmd, idx + 1, cmd->num_pipelines);
|
||||
assert(cmd->num_pipelines >= idx + 1);
|
||||
t_pipeline *got = cmd->pipelines[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);
|
||||
|
|
@ -74,19 +77,31 @@ static void test_parse_command_list_empty(void)
|
|||
command_list_destroy(cmd);
|
||||
}
|
||||
|
||||
static void test_parse_command_list_single_pipeline(void)
|
||||
{
|
||||
t_command_list *cmd = parse_command_list("echo this | cat -e");
|
||||
assert(cmd != NULL);
|
||||
assert(cmd->operator == OP_INVALID);
|
||||
assert_pipelineequal("echo this | cat -e", cmd, 0);
|
||||
assert(cmd->num_pipelines == 1);
|
||||
command_list_destroy(cmd);
|
||||
}
|
||||
|
||||
static void test_parse_command_list_simple_and(void)
|
||||
{
|
||||
t_command_list *cmd = parse_command_list("echo this | cat -e && echo works | wc -c");
|
||||
assert(cmd != NULL);
|
||||
assert(cmd->operator == OP_AND);
|
||||
assert_pipelineequal("echo this | cat -e", cmd->pipeline_left);
|
||||
assert_pipelineequal("echo works | wc -c", cmd->pipeline_right);
|
||||
assert_pipelineequal("echo this | cat -e", cmd, 0);
|
||||
assert_pipelineequal("echo works | wc -c", cmd, 1);
|
||||
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();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue