command list refactor: rename t_command_list to t_cmdlist

This commit is contained in:
Khaïs COLIN 2025-02-25 15:15:23 +01:00 committed by Khaïs COLIN
parent 659c9f57ff
commit 5fceb4713d
3 changed files with 33 additions and 33 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 15:10:29 by khais ### ########.fr */
/* Updated: 2025/02/25 15:25:14 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,11 +17,11 @@
#include "unistd.h"
#include <assert.h>
static t_command_list *parse_command_list(char *input)
static t_cmdlist *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);
t_cmdlist *cmd = cmdlist_from_wordlist(words);
return (cmd);
}
@ -52,7 +52,7 @@ static void assert_simple_commandequal(t_simple_cmd *expected, t_simple_cmd *got
assert(got_word == NULL);
}
static void assert_pipelineequal(char *expected, t_command_list *cmd, int idx)
static void assert_pipelineequal(char *expected, t_cmdlist *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);
@ -80,46 +80,46 @@ static void assert_pipelineequal(char *expected, t_command_list *cmd, int idx)
static void test_parse_command_list_empty(void)
{
t_command_list *cmd = parse_command_list("");
t_cmdlist *cmd = parse_command_list("");
assert(cmd == NULL);
command_list_destroy(cmd);
cmdlist_destroy(cmd);
}
static void test_parse_command_list_single_pipeline(void)
{
t_command_list *cmd = parse_command_list("echo this | cat -e");
t_cmdlist *cmd = parse_command_list("echo this | cat -e");
assert(cmd != NULL);
assert_pipelineequal("echo this | cat -e", cmd, 0);
assert(cmd->operators[0] == OP_END);
assert(cmd->num_pipelines == 1);
command_list_destroy(cmd);
cmdlist_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");
t_cmdlist *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_AND);
assert_pipelineequal("echo works | wc -c", cmd, 1);
assert(cmd->num_pipelines == 2);
command_list_destroy(cmd);
cmdlist_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");
t_cmdlist *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->num_pipelines == 2);
command_list_destroy(cmd);
cmdlist_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");
t_cmdlist *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);
@ -127,12 +127,12 @@ static void test_parse_command_list_triple_or(void)
assert(cmd->operators[1] == OP_OR);
assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2);
assert(cmd->num_pipelines == 3);
command_list_destroy(cmd);
cmdlist_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");
t_cmdlist *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);
@ -141,12 +141,12 @@ static void test_parse_command_list_triple_both_operators(void)
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);
cmdlist_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");
t_cmdlist *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);
@ -156,7 +156,7 @@ static void test_parse_command_list_quad_both_operators(void)
assert(cmd->operators[2] == OP_OR);
assert_pipelineequal("echo final", cmd, 3);
assert(cmd->operators[3] == OP_END);
command_list_destroy(cmd);
cmdlist_destroy(cmd);
}
int main(void)