diff tests.c @ 610:a0e8d9c6300b

A bit more work on the regex stuff.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 Jan 2020 03:33:11 +0200
parents 566e6ef41f9d
children 2e3b81ae8c8a
line wrap: on
line diff
--- a/tests.c	Thu Jan 16 01:46:19 2020 +0200
+++ b/tests.c	Thu Jan 16 03:33:11 2020 +0200
@@ -562,8 +562,8 @@
 typedef struct
 {
     th_regex_char *str;
+    size_t nmatches;
     int flags;
-    BOOL result;
 } test_regex_def;
 
 
@@ -583,16 +583,31 @@
 
     for (const test_regex_def *def = list; def->str != NULL; def++)
     {
-        BOOL matched = FALSE;
+        th_regex_match_node *matches = NULL;
+        size_t nmatches;
 
-        if ((res = th_regex_match(reg, def->str, &matched, NULL, -1, def->flags)) != THERR_OK)
+        if ((res = th_regex_match(reg, def->str, &nmatches, &matches, -1, def->flags)) != THERR_OK)
         {
             THERR("Regex match returned error: %s\n",
                 th_error_str(res));
             goto out;
         }
 
-        printf("  '%s': %s\n", def->str, matched ? "YES" : "NO");
+        printf("  '%s': matched %" PRIu_SIZE_T " time(s), testresult=%s\n",
+            def->str,
+            nmatches,
+            def->nmatches == nmatches ? "YES" : "NO");
+
+        for (th_regex_match_node *m = matches;
+            m != NULL; m = (th_regex_match_node *) m->node.next)
+        {
+            char *tmp = th_strndup(def->str + m->start, m->len);
+            printf("  match [%" PRIu_SIZE_T " ++ %" PRIu_SIZE_T "]: '%s'\n",
+                m->start, m->len, tmp);
+            th_free(tmp);
+        }
+
+        th_regex_free_matches(matches);
     }
 
 out:
@@ -865,12 +880,13 @@
 
         test_regex_def tst1[] =
         {
-            { "abcfoabccg"        , 0, TRUE },
-            { "abcbcfoabccg"      , 0, TRUE },
-            { NULL, 0, FALSE }
+            { "abcfoabccg"        , 1, 0 },
+            { "abcbcfoabccg"      , 1, 0 },
+            { "abcbcfoabccgabcbcfoabccg"   , 2, 0 },
+            { NULL, 0, 0 }
         };
 
-        test_regex_list("^a(bc){1,2}fo[oab]*cc?g", tst1);
+        test_regex_list("a(bc){1,2}fo[oab]*cc?g", tst1);
     }
 
     //