mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
redirection parsing: handle other types of redirection
This commit is contained in:
parent
47ac767f2a
commit
d196649106
3 changed files with 60 additions and 2 deletions
|
|
@ -104,6 +104,55 @@ static void test_redirection_parsing_null(void)
|
|||
do_leak_check();
|
||||
}
|
||||
|
||||
static void test_redirection_parsing_input_in_middle(void)
|
||||
{
|
||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
||||
t_simple_cmd *cmd = parse_simple_cmd("echo hello <outfile world");
|
||||
assert(parse_redirections(cmd) != NULL);
|
||||
assert_strequal("echo", cmd->words->word->word);
|
||||
assert_strequal("hello", cmd->words->next->word->word);
|
||||
assert_strequal("world", cmd->words->next->next->word->word);
|
||||
assert(NULL == cmd->words->next->next->next);
|
||||
assert_strequal("outfile", cmd->redirections->redirection->marker->word);
|
||||
assert(cmd->redirections->redirection->type == REDIR_INPUT);
|
||||
assert(cmd->redirections->next == NULL);
|
||||
simple_cmd_destroy(cmd);
|
||||
do_leak_check();
|
||||
}
|
||||
|
||||
static void test_redirection_parsing_here_doc_in_middle(void)
|
||||
{
|
||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
||||
t_simple_cmd *cmd = parse_simple_cmd("echo hello <<outfile world");
|
||||
assert(parse_redirections(cmd) != NULL);
|
||||
assert_strequal("echo", cmd->words->word->word);
|
||||
assert_strequal("hello", cmd->words->next->word->word);
|
||||
assert_strequal("world", cmd->words->next->next->word->word);
|
||||
assert(NULL == cmd->words->next->next->next);
|
||||
assert_strequal("outfile", cmd->redirections->redirection->marker->word);
|
||||
assert(cmd->redirections->redirection->type == REDIR_HERE_DOC);
|
||||
assert(cmd->redirections->next == NULL);
|
||||
simple_cmd_destroy(cmd);
|
||||
do_leak_check();
|
||||
}
|
||||
|
||||
|
||||
static void test_redirection_parsing_append_in_middle(void)
|
||||
{
|
||||
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
|
||||
t_simple_cmd *cmd = parse_simple_cmd("echo hello >> outfile world");
|
||||
assert(parse_redirections(cmd) != NULL);
|
||||
assert_strequal("echo", cmd->words->word->word);
|
||||
assert_strequal("hello", cmd->words->next->word->word);
|
||||
assert_strequal("world", cmd->words->next->next->word->word);
|
||||
assert(NULL == cmd->words->next->next->next);
|
||||
assert_strequal("outfile", cmd->redirections->redirection->marker->word);
|
||||
assert(cmd->redirections->redirection->type == REDIR_APPEND);
|
||||
assert(cmd->redirections->next == NULL);
|
||||
simple_cmd_destroy(cmd);
|
||||
do_leak_check();
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
test_redirection_parsing_no_redirections();
|
||||
|
|
@ -112,5 +161,8 @@ int main(void) {
|
|||
test_redirection_parsing_output_in_middle();
|
||||
test_redirection_parsing_output_no_filename_at_end();
|
||||
test_redirection_parsing_null();
|
||||
test_redirection_parsing_input_in_middle();
|
||||
test_redirection_parsing_here_doc_in_middle();
|
||||
test_redirection_parsing_append_in_middle();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue