-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_split_test.c
63 lines (58 loc) · 2.24 KB
/
ft_split_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenamar <abenamar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/05 15:14:49 by abenamar #+# #+# */
/* Updated: 2022/12/28 22:00:07 by abenamar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft_test.h"
static void free_split(char **split)
{
size_t i;
i = 0;
while (split[i])
{
free(split[i]);
++i;
}
free(split);
}
void ft_split_test(void)
{
char **strs;
printf(RESET "\nft_split\t");
strs = ft_split("", ' ');
ft_assert(1, strs[0] == NULL);
free_split(strs);
strs = ft_split("test", ' ');
ft_assert(2, !strcmp(strs[0], "test"));
free_split(strs);
strs = ft_split("te st", ' ');
ft_assert(3, (!strcmp(strs[0], "te") && !strcmp(strs[1], "st")));
free_split(strs);
strs = ft_split("t e s t", ' ');
ft_assert(4, (!strcmp(strs[0], "t") && !strcmp(strs[1], "e") && !strcmp(strs[2], "s") && !strcmp(strs[3], "t")));
free_split(strs);
strs = ft_split(" test", ' ');
ft_assert(5, !strcmp(strs[0], "test"));
free_split(strs);
strs = ft_split("test ", ' ');
ft_assert(6, !strcmp(strs[0], "test"));
free_split(strs);
strs = ft_split(" test ", ' ');
ft_assert(7, !strcmp(strs[0], "test"));
free_split(strs);
strs = ft_split(" test ", ' ');
ft_assert(8, !strcmp(strs[0], "test"));
free_split(strs);
strs = ft_split("te st", ' ');
ft_assert(9, (!strcmp(strs[0], "te") && !strcmp(strs[1], "st")));
free_split(strs);
strs = ft_split(" This is ... a test ", ' ');
ft_assert(10, (!strcmp(strs[0], "This") && !strcmp(strs[1], "is") && !strcmp(strs[2], "...") && !strcmp(strs[3], "a") && !strcmp(strs[4], "test")));
free_split(strs);
}