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>
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
@@ -14,6 +14,7 @@ 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 @@ "\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 @@ 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 @@ 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 @@ } 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
@@ -1398,7 +1398,10 @@ 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
@@ -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 @@ 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 @@ 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);