chiark / gitweb /
tests: add a simple test for utf8_n_codepoints()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 16 Feb 2018 09:34:00 +0000 (10:34 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:58:59 +0000 (07:58 +0200)
src/test/test-utf8.c

index 1ea0901f690812993aad29d83a3223126109046b..c04c99dcad19467d640f09cae2e8e4c3aa3e791f 100644 (file)
@@ -106,6 +106,15 @@ static void test_utf16_to_utf8(void) {
         free(a);
 }
 
+static void test_utf8_n_codepoints(void) {
+        assert_se(utf8_n_codepoints("abc") == 3);
+        assert_se(utf8_n_codepoints("zażółcić gęślą jaźń") == 19);
+        assert_se(utf8_n_codepoints("串") == 1);
+        assert_se(utf8_n_codepoints("") == 0);
+        assert_se(utf8_n_codepoints("…👊🔪💐…") == 5);
+        assert_se(utf8_n_codepoints("\xF1") == (size_t) -1);
+}
+
 int main(int argc, char *argv[]) {
         test_utf8_is_valid();
         test_utf8_is_printable();
@@ -114,6 +123,7 @@ int main(int argc, char *argv[]) {
         test_utf8_escaping();
         test_utf8_escaping_printable();
         test_utf16_to_utf8();
+        test_utf8_n_codepoints();
 
         return 0;
 }