From 50e166dad53ebd0c5524629700d5cb9f6b1ee08f Mon Sep 17 00:00:00 2001 From: lalgarra Date: Wed, 8 Oct 2025 20:36:13 +0200 Subject: [PATCH 1/2] Working on ft_strjoin() --- Makefile | 4 +-- ft_strjoin_test.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 ft_strjoin_test.c diff --git a/Makefile b/Makefile index 701c1fe..43b37e3 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: lalgarra +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/10/03 18:03:12 by lalgarra #+# #+# # -# Updated: 2025/10/08 19:27:12 by lalgarra ### ########.fr # +# Updated: 2025/10/08 20:35:23 by lalgarra ### ########.fr # # # # **************************************************************************** # @@ -22,7 +22,7 @@ TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \ ft_memset_test ft_bzero_test ft_memcpy_test ft_calloc_test \ ft_memmove_test ft_strlcpy_test ft_strlcat_test ft_strchr_test \ ft_strrchr_test ft_strncmp_test ft_memcmp_test ft_strnstr_test \ - ft_atoi_test ft_substr_test + ft_atoi_test ft_substr_test ft_strjoin_test %_test : %_test.c $(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test diff --git a/ft_strjoin_test.c b/ft_strjoin_test.c new file mode 100644 index 0000000..50f83cf --- /dev/null +++ b/ft_strjoin_test.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin_test.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lalgarra +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/10/08 20:21:32 by lalgarra #+# #+# */ +/* Updated: 2025/10/08 20:25:32 by lalgarra ### ########.fr */ +/* */ +/* ************************************************************************** */ + + + +#include "libft.h" +#include +#include + +static void test(char *prefix, char *str1, char *str2) +{ + char *res; + int fd; + + 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); + res = ft_strjoin(str1, str2); + ft_putstr_fd("], result:[", fd); + if (res == NULL) + ft_putstr_fd("-NULL-", fd); + else + ft_putstr_fd(res, fd); + free(res); + ft_putendl_fd("]", fd); +} + +static void do_test1(void) +{ + test("test 1: ", "Lorem", " ipsum"); +} + +static void do_test2(void) +{ + test("test 2: ", "", " ipsum"); +} + +static void do_test3(void) +{ + test("test 3: ", "Lorem", ""); +} + +static void do_test4(void) +{ + test("test 4: ", "Lorem", (char *)0); +} + +int main(void) +{ + do_test1(); + do_test2(); + do_test3(); + do_test4(); + return (0); +} From 59cb1ccc1cd314eba9349b49004b014e8c604d0d Mon Sep 17 00:00:00 2001 From: lalgarra Date: Wed, 8 Oct 2025 20:48:25 +0200 Subject: [PATCH 2/2] ft_strjoin() --- ft_strjoin_expected.output | 4 ++++ ft_strjoin_test.c | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 ft_strjoin_expected.output 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); }