test-ctype.con commit Merge branch 'js/xmerge-marker-eol' (81ad6a9)
   1#include "cache.h"
   2
   3static int rc;
   4
   5static void report_error(const char *class, int ch)
   6{
   7        printf("%s classifies char %d (0x%02x) wrongly\n", class, ch, ch);
   8        rc = 1;
   9}
  10
  11static int is_in(const char *s, int ch)
  12{
  13        /* We can't find NUL using strchr.  It's classless anyway. */
  14        if (ch == '\0')
  15                return 0;
  16        return !!strchr(s, ch);
  17}
  18
  19#define TEST_CLASS(t,s) {                       \
  20        int i;                                  \
  21        for (i = 0; i < 256; i++) {             \
  22                if (is_in(s, i) != t(i))        \
  23                        report_error(#t, i);    \
  24        }                                       \
  25}
  26
  27#define DIGIT "0123456789"
  28#define LOWER "abcdefghijklmnopqrstuvwxyz"
  29#define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  30
  31int main(int argc, char **argv)
  32{
  33        TEST_CLASS(isdigit, DIGIT);
  34        TEST_CLASS(isspace, " \n\r\t");
  35        TEST_CLASS(isalpha, LOWER UPPER);
  36        TEST_CLASS(isalnum, LOWER UPPER DIGIT);
  37        TEST_CLASS(is_glob_special, "*?[\\");
  38        TEST_CLASS(is_regex_special, "$()*+.?[\\^{|");
  39        TEST_CLASS(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~");
  40
  41        return rc;
  42}