cmdgroup parsing: start implementing the new architecture

This commit is contained in:
Khaïs COLIN 2025-03-18 11:48:03 +01:00
parent d6bb24df54
commit f9aa614ef2
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 18 additions and 30 deletions

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/18 11:43/36 by khais #+# #+# */
/* Updated: 2025/03/18 11:43:36 by khais ### ########.fr */
/* Created: 2025/03/18 11:49/19 by khais #+# #+# */
/* Updated: 2025/03/18 11:49:19 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,9 +39,7 @@ static void test_cmdgroup_parsing_single_cmdlist(void)
cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c");
// assert
assert(NULL != cmd);
assert(1 == cmd->item_num);
assert(TYPE_LIST == cmd->items[0].type);
assert_cmdgroup_itemlistequal("echo this | cat -e && echo works | wc -c", cmd, 0);
// TODO
// cleanup
cmdgroup_destroy(cmd);
do_leak_check();
@ -55,9 +53,8 @@ static void test_cmdgroup_parsing_two_cmdlist(void)
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c");
// assert
// TODO
assert(NULL != cmd);
assert(1 == cmd->item_num);
assert(TYPE_LIST == cmd->items[0].type);
assert_cmdgroup_itemlistequal("echo this | cat -e && echo works | wc -c", cmd, 0);
// cleanup
cmdgroup_destroy(cmd);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 15:21:09 by khais #+# #+# */
/* Updated: 2025/03/11 18:12:05 by khais ### ########.fr */
/* Updated: 2025/03/18 11:50:23 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -128,24 +128,17 @@ t_cmdgroup *parse_cmdgroup(char *input)
void assert_cmdgroup_itemlistequal(char *expected_str, t_cmdgroup *got_cmd, int item_number)
{
ft_dprintf(STDERR_FILENO, "checking that item %d of cmdlist %p matches [%s]\n", item_number, got_cmd, expected_str);
ft_dprintf(STDERR_FILENO, "expecteing to have at least %d items, and got %d\n", item_number + 1, got_cmd->item_num);
assert(got_cmd->item_num > item_number);
ft_dprintf(STDERR_FILENO, "expecteing item %p to be of type list got %d\n", got_cmd->items[item_number], got_cmd->items[item_number].type);
t_cmdlist *expected = parse_command_list(expected_str);
t_cmdlist *got = got_cmd->items[item_number].inner.cmdlist;
if (expected == NULL)
{
ft_dprintf(STDERR_FILENO, "expecting the list to be null\n");
assert(expected == got);
return ;
}
ft_dprintf(STDERR_FILENO, "checking if the list matches...\n");
assert(expected->num_pipelines == got->num_pipelines);
int i = 0;
while (i < expected->num_pipelines)
{
assert_pipelineequal_raw(expected->pipelines[i], got->pipelines[i]);
assert(expected->operators[i] == got->operators[i]);
i++;
}
assert(false && "not yet implemented");
}