[hackers] [libgrapheme] Add resolved paragraph direction to tests || Laslo Hunhold
commit 7ddf17bf2f20b598d204f32d441e8ea30765b577
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Fri May 26 10:02:58 2023 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Fri May 26 10:02:58 2023 +0200
Add resolved paragraph direction to tests
Only the tests in BidiCharacterTests.txt specify the resolved direction,
so we express the non-specification by using the
neutral-direction-enum-type.
Running the tests, I noticed a small mistake I made, leading to the
wrong resolved type being emitted. The final solution is to use a proper
enum-return-type for the paragraph_level-function, which has been added
as a TODO.
Signed-off-by: Laslo Hunhold <dev_AT_frign.de>
diff --git a/gen/bidirectional-test.c b/gen/bidirectional-test.c
index 255ca86..df30c0e 100644
--- a/gen/bidirectional-test.c
+++ b/gen/bidirectional-test.c
_AT_@ -14,6 +14,7 @@ struct bidirectional_test {
size_t cplen;
enum grapheme_bidirectional_direction mode[3];
size_t modelen;
+ enum grapheme_bidirectional_direction resolved;
int_least8_t *level;
int_least8_t *reorder;
size_t reorderlen;
_AT_@ -212,6 +213,7 @@ bidirectional_test_list_print(const struct bidirectional_test *test,
"\tsize_t cplen;\n"
"\tenum grapheme_bidirectional_direction *mode;\n"
"\tsize_t modelen;\n"
+ "\tenum grapheme_bidirectional_direction resolved;\n"
"\tint_least8_t *level;\n"
"\tint_least8_t *reorder;\n"
"\tsize_t reorderlen;\n} %s[] = {\n",
_AT_@ -250,6 +252,20 @@ bidirectional_test_list_print(const struct bidirectional_test *test,
printf(" },\n");
printf("\t\t.modelen = %zu,\n", test[i].modelen);
+ printf("\t\t.resolved = ");
+ if (test[i].resolved ==
+ GRAPHEME_BIDIRECTIONAL_DIRECTION_NEUTRAL) {
+ printf("GRAPHEME_BIDIRECTIONAL_DIRECTION_"
+ "NEUTRAL");
+ } else if (test[i].resolved ==
+ GRAPHEME_BIDIRECTIONAL_DIRECTION_LTR) {
+ printf("GRAPHEME_BIDIRECTIONAL_DIRECTION_LTR");
+ } else if (test[i].resolved ==
+ GRAPHEME_BIDIRECTIONAL_DIRECTION_RTL) {
+ printf("GRAPHEME_BIDIRECTIONAL_DIRECTION_RTL");
+ }
+ printf(",\n");
+
printf("\t\t.level = (int_least8_t[]){");
for (j = 0; j < test[i].cplen; j++) {
printf(" %" PRIdLEAST8, test[i].level[j]);
_AT_@ -407,6 +423,11 @@ test_callback(const char *file, char **field, size_t nfields, char *comment,
field[1]);
exit(1);
}
+
+ /* the resolved paragraph level is always neutral as the test
+ * file does not specify it */
+ test[testlen - 1].resolved =
+ GRAPHEME_BIDIRECTIONAL_DIRECTION_NEUTRAL;
}
return 0;
_AT_@ -459,6 +480,21 @@ character_test_callback(const char *file, char **field, size_t nfields,
}
test[testlen - 1].modelen = 1;
+ /* parse resolved paragraph level */
+ if (strlen(field[2]) != 1) {
+ fprintf(stderr, "malformed resolved paragraph level.\n");
+ exit(1);
+ } else if (field[2][0] == '0') {
+ test[testlen - 1].resolved =
+ GRAPHEME_BIDIRECTIONAL_DIRECTION_LTR;
+ } else if (field[2][0] == '1') {
+ test[testlen - 1].resolved =
+ GRAPHEME_BIDIRECTIONAL_DIRECTION_RTL;
+ } else {
+ fprintf(stderr, "unhandled resolved paragraph level.\n");
+ exit(1);
+ }
+
if (tmp != test[testlen - 1].cplen) {
fprintf(stderr, "mismatch between string and level lengths.\n");
exit(1);
diff --git a/src/bidirectional.c b/src/bidirectional.c
index eef7c56..6062ed6 100644
--- a/src/bidirectional.c
+++ b/src/bidirectional.c
_AT_@ -1398,7 +1398,10 @@ preprocess(HERODOTUS_READER *r, enum grapheme_bidirectional_direction override,
if (resolved != NULL) {
/* store resolved paragraph level in output variable */
- *resolved = paragraph_level;
+ /* TODO use enum-type */
+ *resolved = (paragraph_level == 0) ?
+ GRAPHEME_BIDIRECTIONAL_DIRECTION_LTR :
+ GRAPHEME_BIDIRECTIONAL_DIRECTION_RTL;
}
if (buf == NULL) {
diff --git a/test/bidirectional.c b/test/bidirectional.c
index 105889e..8ba0ac8 100644
--- a/test/bidirectional.c
+++ b/test/bidirectional.c
_AT_@ -12,6 +12,7 @@
int
main(int argc, char *argv[])
{
+ enum grapheme_bidirectional_direction resolved;
uint_least32_t data[512],
output[512]; /* TODO iterate and get max, allocate */
int_least8_t lev[512];
_AT_@ -34,7 +35,7 @@ main(int argc, char *argv[])
bidirectional_test[i].cp,
bidirectional_test[i].cplen,
bidirectional_test[i].mode[m], data, datalen,
- NULL);
+ &resolved);
ret2 = 0;
if (ret != bidirectional_test[i].cplen ||
_AT_@ -42,6 +43,12 @@ main(int argc, char *argv[])
goto err;
}
+ /* resolved paragraph level (if specified in the test) */
+ if (bidirectional_test[i].resolved != GRAPHEME_BIDIRECTIONAL_DIRECTION_NEUTRAL &&
+ resolved != bidirectional_test[i].resolved) {
+ goto err;
+ }
+
/* line levels */
ret = grapheme_bidirectional_get_line_embedding_levels(
data, ret, lev, levlen);
Received on Fri May 26 2023 - 10:04:50 CEST
This archive was generated by hypermail 2.3.0
: Fri May 26 2023 - 10:12:38 CEST