ctype: add a test for case conversion macros and functions

This commit is contained in:
Lephenixnoir 2021-05-18 11:54:41 +02:00
parent 194a65c663
commit ee0beb8028
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 45 additions and 2 deletions

View File

@ -23,6 +23,7 @@ set(SOURCES
# ctype
src/ctype/charprops.c
src/ctype/classes.c
src/ctype/convert.c
# string
src/string/memarray.c
src/string/core.c

View File

@ -10,6 +10,8 @@
/* ctype */
extern ft_test ft_ctype_macros;
extern ft_test ft_ctype_functions;
extern ft_test ft_ctype_convert_macros;
extern ft_test ft_ctype_convert_functions;
/* string */
extern ft_test ft_string_memset;

View File

@ -23,7 +23,7 @@ static void _ctype_macros(ft_test *t)
}
ft_test ft_ctype_macros = {
.name = "Macro versions of functions",
.name = "Macro-based classification",
.function = _ctype_macros,
};
@ -61,6 +61,6 @@ static void _ctype_functions(ft_test *t)
}
ft_test ft_ctype_functions = {
.name = "Pure functions",
.name = "Function-based classification",
.function = _ctype_functions,
};

38
src/ctype/convert.c Normal file
View File

@ -0,0 +1,38 @@
#include <ft/test.h>
#include <ft/all-tests.h>
#include <ctype.h>
static void _ctype_convert_macros(ft_test *t)
{
for(int c = 0; c < 128; c++) {
int cl = (isupper(c) ? c - 'A' + 'a' : c);
int cu = (islower(c) ? c - 'a' + 'A' : c);
ft_assert(t, tolower(c) == cl);
ft_assert(t, toupper(c) == cu);
}
}
ft_test ft_ctype_convert_macros = {
.name = "Macro-based conversion",
.function = _ctype_convert_macros,
};
#undef tolower
#undef toupper
static void _ctype_convert_functions(ft_test *t)
{
for(int c = 0; c < 128; c++) {
int cl = (isupper(c) ? c - 'A' + 'a' : c);
int cu = (islower(c) ? c - 'a' + 'A' : c);
ft_assert(t, tolower(c) == cl);
ft_assert(t, toupper(c) == cu);
}
}
ft_test ft_ctype_convert_functions = {
.name = "Function-based conversion",
.function = _ctype_convert_functions,
};

View File

@ -16,6 +16,8 @@ ft_list headers_libc[] = {
{ "<ctype.h>", (ft_test*[]){
&ft_ctype_macros,
&ft_ctype_functions,
&ft_ctype_convert_macros,
&ft_ctype_convert_functions,
NULL,
}},
{ "<locale.h>", NULL },