From 2e125c1c7e75db14a88f0b8b09e61a132977c63e Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 20 May 2024 17:56:55 +0200 Subject: Support the 4 forms of Unicode string normalization --- test/_norm-test.h | 20 +++++++++++++------- test/norm-nfc-test.c | 2 ++ test/norm-nfd-test.c | 2 +- test/norm-nfkc-test.c | 2 ++ test/norm-nfkd-test.c | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 test/norm-nfc-test.c create mode 100644 test/norm-nfkc-test.c (limited to 'test') diff --git a/test/_norm-test.h b/test/_norm-test.h index 68209f1..8df9f3f 100644 --- a/test/_norm-test.h +++ b/test/_norm-test.h @@ -15,7 +15,6 @@ #include #define TESTFILE "norm.in" -#define FUNC CONCAT(ucsnorm_, NORMTYPE) static bool test(struct u8view, int); @@ -39,10 +38,8 @@ main(int, char **argv) if (line[nr - 1] == '\n') line[--nr] = '\0'; - if (!test((struct u8view){line, (size_t)nr}, id)) { + if (!test((struct u8view){line, (size_t)nr}, id)) rv = EXIT_FAILURE; - break; - } } if (ferror(fp)) err("getline: %s:", TESTFILE); @@ -87,12 +84,21 @@ test(struct u8view sv, int id) for (size_t i = 0; i < 5; i++) { size_t base; - if (streq(STR(NORMTYPE), "nfkd")) + const char *nt = STR(NORMTYPE); + if (streq(nt, "NT_NFC")) + base = i < 3 ? 1 : 3; + else if (streq(nt, "NT_NFD")) + base = i < 3 ? 2 : 4; + else if (streq(nt, "NT_NFKC")) + base = 3; + else if (streq(nt, "NT_NFKD")) base = 4; else - base = i < 3 ? 2 : 4; + err("invalid NORMTYPE ‘%s’", nt); + struct u8view normd = {}; - normd.p = FUNC(&normd.len, columns.buf[i], alloc_arena, &ctx); + normd.p = + ucsnorm(&normd.len, columns.buf[i], alloc_arena, &ctx, NORMTYPE); if (!ucseq(columns.buf[base], normd)) { warn("case %d: expected c%zu to be ‘%.*s’ but got ‘%.*s’", id, i + 1, SV_PRI_ARGS(columns.buf[base]), SV_PRI_ARGS(normd)); diff --git a/test/norm-nfc-test.c b/test/norm-nfc-test.c new file mode 100644 index 0000000..176cd69 --- /dev/null +++ b/test/norm-nfc-test.c @@ -0,0 +1,2 @@ +#define NORMTYPE NT_NFC +#include "_norm-test.h" diff --git a/test/norm-nfd-test.c b/test/norm-nfd-test.c index 6067352..816bba5 100644 --- a/test/norm-nfd-test.c +++ b/test/norm-nfd-test.c @@ -1,2 +1,2 @@ -#define NORMTYPE nfd +#define NORMTYPE NT_NFD #include "_norm-test.h" diff --git a/test/norm-nfkc-test.c b/test/norm-nfkc-test.c new file mode 100644 index 0000000..cddce1c --- /dev/null +++ b/test/norm-nfkc-test.c @@ -0,0 +1,2 @@ +#define NORMTYPE NT_NFKC +#include "_norm-test.h" diff --git a/test/norm-nfkd-test.c b/test/norm-nfkd-test.c index 3fe8ff2..34bebca 100644 --- a/test/norm-nfkd-test.c +++ b/test/norm-nfkd-test.c @@ -1,2 +1,2 @@ -#define NORMTYPE nfkd +#define NORMTYPE NT_NFKD #include "_norm-test.h" -- cgit v1.2.3