mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-06 02:51:00 +01:00
glib: unicode: add tests for g_utf8_normalize()
Test corner cases and some examples from Unicode Standard Annex #15 http://unicode.org/reports/tr15/
This commit is contained in:
parent
221bbde429
commit
deb495de42
@ -1889,6 +1889,45 @@ test_iso15924 (void)
|
|||||||
#undef PACK
|
#undef PACK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_normalize (void)
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
const gchar *str;
|
||||||
|
const gchar *nfd;
|
||||||
|
const gchar *nfc;
|
||||||
|
const gchar *nfkd;
|
||||||
|
const gchar *nfkc;
|
||||||
|
} Test;
|
||||||
|
Test tests[] = {
|
||||||
|
{ "Äffin", "A\u0308ffin", "Äffin", "A\u0308ffin", "Äffin" },
|
||||||
|
{ "Ä\uFB03n", "A\u0308\uFB03n", "Ä\uFB03n", "A\u0308ffin", "Äffin" },
|
||||||
|
{ "Henry IV", "Henry IV", "Henry IV", "Henry IV", "Henry IV" },
|
||||||
|
{ "Henry \u2163", "Henry \u2163", "Henry \u2163", "Henry IV", "Henry IV" },
|
||||||
|
{ "non-utf\x88", NULL, NULL, NULL, NULL },
|
||||||
|
{ "", "", "", "", "" },
|
||||||
|
};
|
||||||
|
|
||||||
|
#define TEST(str, mode, expected) \
|
||||||
|
{ \
|
||||||
|
gchar *normalized = g_utf8_normalize (str, -1, mode); \
|
||||||
|
g_assert_cmpstr (normalized, ==, expected); \
|
||||||
|
g_free (normalized); \
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
||||||
|
{
|
||||||
|
TEST (tests[i].str, G_NORMALIZE_NFD, tests[i].nfd);
|
||||||
|
TEST (tests[i].str, G_NORMALIZE_NFC, tests[i].nfc);
|
||||||
|
TEST (tests[i].str, G_NORMALIZE_NFKD, tests[i].nfkd);
|
||||||
|
TEST (tests[i].str, G_NORMALIZE_NFKC, tests[i].nfkc);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef TEST
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@ -1933,6 +1972,7 @@ main (int argc,
|
|||||||
g_test_add_func ("/unicode/xdigit", test_xdigit);
|
g_test_add_func ("/unicode/xdigit", test_xdigit);
|
||||||
g_test_add_func ("/unicode/xdigit-value", test_xdigit_value);
|
g_test_add_func ("/unicode/xdigit-value", test_xdigit_value);
|
||||||
g_test_add_func ("/unicode/zero-width", test_zerowidth);
|
g_test_add_func ("/unicode/zero-width", test_zerowidth);
|
||||||
|
g_test_add_func ("/unicode/normalize", test_normalize);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user