[hackers] [libgrapheme] Reflect mirroring in the bidi-tests || Laslo Hunhold

From: <git_AT_suckless.org>
Date: Mon, 29 May 2023 14:38:44 +0200 (CEST)

commit 719d805b28b9e34d5f5e83fcbdb0fbb41c20ec6d
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Mon May 29 10:37:49 2023 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
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 <dev_AT_frign.de>

diff --git a/test/bidirectional.c b/test/bidirectional.c
index f2ba339..5d655fb 100644
--- a/test/bidirectional.c
+++ b/test/bidirectional.c
_AT_@ -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;
_AT_@ -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;
                                 }
                         }
Received on Mon May 29 2023 - 14:38:44 CEST

This archive was generated by hypermail 2.3.0 : Mon May 29 2023 - 14:48:41 CEST