diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-05-03 01:21:34 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-05-03 01:21:34 +0200 |
commit | 25fe3d4b465728bce4ec417893865a57d6226b0c (patch) | |
tree | 92e6462a27ea9cd2ee799a3dc02db589568e6b42 /tests/servers | |
parent | b9e022302aa4a5d97f8b25a1db809e64b46b6f96 (diff) | |
parent | 717513a62d971681a342303216143b30c5d20d4b (diff) | |
download | redot-engine-25fe3d4b465728bce4ec417893865a57d6226b0c.tar.gz |
Merge pull request #81639 from MJacred/is_letter
Add `is_valid_letter()` to `TextServer`
Diffstat (limited to 'tests/servers')
-rw-r--r-- | tests/servers/test_text_server.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/servers/test_text_server.h b/tests/servers/test_text_server.h index 334c642d26..d982102a03 100644 --- a/tests/servers/test_text_server.h +++ b/tests/servers/test_text_server.h @@ -637,6 +637,97 @@ TEST_SUITE("[TextServer]") { } } + SUBCASE("[TextServer] Unicode letters") { + for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) { + Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i); + CHECK_FALSE_MESSAGE(ts.is_null(), "Invalid TS interface."); + + struct ul_testcase { + int fail_index = -1; // Expecting failure at given index. + char32_t text[10]; // Using 0 as the terminator. + }; + ul_testcase cases[14] = { + { + 0, + { 0x2D, 0x33, 0x30, 0, 0, 0, 0, 0, 0, 0 }, // "-30" + }, + { + 1, + { 0x61, 0x2E, 0x31, 0, 0, 0, 0, 0, 0, 0 }, // "a.1" + }, + { + 1, + { 0x61, 0x2C, 0x31, 0, 0, 0, 0, 0, 0, 0 }, // "a,1" + }, + { + 0, + { 0x31, 0x65, 0x2D, 0x32, 0, 0, 0, 0, 0, 0 }, // "1e-2" + }, + { + 0, + { 0xAB, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // "Left-Pointing Double Angle Quotation Mark" + }, + { + -1, + { 0x41, 0x42, 0, 0, 0, 0, 0, 0, 0, 0 }, // "AB" + }, + { + 4, + { 0x54, 0x65, 0x73, 0x74, 0x31, 0, 0, 0, 0, 0 }, // "Test1" + }, + { + 2, + { 0x54, 0x65, 0x2A, 0x73, 0x74, 0, 0, 0, 0, 0 }, // "Te*st" + }, + { + 4, + { 0x74, 0x65, 0x73, 0x74, 0x5F, 0x74, 0x65, 0x73, 0x74, 0x65 }, // "test_teste" + }, + { + 4, + { 0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, 0 }, // "test test" + }, + { + -1, + { 0x643, 0x402, 0x716, 0xB05, 0, 0, 0, 0, 0, 0 }, // "كЂܖଅ" (arabic letters), + }, + { + -1, + { 0x643, 0x402, 0x716, 0xB05, 0x54, 0x65, 0x73, 0x74, 0x30AA, 0x4E21 }, // 0-3 arabic letters, 4-7 latin letters, 8-9 CJK letters + }, + { + -1, + { 0x4D2, 0x4D6, 0x4DA, 0x4DC, 0, 0, 0, 0, 0, 0 }, // "ӒӖӚӜ" cyrillic letters + }, + { + -1, + { 0xC2, 0xC3, 0xC4, 0xC5, 0x100, 0x102, 0x104, 0xC7, 0x106, 0x108 }, // "ÂÃÄÅĀĂĄÇĆĈ" rarer latin letters + }, + }; + + for (int j = 0; j < 14; j++) { + ul_testcase test = cases[j]; + int failed_on_index = -1; + for (int k = 0; k < 10; k++) { + char32_t character = test.text[k]; + if (character == 0) { + break; + } + if (!ts->is_valid_letter(character)) { + failed_on_index = k; + break; + } + } + + if (test.fail_index == -1) { + CHECK_MESSAGE(test.fail_index == failed_on_index, "In interface ", ts->get_name() + ": In test case ", j, ", the character at index ", failed_on_index, " should have been a letter."); + } else { + CHECK_MESSAGE(test.fail_index == failed_on_index, "In interface ", ts->get_name() + ": In test case ", j, ", expected first non-letter at index ", test.fail_index, ", but found at index ", failed_on_index); + } + } + } + } + SUBCASE("[TextServer] Strip Diacritics") { for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) { Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(i); |