string: test strdup*, strspn*, strpbrk

This commit is contained in:
Lephenixnoir 2021-05-23 19:16:13 +02:00
parent 0048fb03ee
commit d7d1ea1a81
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include <ft/test.h>
#include <ft/all-tests.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@ -7,6 +8,7 @@ static void _ft_string_naive(ft_test *t)
{
char const *s1;
char s2[64];
char *s3;
s1 = "xyztuvxyztuv";
ft_assert(t, strchr(s1, 'z') == s1 + 2);
@ -48,6 +50,23 @@ static void _ft_string_naive(ft_test *t)
strncat(s2, s1 + 4, 4);
ft_assert(t, strcmp(s1, s2) != 0 && strncmp(s1, s2, 8) == 0);
ft_assert(t, strcmp(s2, "xyztuvxy") == 0);
s3 = strdup(s1);
ft_assert(t, strcmp(s1, s3) == 0);
free(s3);
s3 = strndup(s1, 5);
ft_assert(t, strcmp(s3, "xyztu") == 0);
free(s3);
ft_assert(t, strspn("abcbdbabed", "abcd") == 8);
ft_assert(t, strspn("abcbdbabed", "abcde") == 10);
ft_assert(t, strcspn("10234.283", "x.") == 5);
ft_assert(t, strcspn("10234.283", "x") == 9);
ft_assert(t, strpbrk(s1, "rstuv") == s1 + 3);
ft_assert(t, strpbrk(s1, "abc") == NULL);
ft_assert(t, strpbrk(s1, s1) == s1);
}
ft_test ft_string_naive = {