commit 719d805b28b9e34d5f5e83fcbdb0fbb41c20ec6d
Author:     Laslo Hunhold <[email protected]>
AuthorDate: Mon May 29 10:37:49 2023 +0200
Commit:     Laslo Hunhold <[email protected]>
CommitDate: Mon May 29 10:37:49 2023 +0200

    Reflect mirroring in the bidi-tests
    
    The bidi-tests do not contain mirrored test data, so we need to generate
    it ad-hoc using the generated mirror-LUTs.
    
    Signed-off-by: Laslo Hunhold <[email protected]>

diff --git a/test/bidirectional.c b/test/bidirectional.c
index f2ba339..5d655fb 100644
--- a/test/bidirectional.c
+++ b/test/bidirectional.c
@@ -5,16 +5,27 @@
 #include <stdio.h>
 
 #include "../gen/bidirectional-test.h"
+#include "../gen/bidirectional.h"
 #include "../gen/types.h"
 #include "../grapheme.h"
 #include "util.h"
 
+static inline int_least16_t
+get_mirror_offset(uint_least32_t cp)
+{
+       if (cp <= UINT32_C(0x10FFFF)) {
+               return mirror_minor[mirror_major[cp >> 8] + (cp & 0xFF)];
+       } else {
+               return 0;
+       }
+}
+
 int
 main(int argc, char *argv[])
 {
        enum grapheme_bidirectional_direction resolved;
-       uint_least32_t data[512],
-               output[512]; /* TODO iterate and get max, allocate */
+       uint_least32_t data[512], output[512],
+               target; /* TODO iterate and get max, allocate */
        int_least8_t lev[512];
        size_t i, num_tests, failed, datalen, levlen, outputlen, ret, j, m,
                ret2;
@@ -75,10 +86,13 @@ main(int argc, char *argv[])
                        }
 
                        for (j = 0; j < ret2; j++) {
+                               target = bidirectional_test[i]
+                                                .cp[bidirectional_test[i]
+                                                            .reorder[j]];
                                if (output[j] !=
-                                   bidirectional_test[i]
-                                           .cp[bidirectional_test[i]
-                                                       .reorder[j]]) {
+                                   (uint_least32_t)((int_least32_t)target +
+                                                    get_mirror_offset(
+                                                            target))) {
                                        goto err;
                                }
                        }

Reply via email to