Compare commits
3 commits
fc301f82aa
...
34d94e3a4e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34d94e3a4e | ||
|
|
e3a7eeadbf | ||
|
|
8741131a28 |
3 changed files with 81 additions and 2 deletions
4
Makefile
4
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
|
|
|
|||
3
ft_substr_expected.output
Normal file
3
ft_substr_expected.output
Normal file
|
|
@ -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:[]
|
||||
76
ft_substr_test.c
Normal file
76
ft_substr_test.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr_test.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/10/08 18:44:25 by lalgarra #+# #+# */
|
||||
/* Updated: 2025/10/08 19:17:14 by lalgarra ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue