add islower/isupper functions (#196)

* add islower/isupper functions

* added test

* more tests + bugfix

* Makefile fix

* rm iscase test on make clean
This commit is contained in:
Steven G. Johnson
2020-08-25 16:42:59 -04:00
committed by GitHub
parent 08f9999a06
commit 5622a0a51b
9 changed files with 7440 additions and 5851 deletions

62
test/iscase.c Normal file
View File

@@ -0,0 +1,62 @@
#include "tests.h"
int read_range(FILE *f, utf8proc_int32_t *start, utf8proc_int32_t *end)
{
unsigned char buf[8192];
size_t len = simple_getline(buf, f);
size_t pos = skipspaces(buf, 0);
unsigned char s[16];
if (pos == len || buf[pos] == '#') return 0;
pos += encode(s, buf + pos) - 1;
check(s[0], "invalid line %s in data", buf);
utf8proc_iterate((utf8proc_uint8_t*) s, -1, start);
if (buf[pos] == '.' && buf[pos+1] == '.') {
encode(s, buf + pos + 2);
check(s[0], "invalid line %s in data", buf);
utf8proc_iterate((utf8proc_uint8_t*) s, -1, end);
}
else
*end = *start;
return 1;
}
int test_iscase(const char *fname, int (*iscase)(utf8proc_int32_t),
utf8proc_int32_t (*thatcase)(utf8proc_int32_t))
{
FILE *f = fopen(fname, "r");
int lines = 0, tests = 0, success = 1;
utf8proc_int32_t c = 0;
check(f != NULL, "error opening data file \"%s\"\n", fname);
while (success && !feof(f)) {
utf8proc_int32_t start, end;
if (read_range(f, &start, &end)) {
for (; c < start; ++c) {
check(!iscase(c), "failed !iscase(%04x) in %s\n", c, fname);
}
for (; c <= end; ++c) {
check(iscase(c), "failed iscase(%04x) in %s\n", c, fname);
check(thatcase(c) == c, "inconsistent thatcase(%04x) in %s\n", c, fname);
++tests;
}
}
++lines;
}
for (; c <= 0x110000; ++c) {
check(!iscase(c), "failed !iscase(%04x) in %s\n", c, fname);
}
printf("Checked %d characters from %d lines of %s\n", tests, lines, fname);
fclose(f);
return success;
}
int main(int argc, char **argv)
{
check(argc == 3, "Expected Lowercase.txt and Uppercase.txt as arguments");
check(test_iscase(argv[1], utf8proc_islower, utf8proc_tolower), "Lowercase tests failed");
check(test_iscase(argv[2], utf8proc_isupper, utf8proc_toupper), "Uppercase tests failed");
printf("utf8proc iscase tests SUCCEEDED.\n");
return 0;
}

View File

@@ -27,9 +27,9 @@ int main(int argc, char **argv)
" combining_class = %d\n"
" bidi_class = %d\n"
" decomp_type = %d\n"
" uppercase_mapping = %x\n"
" lowercase_mapping = %x\n"
" titlecase_mapping = %x\n"
" uppercase_mapping = %04x (seqindex %04x)%s\n"
" lowercase_mapping = %04x (seqindex %04x)%s\n"
" titlecase_mapping = %04x (seqindex %04x)\n"
" casefold = %s\n"
" comb_index = %d\n"
" bidi_mirrored = %d\n"
@@ -43,9 +43,9 @@ int main(int argc, char **argv)
p->combining_class,
p->bidi_class,
p->decomp_type,
utf8proc_toupper(c),
utf8proc_tolower(c),
utf8proc_totitle(c),
utf8proc_toupper(c), p->uppercase_seqindex, utf8proc_isupper(c) ? " (isupper)" : "",
utf8proc_tolower(c), p->lowercase_seqindex, utf8proc_islower(c) ? " (islower)" : "",
utf8proc_totitle(c), p->titlecase_seqindex,
(char *) map,
p->comb_index,
p->bidi_mirrored,