t / helper / test-ctype.con commit Merge branch 'ab/gc-reflog' (f3c19f8)
   1#include "test-tool.h"
   2#include "cache.h"
   3
   4static int rc;
   5
   6static void report_error(const char *class, int ch)
   7{
   8        printf("%s classifies char %d (0x%02x) wrongly\n", class, ch, ch);
   9        rc = 1;
  10}
  11
  12static int is_in(const char *s, int ch)
  13{
  14        /* We can't find NUL using strchr.  It's classless anyway. */
  15        if (ch == '\0')
  16                return 0;
  17        return !!strchr(s, ch);
  18}
  19
  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        }                                       \
  26}
  27
  28#define DIGIT "0123456789"
  29#define LOWER "abcdefghijklmnopqrstuvwxyz"
  30#define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  31
  32int cmd__ctype(int argc, const char **argv)
  33{
  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, "!\"#%&',-/:;<=>@_`~");
  41
  42        return rc;
  43}