diff --git a/Makefile b/Makefile index 19d7f0e..701c1fe 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: lalgarra +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/10/03 18:03:12 by lalgarra #+# #+# # -# Updated: 2025/10/07 18:46:48 by lalgarra ### ########.fr # +# Updated: 2025/10/08 19:27:12 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_atoi_test ft_substr_test %_test : %_test.c $(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test diff --git a/ft_substr_expected.output b/ft_substr_expected.output new file mode 100644 index 0000000..9ad851f --- /dev/null +++ b/ft_substr_expected.output @@ -0,0 +1,3 @@ +test 1: buff:[Lorem ipsum], start:[0], len:[10], result:[Lorem ipsu] +test 2: buff:[Lorem ipsum], start:[7], len:[10], result:[psum] +test 3: buff:[Lorem ipsum], start:[12], len:[10], result:[] diff --git a/ft_substr_test.c b/ft_substr_test.c new file mode 100644 index 0000000..2e513dc --- /dev/null +++ b/ft_substr_test.c @@ -0,0 +1,76 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr_test.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lalgarra +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/10/08 18:44:25 by lalgarra #+# #+# */ +/* Updated: 2025/10/08 19:17:14 by lalgarra ### ########.fr */ +/* */ +/* ************************************************************************** */ + + +#include "libft.h" +#include +#include + +static void test(char *prefix, char buff[], unsigned int start, size_t len) +{ + char *res; + int fd; + + fd = STDOUT_FILENO; + ft_putstr_fd(prefix, fd); + ft_putstr_fd("buff:[", fd); + ft_putstr_fd(buff, fd); + ft_putstr_fd("], start:[", fd); + ft_putnbr_fd(start, fd); + ft_putstr_fd("], len:[", fd); + ft_putnbr_fd(len, fd); + res = ft_substr(buff, start, len); + 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", 0, 10); +} + +static void do_test2(void) +{ + test("test 2: ", "Lorem ipsum", 7, 10); +} + +static void do_test3(void) +{ + test("test 3: ", "Lorem ipsum", 12, 10); +} + +/* +static void zero(char buff[]) +{ + ft_bzero(buff, 128); +} + +static void do_test2(char buff[]) +{ + zero(buff); + ft_strlcpy(buff, "+-50", 5); +} +*/ +int main(void) +{ + //char buff[128]; + + do_test1(); + do_test2(); + do_test3(); + return (0); +}