comparison tests.c @ 640:9e1f9e1d1487

Aaand some more work. Still just a broken concept.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 24 Jan 2020 09:13:24 +0200
parents d191ded8a790
children a2bf1ea05b05
comparison
equal deleted inserted replaced
639:8c957ad9d4c3 640:9e1f9e1d1487
563 563
564 #ifdef TH_EXPERIMENTAL_REGEX 564 #ifdef TH_EXPERIMENTAL_REGEX
565 565
566 typedef struct 566 typedef struct
567 { 567 {
568 th_regex_char *str; 568 th_regex_char_t *str;
569 size_t nmatches; 569 size_t nmatches;
570 int flags; 570 int flags;
571 } test_regex_def; 571 } test_regex_def;
572 572
573 573
574 void test_regex_list(const test_regex_def *list, const th_regex_char *pattern) 574 void test_regex_list(const test_regex_def *list, const th_regex_char_t *pattern)
575 { 575 {
576 th_regex_ctx *reg = NULL; 576 th_regex_t *reg = NULL;
577 int res; 577 int res;
578 578
579 printf("========================================\n"); 579 printf("========================================\n");
580 printf("pattern '%s'\n", pattern); 580 printf("pattern '%s'\n", pattern);
581 if ((res = th_regex_compile(&reg, pattern)) != THERR_OK) 581 if ((res = th_regex_compile(&reg, pattern)) != THERR_OK)
585 goto out; 585 goto out;
586 } 586 }
587 587
588 for (const test_regex_def *def = list; def->str != NULL; def++) 588 for (const test_regex_def *def = list; def->str != NULL; def++)
589 { 589 {
590 th_regex_match_node *matches = NULL; 590 th_regex_match_t *matches = NULL;
591 size_t nmatches; 591 size_t nmatches;
592 592
593 if ((res = th_regex_match(reg, def->str, 593 if ((res = th_regex_match(reg, def->str,
594 &nmatches, &matches, -1, def->flags)) != THERR_OK) 594 &nmatches, &matches, -1, def->flags)) != THERR_OK)
595 { 595 {
601 printf(" '%s': matched %" PRIu_SIZE_T " time(s), testresult=%s\n", 601 printf(" '%s': matched %" PRIu_SIZE_T " time(s), testresult=%s\n",
602 def->str, 602 def->str,
603 nmatches, 603 nmatches,
604 def->nmatches == nmatches ? "YES" : "NO"); 604 def->nmatches == nmatches ? "YES" : "NO");
605 605
606 for (th_regex_match_node *m = matches; 606 for (th_regex_match_t *m = matches;
607 m != NULL; m = (th_regex_match_node *) m->node.next) 607 m != NULL; m = (th_regex_match_t *) m->node.next)
608 { 608 {
609 char *tmp = th_strndup(def->str + m->start, m->len); 609 char *tmp = th_strndup(def->str + m->start, m->len);
610 printf(" match [%" PRIu_SIZE_T " ++ %" PRIu_SIZE_T "]: '%s'\n", 610 printf(" match [%" PRIu_SIZE_T " ++ %" PRIu_SIZE_T "]: '%s'\n",
611 m->start, m->len, tmp); 611 m->start, m->len, tmp);
612 th_free(tmp); 612 th_free(tmp);
876 // Regular expressions 876 // Regular expressions
877 // 877 //
878 #ifdef TH_EXPERIMENTAL_REGEX 878 #ifdef TH_EXPERIMENTAL_REGEX
879 if (test_set_start("Regular expressions")) 879 if (test_set_start("Regular expressions"))
880 { 880 {
881 th_regex_ctx *reg = NULL;
882 int res;
883
884 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG 881 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG
885 th_dbg_re_flags = TH_DBG_RE_MATCH; 882 th_dbg_re_flags = TH_DBG_RE_MATCH;
886 #endif 883 #endif
887 884
888 #if 0 885 #if 0
889 res = th_regex_compile(&reg, "z*k+abba fabboa? k{4} [gz]{1,2} foo(bar|zoo)?"); 886 {
890 if (res != THERR_OK) 887 th_regex_t *reg = NULL;
891 printf("result: %s\n", th_error_str(res)); 888 int res = th_regex_compile(&reg, "z*k+abba fabboa? k{4} [gz]{1,2} foo(bar|zoo)?");
892 th_regex_free(reg); 889 if (res != THERR_OK)
890 printf("result: %s\n", th_error_str(res));
891 th_regex_free(reg);
892 }
893 893
894 // 894 //
895 { 895 {
896 static const test_regex_def tlist[] = 896 static const test_regex_def tlist[] =
897 { 897 {