ctype: add a test for case conversion macros and functions
This commit is contained in:
parent
194a65c663
commit
ee0beb8028
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
|
@ -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 },
|
||||
|
|
Loading…
Reference in New Issue