lots of improvements standby for the results
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
#include "xicu.hpp"
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
int main() {
|
||||
printf("Testing x-icu configurable generator...\n\n");
|
||||
|
||||
// Test isLetter (bitmap)
|
||||
struct { uint32_t cp; bool expected; const char* desc; } letter_tests[] = {
|
||||
{ 'A', true, "Latin capital A" },
|
||||
{ 'z', true, "Latin small z" },
|
||||
{ '0', false, "Digit 0" },
|
||||
{ '@', false, "At sign" },
|
||||
{ ' ', false, "Space" },
|
||||
{ 0x00E9, true, "e acute" },
|
||||
{ 0x4E2D, true, "CJK ideograph" },
|
||||
{ 0x03B1, true, "Greek alpha" },
|
||||
{ 0x0627, true, "Arabic alef" },
|
||||
{ 0x1F600, false, "Emoji" },
|
||||
};
|
||||
|
||||
printf("=== isLetter (bitmap) ===\n");
|
||||
int passed = 0, failed = 0;
|
||||
for (auto& t : letter_tests) {
|
||||
bool r = xicu::isLetter(t.cp);
|
||||
if (r == t.expected) { printf("PASS: U+%04X %s\n", t.cp, t.desc); passed++; }
|
||||
else { printf("FAIL: U+%04X %s got %d exp %d\n", t.cp, t.desc, r, t.expected); failed++; }
|
||||
}
|
||||
|
||||
// Test isPunctuation (sparse_map)
|
||||
struct { uint32_t cp; bool expected; const char* desc; } punct_tests[] = {
|
||||
{ '.', true, "Period" },
|
||||
{ ',', true, "Comma" },
|
||||
{ '!', true, "Exclamation" },
|
||||
{ '?', true, "Question" },
|
||||
{ 'A', false, "Letter A" },
|
||||
{ '0', false, "Digit 0" },
|
||||
{ ' ', false, "Space" },
|
||||
{ 0x2026, true, "Ellipsis" },
|
||||
{ 0x2018, true, "Left single quote" },
|
||||
{ 0x201C, true, "Left double quote" },
|
||||
};
|
||||
|
||||
printf("\n=== isPunctuation (sparse_map) ===\n");
|
||||
for (auto& t : punct_tests) {
|
||||
bool r = xicu::isPunctuation(t.cp);
|
||||
if (r == t.expected) { printf("PASS: U+%04X %s\n", t.cp, t.desc); passed++; }
|
||||
else { printf("FAIL: U+%04X %s got %d exp %d\n", t.cp, t.desc, r, t.expected); failed++; }
|
||||
}
|
||||
|
||||
// Test isWhitespace (sparse_map)
|
||||
struct { uint32_t cp; bool expected; const char* desc; } ws_tests[] = {
|
||||
{ ' ', true, "Space" },
|
||||
{ '\t', true, "Tab" },
|
||||
{ '\n', true, "LF" },
|
||||
{ '\r', true, "CR" },
|
||||
{ 0x00A0, true, "NBSP" },
|
||||
{ 0x2000, true, "En quad" },
|
||||
{ 0x2003, true, "Em space" },
|
||||
{ 0x2028, true, "Line separator" },
|
||||
{ 0x2029, true, "Paragraph separator" },
|
||||
{ 0x3000, true, "Ideographic space" },
|
||||
{ 'A', false, "Letter A" },
|
||||
{ '0', false, "Digit 0" },
|
||||
};
|
||||
|
||||
printf("\n=== isWhitespace (sparse_map) ===\n");
|
||||
for (auto& t : ws_tests) {
|
||||
bool r = xicu::isWhitespace(t.cp);
|
||||
if (r == t.expected) { printf("PASS: U+%04X %s\n", t.cp, t.desc); passed++; }
|
||||
else { printf("FAIL: U+%04X %s got %d exp %d\n", t.cp, t.desc, r, t.expected); failed++; }
|
||||
}
|
||||
|
||||
// Test isSpace (sparse_map) - only Zs
|
||||
struct { uint32_t cp; bool expected; const char* desc; } space_tests[] = {
|
||||
{ ' ', true, "Space" },
|
||||
{ 0x00A0, true, "NBSP" },
|
||||
{ 0x2000, true, "En quad" },
|
||||
{ 0x2003, true, "Em space" },
|
||||
{ 0x3000, true, "Ideographic space" },
|
||||
{ '\t', false, "Tab (not Zs)" },
|
||||
{ '\n', false, "LF (not Zs)" },
|
||||
{ 'A', false, "Letter A" },
|
||||
};
|
||||
|
||||
printf("\n=== isSpace (sparse_map) ===\n");
|
||||
for (auto& t : space_tests) {
|
||||
bool r = xicu::isSpace(t.cp);
|
||||
if (r == t.expected) { printf("PASS: U+%04X %s\n", t.cp, t.desc); passed++; }
|
||||
else { printf("FAIL: U+%04X %s got %d exp %d\n", t.cp, t.desc, r, t.expected); failed++; }
|
||||
}
|
||||
|
||||
// Test isDecimal (sparse_map)
|
||||
struct { uint32_t cp; bool expected; const char* desc; } dec_tests[] = {
|
||||
{ '0', true, "Digit 0" },
|
||||
{ '9', true, "Digit 9" },
|
||||
{ 'A', false, "Letter A" },
|
||||
{ 0x0660, true, "Arabic-Indic 0" },
|
||||
{ 0x0966, true, "Devanagari 0" },
|
||||
{ 0xFF10, true, "Fullwidth 0" },
|
||||
};
|
||||
|
||||
printf("\n=== isDecimal (sparse_map) ===\n");
|
||||
for (auto& t : dec_tests) {
|
||||
bool r = xicu::isDecimal(t.cp);
|
||||
if (r == t.expected) { printf("PASS: U+%04X %s\n", t.cp, t.desc); passed++; }
|
||||
else { printf("FAIL: U+%04X %s got %d exp %d\n", t.cp, t.desc, r, t.expected); failed++; }
|
||||
}
|
||||
|
||||
// Test getDecimal_val (delta_ranges)
|
||||
struct { uint32_t cp; int expected; const char* desc; } decval_tests[] = {
|
||||
{ '0', 0, "Digit 0" },
|
||||
{ '5', 5, "Digit 5" },
|
||||
{ '9', 9, "Digit 9" },
|
||||
{ 0x0665, 5, "Arabic-Indic 5" },
|
||||
{ 'A', 0, "Letter A" },
|
||||
};
|
||||
|
||||
printf("\n=== getDecimal_val (delta_ranges) ===\n");
|
||||
for (auto& t : decval_tests) {
|
||||
int r = xicu::getDecimal_val(t.cp);
|
||||
if (r == t.expected) { printf("PASS: U+%04X %s = %d\n", t.cp, t.desc, r); passed++; }
|
||||
else { printf("FAIL: U+%04X %s got %d exp %d\n", t.cp, t.desc, r, t.expected); failed++; }
|
||||
}
|
||||
|
||||
// Test getUppercase_map (sparse_map)
|
||||
struct { uint32_t cp; int expected; const char* desc; } up_tests[] = {
|
||||
{ 'a', 'A' - 'a', "a -> A" },
|
||||
{ 'z', 'Z' - 'z', "z -> Z" },
|
||||
{ 0x00E9, 0x00C9 - 0x00E9, "e acute -> E acute" },
|
||||
{ 'A', 0, "A (already upper)" },
|
||||
{ '0', 0, "Digit 0" },
|
||||
};
|
||||
|
||||
printf("\n=== getUppercase_map (sparse_map) ===\n");
|
||||
for (auto& t : up_tests) {
|
||||
int r = xicu::getUppercase_map(t.cp);
|
||||
if (r == t.expected) { printf("PASS: U+%04X %s = %d\n", t.cp, t.desc, r); passed++; }
|
||||
else { printf("FAIL: U+%04X %s got %d exp %d\n", t.cp, t.desc, r, t.expected); failed++; }
|
||||
}
|
||||
|
||||
// Test getLowercase_map (sparse_map)
|
||||
struct { uint32_t cp; int expected; const char* desc; } low_tests[] = {
|
||||
{ 'A', 'a' - 'A', "A -> a" },
|
||||
{ 'Z', 'z' - 'Z', "Z -> z" },
|
||||
{ 0x00C9, 0x00E9 - 0x00C9, "E acute -> e acute" },
|
||||
{ 'a', 0, "a (already lower)" },
|
||||
{ '0', 0, "Digit 0" },
|
||||
};
|
||||
|
||||
printf("\n=== getLowercase_map (sparse_map) ===\n");
|
||||
for (auto& t : low_tests) {
|
||||
int r = xicu::getLowercase_map(t.cp);
|
||||
if (r == t.expected) { printf("PASS: U+%04X %s = %d\n", t.cp, t.desc, r); passed++; }
|
||||
else { printf("FAIL: U+%04X %s got %d exp %d\n", t.cp, t.desc, r, t.expected); failed++; }
|
||||
}
|
||||
|
||||
printf("\n=== Summary ===\n");
|
||||
printf("Passed: %d\n", passed);
|
||||
printf("Failed: %d\n", failed);
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user