4 static int test_isdigit(int c
)
9 static int test_isspace(int c
)
14 static int test_isalpha(int c
)
19 static int test_isalnum(int c
)
24 #define DIGIT "0123456789"
25 #define LOWER "abcdefghijklmnopqrstuvwxyz"
26 #define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
28 static const struct ctype_class
{
33 { "isdigit", test_isdigit
, DIGIT
},
34 { "isspace", test_isspace
, " \n\r\t" },
35 { "isalpha", test_isalpha
, LOWER UPPER
},
36 { "isalnum", test_isalnum
, LOWER UPPER DIGIT
},
40 static int test_class(const struct ctype_class
*test
)
44 for (i
= 0; i
< 256; i
++) {
45 int expected
= i
? !!strchr(test
->members
, i
) : 0;
46 int actual
= test
->test_fn(i
);
48 if (actual
!= expected
) {
50 printf("%s classifies char %d (0x%02x) wrongly\n",
57 int main(int argc
, char **argv
)
59 const struct ctype_class
*test
;
62 for (test
= classes
; test
->name
; test
++)
63 rc
|= test_class(test
);