forked from JuliaStrings/utf8proc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add islower/isupper functions (JuliaStrings#196)
* add islower/isupper functions * added test * more tests + bugfix * Makefile fix * rm iscase test on make clean
- Loading branch information
Showing
9 changed files
with
7,527 additions
and
5,938 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
/test/valid | ||
/test/iterate | ||
/test/case | ||
/test/iscase | ||
/test/custom | ||
/tmp/ | ||
/mingw_static/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.