From 5f9dc111cf9d1441d7bbe4b8c4730b931a610b3b Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 12 Feb 2017 09:53:43 +0000 Subject: [PATCH] Add tests for the isdigit and isxdigit ctype APIs. --- tests/printcdata.c | 2 +- tests/printucddata.c | 2 +- tests/printucddata_cpp.cpp | 2 +- tools/printdata.py | 11 +++++++++-- tools/ucd.py | 6 ++++++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/printcdata.c b/tests/printcdata.c index 6f59f453..12b52570 100644 --- a/tests/printcdata.c +++ b/tests/printcdata.c @@ -248,7 +248,7 @@ int main(int argc, char **argv) else { for (codepoint_t c = 0; c <= 0x10FFFF; ++c) - uprintf(stdout, c, format ? format : "%pH %s %C %c %UH %LH %TH %is %iu %il\n"); + uprintf(stdout, c, format ? format : "%pH %s %C %c %UH %LH %TH %id %ix %is %iu %il\n"); } return 0; } diff --git a/tests/printucddata.c b/tests/printucddata.c index 136d88ee..7b24580a 100644 --- a/tests/printucddata.c +++ b/tests/printucddata.c @@ -243,7 +243,7 @@ int main(int argc, char **argv) else { for (codepoint_t c = 0; c <= 0x10FFFF; ++c) - uprintf(stdout, c, format ? format : "%pH %s %C %c %UH %LH %TH %is %iu %il\n"); + uprintf(stdout, c, format ? format : "%pH %s %C %c %UH %LH %TH %id %ix %is %iu %il\n"); } return 0; } diff --git a/tests/printucddata_cpp.cpp b/tests/printucddata_cpp.cpp index c19c4fbf..cfbb29be 100644 --- a/tests/printucddata_cpp.cpp +++ b/tests/printucddata_cpp.cpp @@ -243,7 +243,7 @@ int main(int argc, char **argv) else { for (ucd::codepoint_t c = 0; c <= 0x10FFFF; ++c) - uprintf(stdout, c, format ? format : "%pH %s %C %c %UH %LH %TH %is %iu %il\n"); + uprintf(stdout, c, format ? format : "%pH %s %C %c %UH %LH %TH %id %ix %is %iu %il\n"); } return 0; } diff --git a/tools/printdata.py b/tools/printdata.py index fd1eb236..46a2fc1f 100755 --- a/tools/printdata.py +++ b/tools/printdata.py @@ -43,6 +43,12 @@ if '--with-csur' in sys.argv: for codepoint in data['CodePoint']: unicode_chars[codepoint] = data +def isdigit(data): + return 1 if data['CodePoint'].char() in '0123456789' else 0 + +def isxdigit(data): + return 1 if data['CodePoint'].char() in '0123456789ABCDEFabcdef' else 0 + def isspace(data): return data.get('White_Space', 0) @@ -67,7 +73,7 @@ if __name__ == '__main__': try: data = unicode_chars[codepoint] except KeyError: - data = {} + data = {'CodePoint': codepoint} script = data.get('Script', 'Zzzz') title = data.get('TitleCase', codepoint) upper = data.get('UpperCase', codepoint) @@ -75,9 +81,10 @@ if __name__ == '__main__': if title == null: title = codepoint if upper == null: upper = codepoint if lower == null: lower = codepoint - print('%s %s %s %s %s %s %s %s %s %s' % ( + print('%s %s %s %s %s %s %s %s %s %s %s %s' % ( codepoint, script, data.get('GeneralCategory', 'Cn')[0], data.get('GeneralCategory', 'Cn'), upper, lower, title, + isdigit(data), isxdigit(data), isspace(data), isupper(data), islower(data))) diff --git a/tools/ucd.py b/tools/ucd.py index 2006efe7..4d9fe237 100755 --- a/tools/ucd.py +++ b/tools/ucd.py @@ -50,6 +50,9 @@ class CodePoint: def __lt__(self, other): return self.codepoint < other.codepoint + def char(self): + return unichr(self.codepoint) + class CodeRange: def __init__(self, x): f, l = x.split('..') @@ -69,6 +72,9 @@ class CodeRange: def size(self): return self.last.codepoint - self.first.codepoint + 1 + def char(self): + return unichr(self.first.codepoint) + def codepoint(x): if '..' in x[0]: return CodeRange(x[0]), x[1:]