commit 7ddf17bf2f20b598d204f32d441e8ea30765b577
parent 1815d4d8d141da580372c678c3e38fab0e948d52
Author: Laslo Hunhold <dev@frign.de>
Date: Fri, 26 May 2023 10:02:58 +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@frign.de>
Diffstat:
3 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/gen/bidirectional-test.c b/gen/bidirectional-test.c
@@ -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;
@@ -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",
@@ -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]);
@@ -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;
@@ -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
@@ -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
@@ -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];
@@ -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 ||
@@ -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);