* Test utf8_strnwidth with various Chinese strings * Chinese characters typically have a width of 2 columns when displayed */
| 7 | * Chinese characters typically have a width of 2 columns when displayed |
| 8 | */ |
| 9 | void test_utf8_width__strnwidth_chinese(void) |
| 10 | { |
| 11 | const char *str; |
| 12 | |
| 13 | /* Test basic ASCII - each character should have width 1 */ |
| 14 | cl_assert_equal_i(5, utf8_strnwidth("Hello", 5, 0)); |
| 15 | /* skip_ansi = 1 */ |
| 16 | cl_assert_equal_i(5, utf8_strnwidth("Hello", 5, 1)); |
| 17 | |
| 18 | /* Test simple Chinese characters - each should have width 2 */ |
| 19 | /* "你好" is 6 bytes (3 bytes per char in UTF-8), 4 display columns */ |
| 20 | cl_assert_equal_i(4, utf8_strnwidth("你好", 6, 0)); |
| 21 | |
| 22 | /* Test mixed ASCII and Chinese - ASCII = 1 column, Chinese = 2 columns */ |
| 23 | /* "h"(1) + "i"(1) + "你"(2) + "好"(2) = 6 */ |
| 24 | cl_assert_equal_i(6, utf8_strnwidth("Hi你好", 8, 0)); |
| 25 | |
| 26 | /* Test longer Chinese string */ |
| 27 | /* 5 Chinese chars = 10 display columns */ |
| 28 | cl_assert_equal_i(10, utf8_strnwidth("你好世界!", 15, 0)); |
| 29 | |
| 30 | /* Test individual Chinese character width */ |
| 31 | cl_assert_equal_i(2, utf8_strnwidth("中", 3, 0)); |
| 32 | |
| 33 | /* Test empty string */ |
| 34 | cl_assert_equal_i(0, utf8_strnwidth("", 0, 0)); |
| 35 | |
| 36 | /* Test length limiting */ |
| 37 | str = "你好世界"; |
| 38 | /* Only first char "你"(2 columns) within 3 bytes */ |
| 39 | cl_assert_equal_i(2, utf8_strnwidth(str, 3, 0)); |
| 40 | /* First two chars "你好"(4 columns) in 6 bytes */ |
| 41 | cl_assert_equal_i(4, utf8_strnwidth(str, 6, 0)); |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * Tests for utf8_strwidth (simpler version without length limit) |
nothing calls this directly
no test coverage detected