2025-02-21 12:35:51 +01:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* parse_simple_cmds.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2025/02/21 12:20:20 by khais #+# #+# */
|
2025-03-07 11:55:51 +01:00
|
|
|
/* Updated: 2025/03/07 12:32:04 by khais ### ########.fr */
|
2025-02-21 12:35:51 +01:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include "../src/parser/simple_cmd/simple_cmd.h"
|
|
|
|
|
#include "../src/parser/wordsplit/wordsplit.h"
|
|
|
|
|
#include "../src/parser/wordlist/wordlist.h"
|
2025-02-21 12:48:35 +01:00
|
|
|
#include "testutil.h"
|
2025-02-21 12:35:51 +01:00
|
|
|
|
|
|
|
|
static t_simple_cmd *parse_simple_cmd(char *input)
|
|
|
|
|
{
|
|
|
|
|
t_wordlist *words = minishell_wordsplit(input);
|
|
|
|
|
t_simple_cmd *cmd = simple_cmd_from_wordlist(words);
|
|
|
|
|
return (cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_parse_empty_command(void)
|
|
|
|
|
{
|
|
|
|
|
t_simple_cmd *cmd = parse_simple_cmd("");
|
|
|
|
|
assert(cmd != NULL);
|
|
|
|
|
simple_cmd_destroy(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-21 12:48:35 +01:00
|
|
|
static void test_parse_nonempty_command(void)
|
|
|
|
|
{
|
|
|
|
|
t_simple_cmd *cmd = parse_simple_cmd("echo Hello World!");
|
|
|
|
|
assert(cmd != NULL);
|
|
|
|
|
assert_strequal("echo", wordlist_get(cmd->words, 0)->word);
|
|
|
|
|
assert_strequal("Hello", wordlist_get(cmd->words, 1)->word);
|
|
|
|
|
assert_strequal("World!", wordlist_get(cmd->words, 2)->word);
|
|
|
|
|
simple_cmd_destroy(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-21 12:35:51 +01:00
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
test_parse_empty_command();
|
2025-02-21 12:48:35 +01:00
|
|
|
test_parse_nonempty_command();
|
2025-02-21 12:35:51 +01:00
|
|
|
return (0);
|
|
|
|
|
}
|