t-ctype: avoid duplicating class names
[git.git] / t / unit-tests / t-ctype.c
blobd6ac1fe678dc73c6e126c6d1357c21d0af267a56
1 #include "test-lib.h"
3 #define TEST_CHAR_CLASS(class, string) do { \
4 size_t len = ARRAY_SIZE(string) - 1 + \
5 BUILD_ASSERT_OR_ZERO(ARRAY_SIZE(string) > 0) + \
6 BUILD_ASSERT_OR_ZERO(sizeof(string[0]) == sizeof(char)); \
7 int skip = test__run_begin(); \
8 if (!skip) { \
9 for (int i = 0; i < 256; i++) { \
10 if (!check_int(class(i), ==, !!memchr(string, i, len)))\
11 test_msg(" i: 0x%02x", i); \
12 } \
13 check(!class(EOF)); \
14 } \
15 test__run_end(!skip, TEST_LOCATION(), #class " works"); \
16 } while (0)
18 #define DIGIT "0123456789"
19 #define LOWER "abcdefghijklmnopqrstuvwxyz"
20 #define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
21 #define PUNCT "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
22 #define ASCII \
23 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
24 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
25 "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" \
26 "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f" \
27 "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" \
28 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f" \
29 "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" \
30 "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"
31 #define CNTRL \
32 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
33 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
34 "\x7f"
36 int cmd_main(int argc, const char **argv) {
37 TEST_CHAR_CLASS(isspace, " \n\r\t");
38 TEST_CHAR_CLASS(isdigit, DIGIT);
39 TEST_CHAR_CLASS(isalpha, LOWER UPPER);
40 TEST_CHAR_CLASS(isalnum, LOWER UPPER DIGIT);
41 TEST_CHAR_CLASS(is_glob_special, "*?[\\");
42 TEST_CHAR_CLASS(is_regex_special, "$()*+.?[\\^{|");
43 TEST_CHAR_CLASS(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~");
44 TEST_CHAR_CLASS(isascii, ASCII);
45 TEST_CHAR_CLASS(islower, LOWER);
46 TEST_CHAR_CLASS(isupper, UPPER);
47 TEST_CHAR_CLASS(iscntrl, CNTRL);
48 TEST_CHAR_CLASS(ispunct, PUNCT);
49 TEST_CHAR_CLASS(isxdigit, DIGIT "abcdefABCDEF");
50 TEST_CHAR_CLASS(isprint, LOWER UPPER DIGIT PUNCT " ");
52 return test_done();