comparison tests.c @ 643:a2bf1ea05b05

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 24 Jan 2020 12:06:43 +0200
parents 9e1f9e1d1487
children b897995101b7
comparison
equal deleted inserted replaced
642:3a35db5c1873 643:a2bf1ea05b05
575 { 575 {
576 th_regex_t *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);
581 if ((res = th_regex_compile(&reg, pattern)) != THERR_OK) 580 if ((res = th_regex_compile(&reg, pattern)) != THERR_OK)
582 { 581 {
583 THERR("Regex compilation failed: %s\n", 582 THERR("Regex compilation failed: %s\n",
584 th_error_str(res)); 583 th_error_str(res));
585 goto out; 584 goto out;
588 for (const test_regex_def *def = list; def->str != NULL; def++) 587 for (const test_regex_def *def = list; def->str != NULL; def++)
589 { 588 {
590 th_regex_match_t *matches = NULL; 589 th_regex_match_t *matches = NULL;
591 size_t nmatches; 590 size_t nmatches;
592 591
592 printf("----------------------------------------\n");
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 {
596 THERR("Regex match returned error: %s\n", 596 THERR("Regex match returned error: %s\n",
597 th_error_str(res)); 597 th_error_str(res));
598 goto out; 598 goto out;
599 } 599 }
600 600
601 printf("\npattern '%s'\n", pattern);
601 printf(" '%s': matched %" PRIu_SIZE_T " time(s), testresult=%s\n", 602 printf(" '%s': matched %" PRIu_SIZE_T " time(s), testresult=%s\n",
602 def->str, 603 def->str,
603 nmatches, 604 nmatches,
604 def->nmatches == nmatches ? "YES" : "NO"); 605 def->nmatches == nmatches ? "YES" : "NO");
605 606
877 // 878 //
878 #ifdef TH_EXPERIMENTAL_REGEX 879 #ifdef TH_EXPERIMENTAL_REGEX
879 if (test_set_start("Regular expressions")) 880 if (test_set_start("Regular expressions"))
880 { 881 {
881 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG 882 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG
882 th_dbg_re_flags = TH_DBG_RE_MATCH; 883 th_dbg_re_flags = th_verbosity > 0 ? TH_DBG_RE_MATCH : 0;
883 #endif 884 #endif
884 885
885 #if 0 886 #if 0
886 { 887 {
887 th_regex_t *reg = NULL; 888 th_regex_t *reg = NULL;
888 int res = th_regex_compile(&reg, "z*k+abba fabboa? k{4} [gz]{1,2} foo(bar|zoo)?"); 889 int res = th_regex_compile(&reg, "z*k+abba fabboa? k{4} [gz]{1,2} foo(bar|zoo)?");
889 if (res != THERR_OK) 890 if (res != THERR_OK)
890 printf("result: %s\n", th_error_str(res)); 891 printf("result: %s\n", th_error_str(res));
891 th_regex_free(reg); 892 th_regex_free(reg);
892 } 893 }
893
894 //
895 { 894 {
896 static const test_regex_def tlist[] = 895 static const test_regex_def tlist[] =
897 { 896 {
898 { "abcfoabccg" , 1, 0 }, 897 { "abcfoabccg" , 1, 0 },
899 { "abcbcfoabccg" , 1, 0 }, 898 { "abcbcfoabccg" , 1, 0 },