diff --git a/ft_strjoin_expected.output b/ft_strjoin_expected.output new file mode 100644 index 0000000..a83e0bb --- /dev/null +++ b/ft_strjoin_expected.output @@ -0,0 +1,4 @@ +test 1: str1:[Lorem], str2:[ ipsum], result:[Lorem ipsum] +test 2: str1:[], str2:[ ipsum], result:[ ipsum] +test 3: str1:[Lorem], str2:[], result:[Lorem] +test 4: str1:[Lorem], str2:[-NULL-], result:[Lorem] diff --git a/ft_strjoin_test.c b/ft_strjoin_test.c index 50f83cf..aa641c6 100644 --- a/ft_strjoin_test.c +++ b/ft_strjoin_test.c @@ -6,7 +6,7 @@ /* By: lalgarra +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/10/08 20:21:32 by lalgarra #+# #+# */ -/* Updated: 2025/10/08 20:25:32 by lalgarra ### ########.fr */ +/* Updated: 2025/10/08 20:41:28 by lalgarra ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,14 @@ #include #include +static void ft_putstr_fd1(char *res, int fd) +{ + if (res == NULL) + ft_putstr_fd("-NULL-", fd); + else + ft_putstr_fd(res, fd); +} + static void test(char *prefix, char *str1, char *str2) { char *res; @@ -24,15 +32,12 @@ static void test(char *prefix, char *str1, char *str2) fd = STDOUT_FILENO; ft_putstr_fd(prefix, fd); ft_putstr_fd("str1:[", fd); - ft_putstr_fd(str1, fd); - ft_putstr_fd("str2:[", fd); - ft_putstr_fd(str2, fd); + ft_putstr_fd1(str1, fd); + ft_putstr_fd("], str2:[", fd); + ft_putstr_fd1(str2, fd); res = ft_strjoin(str1, str2); ft_putstr_fd("], result:[", fd); - if (res == NULL) - ft_putstr_fd("-NULL-", fd); - else - ft_putstr_fd(res, fd); + ft_putstr_fd1(res, fd); free(res); ft_putendl_fd("]", fd); }