Sync with 2.18.1
[git.git] / t / helper / test-ctype.c
blob92c4c2313e78a305dd0da1e7a853e58e325d2f84
1 #include "test-tool.h"
2 #include "cache.h"
4 static int rc;
6 static void report_error(const char *class, int ch)
8 printf("%s classifies char %d (0x%02x) wrongly\n", class, ch, ch);
9 rc = 1;
12 static int is_in(const char *s, int ch)
14 /* We can't find NUL using strchr. It's classless anyway. */
15 if (ch == '\0')
16 return 0;
17 return !!strchr(s, ch);
20 #define TEST_CLASS(t,s) { \
21 int i; \
22 for (i = 0; i < 256; i++) { \
23 if (is_in(s, i) != t(i)) \
24 report_error(#t, i); \
25 } \
28 #define DIGIT "0123456789"
29 #define LOWER "abcdefghijklmnopqrstuvwxyz"
30 #define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
32 int cmd__ctype(int argc, const char **argv)
34 TEST_CLASS(isdigit, DIGIT);
35 TEST_CLASS(isspace, " \n\r\t");
36 TEST_CLASS(isalpha, LOWER UPPER);
37 TEST_CLASS(isalnum, LOWER UPPER DIGIT);
38 TEST_CLASS(is_glob_special, "*?[\\");
39 TEST_CLASS(is_regex_special, "$()*+.?[\\^{|");
40 TEST_CLASS(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~");
42 return rc;