| 15 | } |
| 16 | |
| 17 | int main(int argc, char **argv) |
| 18 | { |
| 19 | int c, error = 0, updates = 0; |
| 20 | |
| 21 | (void) argc; /* unused */ |
| 22 | (void) argv; /* unused */ |
| 23 | |
| 24 | /* some simple sanity tests of the character widths */ |
| 25 | for (c = 0; c <= 0x110000; ++c) { |
| 26 | int cat = utf8proc_get_property(c)->category; |
| 27 | int w = utf8proc_charwidth(c); |
| 28 | int ambiguous = utf8proc_charwidth_ambiguous(c); |
| 29 | if ((cat == UTF8PROC_CATEGORY_MN || cat == UTF8PROC_CATEGORY_ME) && w > 0) { |
| 30 | fprintf(stderr, "nonzero width %d for combining char %x\n", w, c); |
| 31 | error += 1; |
| 32 | } |
| 33 | if (w == 0 && |
| 34 | ((cat >= UTF8PROC_CATEGORY_LU && cat <= UTF8PROC_CATEGORY_LO) || |
| 35 | (cat >= UTF8PROC_CATEGORY_ND && cat <= UTF8PROC_CATEGORY_SC) || |
| 36 | (cat >= UTF8PROC_CATEGORY_SO && cat <= UTF8PROC_CATEGORY_ZS))) { |
| 37 | fprintf(stderr, "zero width for symbol-like char %x\n", c); |
| 38 | error += 1; |
| 39 | } |
| 40 | if (c <= 127 && ((!isprint(c) && w > 0) || (isprint(c) && wcwidth(c) != w))) { |
| 41 | fprintf(stderr, "wcwidth %d mismatch %d for %s ASCII %x\n", |
| 42 | wcwidth(c), w, |
| 43 | isprint(c) ? "printable" : "non-printable", c); |
| 44 | error += 1; |
| 45 | } |
| 46 | if (c <= 127 && utf8proc_charwidth_ambiguous(c)) { |
| 47 | fprintf(stderr, "ambiwith set for ASCII %x\n", c); |
| 48 | error += 1; |
| 49 | } |
| 50 | if (!my_isprint(c) && w > 0) { |
| 51 | fprintf(stderr, "non-printing %x had width %d\n", c, w); |
| 52 | error += 1; |
| 53 | } |
| 54 | if (my_unassigned(c) && w != 1) { |
| 55 | fprintf(stderr, "unexpected width %d for unassigned char %x\n", w, c); |
| 56 | error += 1; |
| 57 | } |
| 58 | if (ambiguous && w >= 2) { |
| 59 | fprintf(stderr, "char %x is both doublewidth and ambiguous\n", c); |
| 60 | error += 1; |
| 61 | } |
| 62 | } |
| 63 | check(!error, "utf8proc_charwidth FAILED %d tests.", error); |
| 64 | |
| 65 | check(utf8proc_charwidth(0x00ad) == 1, "incorrect width for U+00AD (soft hyphen)"); |
| 66 | check(utf8proc_charwidth_ambiguous(0x00ad) , "incorrect ambiguous width for U+00AD (soft hyphen)"); |
| 67 | check(utf8proc_charwidth(0xe000) == 1, "incorrect width for U+e000 (PUA)"); |
| 68 | check(utf8proc_charwidth_ambiguous(0xe000), "incorrect ambiguous width for U+e000 (PUA)"); |
| 69 | |
| 70 | check(utf8proc_charwidth_ambiguous(0x00A1), "incorrect ambiguous width for U+00A1 (inverted exclamation mark)"); |
| 71 | check(!utf8proc_charwidth_ambiguous(0x00A2), "incorrect ambiguous width for U+00A2 (cent sign)"); |
| 72 | |
| 73 | /* print some other information by compariing with system wcwidth */ |
| 74 | printf("Mismatches with system wcwidth (not necessarily errors):\n"); |
nothing calls this directly
no test coverage detected