FxLibcTest/src/ctype/classes.c

60 lines
1.8 KiB
C

#include <ft/test.h>
#include <ft/all-tests.h>
#include <ctype.h>
#include "charprops.h"
static void _ctype_classes(ft_test *t)
{
for(int c = 0; c < 128; c++) {
uint16_t props_f=0, props_m=0;
if(isalnum(c)) props_f |= CP_ALNUM;
if(isalpha(c)) props_f |= CP_ALPHA;
if(isblank(c)) props_f |= CP_BLANK;
if(iscntrl(c)) props_f |= CP_CNTRL;
if(isdigit(c)) props_f |= CP_DIGIT;
if(islower(c)) props_f |= CP_LOWER;
if(isgraph(c)) props_f |= CP_GRAPH;
if(ispunct(c)) props_f |= CP_PUNCT;
if(isprint(c)) props_f |= CP_PRINT;
if(isspace(c)) props_f |= CP_SPACE;
if(isupper(c)) props_f |= CP_UPPER;
if(isxdigit(c)) props_f |= CP_XDIGIT;
#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
if(isalnum(c)) props_m |= CP_ALNUM;
if(isalpha(c)) props_m |= CP_ALPHA;
if(isblank(c)) props_m |= CP_BLANK;
if(iscntrl(c)) props_m |= CP_CNTRL;
if(isdigit(c)) props_m |= CP_DIGIT;
if(islower(c)) props_m |= CP_LOWER;
if(isgraph(c)) props_m |= CP_GRAPH;
if(ispunct(c)) props_m |= CP_PUNCT;
if(isprint(c)) props_m |= CP_PRINT;
if(isspace(c)) props_m |= CP_SPACE;
if(isupper(c)) props_m |= CP_UPPER;
if(isxdigit(c)) props_m |= CP_XDIGIT;
ft_assert(t, props_f == charprops[c] && props_m == charprops[c]);
}
}
ft_test ft_ctype_classes = {
.name = "Character classification",
.function = _ctype_classes,
};