chiark / gitweb /
transition various bits of code to unicode.h interfaces
[disorder] / lib / test.c
index 69ca609af532590af3e5ab3f331f44f58a2556f8..4b073a8b8fdfc75cab205d6a03ad1cd49705f7c3 100644 (file)
@@ -139,15 +139,16 @@ static void test_utf8(void) {
   char *u8;                                    \
                                                \
   insist(validutf8(CHARS));                    \
-  ucs = utf82ucs4(CHARS);                      \
+  ucs = utf8_to_utf32(CHARS, strlen(CHARS), 0); \
   insist(ucs != 0);                            \
-  insist(!ucs4cmp(w, ucs));                    \
-  u8 = ucs42utf8(ucs);                         \
+  insist(!utf32_cmp(w, ucs));                  \
+  u8 = utf32_to_utf8(ucs, utf32_len(ucs), 0);   \
   insist(u8 != 0);                             \
   insist(!strcmp(u8, CHARS));                  \
 } while(0)
 
   fprintf(stderr, "test_utf8\n");
+#define validutf8(S) utf8_valid((S), strlen(S))
 
   /* empty string */
 
@@ -392,8 +393,10 @@ static void test_casefold(void) {
       break;
     }
     if(l) {
+      uint32_t *d;
       /* Case-folded data is now normalized */
-      canon_expected = ucs42utf8(utf32_decompose_canon(&l, 1, 0));
+      d = utf32_decompose_canon(&l, 1, 0);
+      canon_expected = utf32_to_utf8(d, utf32_len(d), 0);
       if(strcmp(canon_folded, canon_expected)) {
        fprintf(stderr, "%s:%d: canon-casefolding %#lx got '%s', expected '%s'\n",
                __FILE__, __LINE__, (unsigned long)c,
@@ -401,7 +404,8 @@ static void test_casefold(void) {
        count_error();
       }
       ++tests;
-      compat_expected = ucs42utf8(utf32_decompose_compat(&l, 1, 0));
+      d = utf32_decompose_compat(&l, 1, 0);
+      compat_expected = utf32_to_utf8(d, utf32_len(d), 0);
       if(strcmp(compat_folded, compat_expected)) {
        fprintf(stderr, "%s:%d: compat-casefolding %#lx got '%s', expected '%s'\n",
                __FILE__, __LINE__, (unsigned long)c,
@@ -467,7 +471,7 @@ static FILE *open_unicode_test(const char *path) {
   return fp;
 }
 
-/** @brief Run breaking tests for utf32_is_gcb() etc */
+/** @brief Run breaking tests for utf32_grapheme_boundary() etc */
 static void breaktest(const char *path,
                       int (*breakfn)(const uint32_t *, size_t, size_t)) {
   FILE *fp = open_unicode_test(path);
@@ -567,11 +571,11 @@ static void test_unicode(void) {
       fprintf(stderr,                                           \
               "NormalizationTest.txt:%d: c%d != "#T"(c%d)\n",   \
               lineno, A, B);                                    \
-      fprintf(stderr, "    c%d:      %s\n",                    \
+      fprintf(stderr, "      c%d: %s\n",                         \
               A, format_utf32(c[A]));                          \
       fprintf(stderr, "%4s(c%d): %s\n",                                \
               #T, B, format_utf32(T##_c[B]));                  \
-      count_error();                                                   \
+      count_error();                                           \
     }                                                          \
   } while(0)
     unt_check(NFD, 3, 1);
@@ -591,7 +595,7 @@ static void test_unicode(void) {
     xfree(l);
   }
   fclose(fp);
-  breaktest("auxiliary/GraphemeBreakTest.txt", utf32_is_gcb);
+  breaktest("auxiliary/GraphemeBreakTest.txt", utf32_is_grapheme_boundary);
   breaktest("auxiliary/WordBreakTest.txt", utf32_is_word_boundary);
 }