|
1 |
| -#include "test-lib.h" |
| 1 | +#include "unit-test.h" |
2 | 2 |
|
3 | 3 | #define TEST_CHAR_CLASS(class, string) do { \
|
4 | 4 | size_t len = ARRAY_SIZE(string) - 1 + \
|
5 | 5 | BUILD_ASSERT_OR_ZERO(ARRAY_SIZE(string) > 0) + \
|
6 | 6 | BUILD_ASSERT_OR_ZERO(sizeof(string[0]) == sizeof(char)); \
|
7 |
| - if_test (#class " works") { \ |
8 |
| - for (int i = 0; i < 256; i++) { \ |
9 |
| - if (!check_int(class(i), ==, !!memchr(string, i, len)))\ |
10 |
| - test_msg(" i: 0x%02x", i); \ |
11 |
| - } \ |
12 |
| - check(!class(EOF)); \ |
| 7 | + for (int i = 0; i < 256; i++) { \ |
| 8 | + int actual = class(i), expect = !!memchr(string, i, len); \ |
| 9 | + if (actual != expect) \ |
| 10 | + cl_failf("0x%02x is classified incorrectly: expected %d, got %d", \ |
| 11 | + i, expect, actual); \ |
13 | 12 | } \
|
| 13 | + cl_assert(!class(EOF)); \ |
14 | 14 | } while (0)
|
15 | 15 |
|
16 | 16 | #define DIGIT "0123456789"
|
|
31 | 31 | "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
|
32 | 32 | "\x7f"
|
33 | 33 |
|
34 |
| -int cmd_main(int argc, const char **argv) { |
| 34 | +void test_ctype__isspace(void) |
| 35 | +{ |
35 | 36 | TEST_CHAR_CLASS(isspace, " \n\r\t");
|
| 37 | +} |
| 38 | + |
| 39 | +void test_ctype__isdigit(void) |
| 40 | +{ |
36 | 41 | TEST_CHAR_CLASS(isdigit, DIGIT);
|
| 42 | +} |
| 43 | + |
| 44 | +void test_ctype__isalpha(void) |
| 45 | +{ |
37 | 46 | TEST_CHAR_CLASS(isalpha, LOWER UPPER);
|
| 47 | +} |
| 48 | + |
| 49 | +void test_ctype__isalnum(void) |
| 50 | +{ |
38 | 51 | TEST_CHAR_CLASS(isalnum, LOWER UPPER DIGIT);
|
| 52 | +} |
| 53 | + |
| 54 | +void test_ctype__is_glob_special(void) |
| 55 | +{ |
39 | 56 | TEST_CHAR_CLASS(is_glob_special, "*?[\\");
|
| 57 | +} |
| 58 | + |
| 59 | +void test_ctype__is_regex_special(void) |
| 60 | +{ |
40 | 61 | TEST_CHAR_CLASS(is_regex_special, "$()*+.?[\\^{|");
|
| 62 | +} |
| 63 | + |
| 64 | +void test_ctype__is_pathspec_magic(void) |
| 65 | +{ |
41 | 66 | TEST_CHAR_CLASS(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~");
|
| 67 | +} |
| 68 | + |
| 69 | +void test_ctype__isascii(void) |
| 70 | +{ |
42 | 71 | TEST_CHAR_CLASS(isascii, ASCII);
|
| 72 | +} |
| 73 | + |
| 74 | +void test_ctype__islower(void) |
| 75 | +{ |
43 | 76 | TEST_CHAR_CLASS(islower, LOWER);
|
| 77 | +} |
| 78 | + |
| 79 | +void test_ctype__isupper(void) |
| 80 | +{ |
44 | 81 | TEST_CHAR_CLASS(isupper, UPPER);
|
| 82 | +} |
| 83 | + |
| 84 | +void test_ctype__iscntrl(void) |
| 85 | +{ |
45 | 86 | TEST_CHAR_CLASS(iscntrl, CNTRL);
|
| 87 | +} |
| 88 | + |
| 89 | +void test_ctype__ispunct(void) |
| 90 | +{ |
46 | 91 | TEST_CHAR_CLASS(ispunct, PUNCT);
|
| 92 | +} |
| 93 | + |
| 94 | +void test_ctype__isxdigit(void) |
| 95 | +{ |
47 | 96 | TEST_CHAR_CLASS(isxdigit, DIGIT "abcdefABCDEF");
|
48 |
| - TEST_CHAR_CLASS(isprint, LOWER UPPER DIGIT PUNCT " "); |
| 97 | +} |
49 | 98 |
|
50 |
| - return test_done(); |
| 99 | +void test_ctype__isprint(void) |
| 100 | +{ |
| 101 | + TEST_CHAR_CLASS(isprint, LOWER UPPER DIGIT PUNCT " "); |
51 | 102 | }
|
0 commit comments