mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
word splitting: a single word is not split
Sorry this commit is a bit big, lots of groudwork is being established here
This commit is contained in:
parent
871571e258
commit
a083800506
9 changed files with 262 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
rawtests = \
|
||||
test_env_manip \
|
||||
metacharacters \
|
||||
word_splitting \
|
||||
|
||||
ifeq ($(CFLAGS),)
|
||||
CFLAGS = -Wall -Wextra -Werror -g
|
||||
|
|
|
|||
49
tests/word_splitting.c
Normal file
49
tests/word_splitting.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* word_splitting.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 15:17:56 by khais #+# #+# */
|
||||
/* Updated: 2025/02/13 17:24:33 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <assert.h>
|
||||
#include "testutil.h"
|
||||
#include "../src/parser/wordsplit/wordsplit.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
** https://bash-hackers.gabe565.com/syntax/words/
|
||||
*/
|
||||
void test_wordsplit_singleword(void)
|
||||
{
|
||||
t_wordlist *words;
|
||||
|
||||
words = minishell_wordsplit("echo");
|
||||
assert_strequal("echo", wordlist_get(words, 0)->word);
|
||||
assert(NULL == wordlist_get(words, 1));
|
||||
wordlist_destroy(words);
|
||||
}
|
||||
|
||||
void test_wordsplit_basic(void)
|
||||
{
|
||||
t_wordlist *words;
|
||||
|
||||
words = minishell_wordsplit("echo The file is named $MYFILE");
|
||||
assert_strequal("echo", wordlist_get(words, 0)->word);
|
||||
assert_strequal("The", wordlist_get(words, 1)->word);
|
||||
assert_strequal("file", wordlist_get(words, 2)->word);
|
||||
assert_strequal("is", wordlist_get(words, 3)->word);
|
||||
assert_strequal("named", wordlist_get(words, 4)->word);
|
||||
assert_strequal("$MYFILE", wordlist_get(words, 5)->word);
|
||||
assert(NULL == wordlist_get(words, 6));
|
||||
wordlist_destroy(words);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_wordsplit_singleword();
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue