Browse Source

Add tests for the isdigit and isxdigit ctype APIs.

master
Reece H. Dunn 8 years ago
parent
commit
5f9dc111cf
5 changed files with 18 additions and 5 deletions
  1. 1
    1
      tests/printcdata.c
  2. 1
    1
      tests/printucddata.c
  3. 1
    1
      tests/printucddata_cpp.cpp
  4. 9
    2
      tools/printdata.py
  5. 6
    0
      tools/ucd.py

+ 1
- 1
tests/printcdata.c View File

else else
{ {
for (codepoint_t c = 0; c <= 0x10FFFF; ++c) 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; return 0;
} }

+ 1
- 1
tests/printucddata.c View File

else else
{ {
for (codepoint_t c = 0; c <= 0x10FFFF; ++c) 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; return 0;
} }

+ 1
- 1
tests/printucddata_cpp.cpp View File

else else
{ {
for (ucd::codepoint_t c = 0; c <= 0x10FFFF; ++c) 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; return 0;
} }

+ 9
- 2
tools/printdata.py View File

for codepoint in data['CodePoint']: for codepoint in data['CodePoint']:
unicode_chars[codepoint] = data 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): def isspace(data):
return data.get('White_Space', 0) return data.get('White_Space', 0)


try: try:
data = unicode_chars[codepoint] data = unicode_chars[codepoint]
except KeyError: except KeyError:
data = {}
data = {'CodePoint': codepoint}
script = data.get('Script', 'Zzzz') script = data.get('Script', 'Zzzz')
title = data.get('TitleCase', codepoint) title = data.get('TitleCase', codepoint)
upper = data.get('UpperCase', codepoint) upper = data.get('UpperCase', codepoint)
if title == null: title = codepoint if title == null: title = codepoint
if upper == null: upper = codepoint if upper == null: upper = codepoint
if lower == null: lower = 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, codepoint, script,
data.get('GeneralCategory', 'Cn')[0], data.get('GeneralCategory', 'Cn'), data.get('GeneralCategory', 'Cn')[0], data.get('GeneralCategory', 'Cn'),
upper, lower, title, upper, lower, title,
isdigit(data), isxdigit(data),
isspace(data), isspace(data),
isupper(data), islower(data))) isupper(data), islower(data)))

+ 6
- 0
tools/ucd.py View File

def __lt__(self, other): def __lt__(self, other):
return self.codepoint < other.codepoint return self.codepoint < other.codepoint


def char(self):
return unichr(self.codepoint)

class CodeRange: class CodeRange:
def __init__(self, x): def __init__(self, x):
f, l = x.split('..') f, l = x.split('..')
def size(self): def size(self):
return self.last.codepoint - self.first.codepoint + 1 return self.last.codepoint - self.first.codepoint + 1


def char(self):
return unichr(self.first.codepoint)

def codepoint(x): def codepoint(x):
if '..' in x[0]: if '..' in x[0]:
return CodeRange(x[0]), x[1:] return CodeRange(x[0]), x[1:]

Loading…
Cancel
Save