From 998010436ee77e8fa64a8065e15691dd731ace8c Mon Sep 17 00:00:00 2001 From: lalgarra Date: Wed, 8 Oct 2025 21:33:44 +0200 Subject: [PATCH 1/2] Working on ft_strtrim() --- Makefile | 4 ++-- ft_strjoin_test.c | 6 ++---- ft_strnstr_test.c | 5 ++--- ft_strtrim_test.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 ft_strtrim_test.c diff --git a/Makefile b/Makefile index 43b37e3..c6bc71a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: lalgarra +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/10/03 18:03:12 by lalgarra #+# #+# # -# Updated: 2025/10/08 20:35:23 by lalgarra ### ########.fr # +# Updated: 2025/10/08 20:53:52 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_strjoin_test + ft_atoi_test ft_substr_test ft_strjoin_test ft_strtrim_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 index aa641c6..426a62d 100644 --- a/ft_strjoin_test.c +++ b/ft_strjoin_test.c @@ -6,17 +6,15 @@ /* By: lalgarra +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/10/08 20:21:32 by lalgarra #+# #+# */ -/* Updated: 2025/10/08 20:41:28 by lalgarra ### ########.fr */ +/* Updated: 2025/10/08 20:54:31 by lalgarra ### ########.fr */ /* */ /* ************************************************************************** */ - - #include "libft.h" #include #include -static void ft_putstr_fd1(char *res, int fd) +static void ft_putstr_fd1(char *res, int fd) { if (res == NULL) ft_putstr_fd("-NULL-", fd); diff --git a/ft_strnstr_test.c b/ft_strnstr_test.c index b1f9184..df6e60f 100644 --- a/ft_strnstr_test.c +++ b/ft_strnstr_test.c @@ -6,11 +6,10 @@ /* By: lalgarra +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/10/06 20:46:15 by lalgarra #+# #+# */ -/* Updated: 2025/10/07 18:00:51 by lalgarra ### ########.fr */ +/* Updated: 2025/10/08 20:55:13 by lalgarra ### ########.fr */ /* */ /* ************************************************************************** */ - #include "libft.h" #include #include @@ -103,7 +102,7 @@ static void do_test6(char *prefix, char big[], char littl[]) zero(big, littl); size = 20; memcpy(littl, "e\x00g", 3); - memcpy(big, "is there\x00 a nyacat ?",20); + memcpy(big, "is there\x00 a nyacat ?", 20); test(prefix, big, littl, size); } diff --git a/ft_strtrim_test.c b/ft_strtrim_test.c new file mode 100644 index 0000000..6186dd7 --- /dev/null +++ b/ft_strtrim_test.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim_test.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lalgarra +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/10/08 20:50:12 by lalgarra #+# #+# */ +/* Updated: 2025/10/08 21:32:34 by lalgarra ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#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 *set) +{ + char *res; + int fd; + + fd = STDOUT_FILENO; + ft_putstr_fd(prefix, fd); + ft_putstr_fd("str1:[", fd); + ft_putstr_fd1(str1, fd); + res = ft_strtrim(str1, set); + ft_putstr_fd("], result:[", fd); + ft_putstr_fd1(res, fd); + free(res); + ft_putendl_fd("]", fd); +} + +int main(void) +{ + test("test 1: ", "Lorem", " "); + test("test 2: ", " Lorem ", " "); + test("test 3: ", " Lorem ", " Lm"); + test("test 4: ", " ", " "); + test("test 5: ", (void *)0, " "); + test("test 1: ", "Lorem", (void *)0); + return (0); +} From 337475e0227ad2be39d00877fe04da374fdf07d5 Mon Sep 17 00:00:00 2001 From: lalgarra Date: Wed, 8 Oct 2025 22:00:12 +0200 Subject: [PATCH 2/2] ft_strtrim() --- ft_strtrim_expected.output | 6 ++++++ ft_strtrim_test.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 ft_strtrim_expected.output diff --git a/ft_strtrim_expected.output b/ft_strtrim_expected.output new file mode 100644 index 0000000..09f1a1f --- /dev/null +++ b/ft_strtrim_expected.output @@ -0,0 +1,6 @@ +test 1: str1:[Lorem], result:[Lorem] +test 2: str1:[ Lorem ], result:[Lorem] +test 3: str1:[ Lorem ], result:[ore] +test 4: str1:[ ], result:[] +test 5: str1:[-NULL-], result:[] +test 6: str1:[Lorem], result:[Lorem] diff --git a/ft_strtrim_test.c b/ft_strtrim_test.c index 6186dd7..df42a61 100644 --- a/ft_strtrim_test.c +++ b/ft_strtrim_test.c @@ -6,7 +6,7 @@ /* By: lalgarra +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/10/08 20:50:12 by lalgarra #+# #+# */ -/* Updated: 2025/10/08 21:32:34 by lalgarra ### ########.fr */ +/* Updated: 2025/10/08 21:53:15 by lalgarra ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,6 @@ int main(void) test("test 3: ", " Lorem ", " Lm"); test("test 4: ", " ", " "); test("test 5: ", (void *)0, " "); - test("test 1: ", "Lorem", (void *)0); + test("test 6: ", "Lorem", (void *)0); return (0); }