FxLibcTest/src/ctype/classes.c

67 lines
2.5 KiB
C

#include <ft/test.h>
#include <ft/all-tests.h>
#include <ctype.h>
#include "charprops.h"
static void _ctype_macros(ft_test *t)
{
for(int c = 0; c < 128; c++) {
ft_assert(t, (isalnum(c) != 0) == ((charprops[c] & CP_ALNUM) != 0));
ft_assert(t, (isalpha(c) != 0) == ((charprops[c] & CP_ALPHA) != 0));
ft_assert(t, (isblank(c) != 0) == ((charprops[c] & CP_BLANK) != 0));
ft_assert(t, (iscntrl(c) != 0) == ((charprops[c] & CP_CNTRL) != 0));
ft_assert(t, (isdigit(c) != 0) == ((charprops[c] & CP_DIGIT) != 0));
ft_assert(t, (islower(c) != 0) == ((charprops[c] & CP_LOWER) != 0));
ft_assert(t, (isgraph(c) != 0) == ((charprops[c] & CP_GRAPH) != 0));
ft_assert(t, (ispunct(c) != 0) == ((charprops[c] & CP_PUNCT) != 0));
ft_assert(t, (isprint(c) != 0) == ((charprops[c] & CP_PRINT) != 0));
ft_assert(t, (isspace(c) != 0) == ((charprops[c] & CP_SPACE) != 0));
ft_assert(t, (isupper(c) != 0) == ((charprops[c] & CP_UPPER) != 0));
ft_assert(t, (isxdigit(c) != 0) == ((charprops[c] & CP_XDIGIT) != 0));
}
}
ft_test ft_ctype_macros = {
.name = "Macro-based classification",
.function = _ctype_macros,
};
#undef isalnum
#undef isalpha
#undef isblank
#undef iscntrl
#undef isdigit
#undef islower
#undef isgraph
#undef ispunct
#undef isprint
#undef isspace
#undef isupper
#undef isxdigit
#undef tolower
#undef toupper
static void _ctype_functions(ft_test *t)
{
for(int c = 0; c < 128; c++) {
ft_assert(t, (isalnum(c) != 0) == ((charprops[c] & CP_ALNUM) != 0));
ft_assert(t, (isalpha(c) != 0) == ((charprops[c] & CP_ALPHA) != 0));
ft_assert(t, (isblank(c) != 0) == ((charprops[c] & CP_BLANK) != 0));
ft_assert(t, (iscntrl(c) != 0) == ((charprops[c] & CP_CNTRL) != 0));
ft_assert(t, (isdigit(c) != 0) == ((charprops[c] & CP_DIGIT) != 0));
ft_assert(t, (islower(c) != 0) == ((charprops[c] & CP_LOWER) != 0));
ft_assert(t, (isgraph(c) != 0) == ((charprops[c] & CP_GRAPH) != 0));
ft_assert(t, (ispunct(c) != 0) == ((charprops[c] & CP_PUNCT) != 0));
ft_assert(t, (isprint(c) != 0) == ((charprops[c] & CP_PRINT) != 0));
ft_assert(t, (isspace(c) != 0) == ((charprops[c] & CP_SPACE) != 0));
ft_assert(t, (isupper(c) != 0) == ((charprops[c] & CP_UPPER) != 0));
ft_assert(t, (isxdigit(c) != 0) == ((charprops[c] & CP_XDIGIT) != 0));
}
}
ft_test ft_ctype_functions = {
.name = "Function-based classification",
.function = _ctype_functions,
};