96 lines
3.4 KiB
C++
96 lines
3.4 KiB
C++
#include "xicu.hpp"
|
|
#include <cstdio>
|
|
#include <cstdint>
|
|
|
|
int main() {
|
|
printf("Testing x-icu binary tables...\n\n");
|
|
|
|
// Test alphanumeric
|
|
struct AlnumTest { uint32_t cp; bool expected; const char* desc; };
|
|
AlnumTest alnum_tests[] = {
|
|
{ 0x0041, true, "Latin capital A" },
|
|
{ 0x007A, true, "Latin small z" },
|
|
{ 0x0030, true, "Digit 0" },
|
|
{ 0x0039, true, "Digit 9" },
|
|
{ 0x00E9, true, "Latin small e with acute" },
|
|
{ 0x4E2D, true, "CJK ideograph" },
|
|
{ 0x03B1, true, "Greek alpha" },
|
|
{ 0x0040, false, "At sign" },
|
|
{ 0x0023, false, "Hash" },
|
|
{ 0x0020, false, "Space" },
|
|
{ 0x0009, false, "Tab" },
|
|
{ 0x1F600, false, "Emoji (grinning face)" },
|
|
{ 0x0627, true, "Arabic letter alef" },
|
|
{ 0x0915, true, "Devanagari letter ka" },
|
|
{ 0x3042, true, "Hiragana letter a" },
|
|
};
|
|
|
|
printf("=== Alphanumeric Tests ===\n");
|
|
int passed = 0, failed = 0;
|
|
for (const auto& t : alnum_tests) {
|
|
bool result = xicu::isAlphanumeric(t.cp);
|
|
if (result == t.expected) {
|
|
printf("PASS: U+%04X (%s) -> %s\n", t.cp, t.desc, result ? "true" : "false");
|
|
passed++;
|
|
} else {
|
|
printf("FAIL: U+%04X (%s) -> got %s, expected %s\n", t.cp, t.desc,
|
|
result ? "true" : "false", t.expected ? "true" : "false");
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
// Test whitespace
|
|
struct WsTest { uint32_t cp; bool expected; const char* desc; };
|
|
WsTest ws_tests[] = {
|
|
{ ' ', true, "Space" },
|
|
{ '\t', true, "Tab" },
|
|
{ '\n', true, "Line feed" },
|
|
{ '\r', true, "Carriage return" },
|
|
{ '\f', true, "Form feed" },
|
|
{ '\v', true, "Vertical tab" },
|
|
{ 0x1C, true, "File separator" },
|
|
{ 0x1D, true, "Group separator" },
|
|
{ 0x1E, true, "Record separator" },
|
|
{ 0x1F, true, "Unit separator" },
|
|
{ 0x85, true, "Next line (NEL)" },
|
|
{ 0xA0, true, "No-break space" },
|
|
{ 'A', false, "Letter A" },
|
|
{ '0', false, "Digit 0" },
|
|
{ '@', false, "At sign" },
|
|
{ 0x2000, true, "En quad" },
|
|
{ 0x2001, true, "Em quad" },
|
|
{ 0x2002, true, "En space" },
|
|
{ 0x2003, true, "Em space" },
|
|
{ 0x2004, true, "Three-per-em space" },
|
|
{ 0x2005, true, "Four-per-em space" },
|
|
{ 0x2006, true, "Six-per-em space" },
|
|
{ 0x2007, true, "Figure space" },
|
|
{ 0x2008, true, "Punctuation space" },
|
|
{ 0x2009, true, "Thin space" },
|
|
{ 0x200A, true, "Hair space" },
|
|
{ 0x2028, true, "Line separator" },
|
|
{ 0x2029, true, "Paragraph separator" },
|
|
{ 0x202F, true, "Narrow no-break space" },
|
|
{ 0x205F, true, "Medium mathematical space" },
|
|
{ 0x3000, true, "Ideographic space" },
|
|
};
|
|
|
|
printf("\n=== Whitespace Tests ===\n");
|
|
for (const auto& t : ws_tests) {
|
|
bool result = xicu::isWhitespace(t.cp);
|
|
if (result == t.expected) {
|
|
printf("PASS: U+%04X (%s) -> %s\n", t.cp, t.desc, result ? "true" : "false");
|
|
passed++;
|
|
} else {
|
|
printf("FAIL: U+%04X (%s) -> got %s, expected %s\n", t.cp, t.desc,
|
|
result ? "true" : "false", t.expected ? "true" : "false");
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
printf("\n=== Summary ===\n");
|
|
printf("Passed: %d\n", passed);
|
|
printf("Failed: %d\n", failed);
|
|
|
|
return failed == 0 ? 0 : 1;
|
|
} |