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); +}