mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
command list parse: different operators
This commit is contained in:
parent
1c00020c86
commit
659c9f57ff
3 changed files with 79 additions and 9 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 17:40:48 by khais #+# #+# */
|
||||
/* Updated: 2025/02/25 15:02:03 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/25 15:10:29 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -89,8 +89,8 @@ 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->operators[0] == OP_END);
|
||||
assert(cmd->num_pipelines == 1);
|
||||
command_list_destroy(cmd);
|
||||
}
|
||||
|
|
@ -99,8 +99,8 @@ 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, 0);
|
||||
assert(cmd->operators[0] == OP_AND);
|
||||
assert_pipelineequal("echo works | wc -c", cmd, 1);
|
||||
assert(cmd->num_pipelines == 2);
|
||||
command_list_destroy(cmd);
|
||||
|
|
@ -111,8 +111,8 @@ 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(cmd->operators[0] == OP_OR);
|
||||
assert_pipelineequal("echo works | wc -c", cmd, 1);
|
||||
assert(cmd->operator == OP_OR);
|
||||
assert(cmd->num_pipelines == 2);
|
||||
command_list_destroy(cmd);
|
||||
}
|
||||
|
|
@ -122,13 +122,43 @@ 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(cmd->operators[0] == OP_OR);
|
||||
assert_pipelineequal("echo works | wc -c", cmd, 1);
|
||||
assert(cmd->operators[1] == OP_OR);
|
||||
assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2);
|
||||
assert(cmd->operator == OP_OR);
|
||||
assert(cmd->num_pipelines == 3);
|
||||
command_list_destroy(cmd);
|
||||
}
|
||||
|
||||
static void test_parse_command_list_triple_both_operators(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(cmd->operators[0] == OP_OR);
|
||||
assert_pipelineequal("echo works | wc -c", cmd, 1);
|
||||
assert(cmd->operators[1] == OP_AND);
|
||||
assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2);
|
||||
assert(cmd->operators[2] == OP_END);
|
||||
assert(cmd->num_pipelines == 3);
|
||||
command_list_destroy(cmd);
|
||||
}
|
||||
|
||||
static void test_parse_command_list_quad_both_operators(void)
|
||||
{
|
||||
t_command_list *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1 || echo final");
|
||||
assert(cmd != NULL);
|
||||
assert_pipelineequal("echo this | cat -e", cmd, 0);
|
||||
assert(cmd->operators[0] == OP_OR);
|
||||
assert_pipelineequal("echo works | wc -c", cmd, 1);
|
||||
assert(cmd->operators[1] == OP_AND);
|
||||
assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2);
|
||||
assert(cmd->operators[2] == OP_OR);
|
||||
assert_pipelineequal("echo final", cmd, 3);
|
||||
assert(cmd->operators[3] == OP_END);
|
||||
command_list_destroy(cmd);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_parse_command_list_empty();
|
||||
|
|
@ -136,5 +166,7 @@ int main(void)
|
|||
test_parse_command_list_simple_and();
|
||||
test_parse_command_list_simple_or();
|
||||
test_parse_command_list_triple_or();
|
||||
test_parse_command_list_triple_both_operators();
|
||||
test_parse_command_list_quad_both_operators();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue