diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 22:12:02 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 22:12:02 +0300 |
| commit | 94c5e361fbb229b0cd6853e2102a7d95f1f358b3 (patch) | |
| tree | 3c0f11af9dcb84dac8067a31a6979acd6dd56fbf /tests/common/test_utf8.c | |
| parent | 08dc9047098d6d96791024ac7d8f5837633673ef (diff) | |
better public interface and doxygen
Diffstat (limited to 'tests/common/test_utf8.c')
| -rw-r--r-- | tests/common/test_utf8.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/common/test_utf8.c b/tests/common/test_utf8.c new file mode 100644 index 0000000..72f8904 --- /dev/null +++ b/tests/common/test_utf8.c @@ -0,0 +1,27 @@ +#include "common/utf8.h" +#include <assert.h> +#include <stdlib.h> +#include <string.h> + +int main(void) +{ + char latin1[256]; + for (int i = 1; i <= 255; i++) latin1[i - 1] = (char)i; + latin1[255] = '\0'; + size_t len = 0, back_len = 0; + char *utf8 = yasl_utf8_from_latin1(latin1, 255, &len); + assert(utf8 && yasl_utf8_validate(utf8, len)); + char *back = yasl_utf8_to_latin1(utf8, &back_len); + assert(back && back_len == 255 && memcmp(back, latin1, 256) == 0); + free(back); + free(utf8); + assert(!yasl_utf8_to_latin1("😀", &len)); + assert(!yasl_utf8_to_latin1("\xc3", &len)); + assert(!yasl_utf8_validate("\xc3", 1)); + assert(!yasl_utf8_validate("\xe2\x82", 2)); + assert(!yasl_utf8_validate("\xf0\x9f\x98", 3)); + assert(!yasl_utf8_validate("\xed\xa0\x80", 3)); /* Surrogate. */ + assert(yasl_utf8_validate("😀", sizeof("😀") - 1)); + assert(yasl_utf8_validate(NULL, 0)); + return 0; +} |
