Mercurial > hg > th-libs
comparison tests.c @ 666:e1d27caf0dbd
More work on regex stuff.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 27 Jan 2020 12:43:39 +0200 |
parents | c5aa9ada1051 |
children | 48e8820bc625 |
comparison
equal
deleted
inserted
replaced
665:4932188c9101 | 666:e1d27caf0dbd |
---|---|
601 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern) | 601 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern) |
602 { | 602 { |
603 th_regex_t *expr = NULL; | 603 th_regex_t *expr = NULL; |
604 int res; | 604 int res; |
605 | 605 |
606 printf("========================================\n"); | 606 printf("\n========================================\n\n"); |
607 printf("Compiling pattern \"%s\"\n", pattern); | 607 printf("Compiling pattern \"%s\"\n", pattern); |
608 if ((res = th_regex_compile(&expr, pattern)) != THERR_OK) | 608 if ((res = th_regex_compile(&expr, pattern)) != THERR_OK) |
609 { | 609 { |
610 THERR("Regex compilation failed: %s\n", | 610 THERR("Regex compilation failed: %s\n", |
611 th_error_str(res)); | 611 th_error_str(res)); |
618 for (const test_regex_def1 *def = list; def->str != NULL; def++) | 618 for (const test_regex_def1 *def = list; def->str != NULL; def++) |
619 { | 619 { |
620 th_regex_match_t *matches = NULL; | 620 th_regex_match_t *matches = NULL; |
621 size_t nmatches; | 621 size_t nmatches; |
622 | 622 |
623 printf("----------------------------------------\n"); | 623 printf("\n----------------------------------------\n"); |
624 if ((res = th_regex_match(expr, def->str, | 624 if ((res = th_regex_match(expr, def->str, |
625 &nmatches, &matches, -1, def->flags)) != THERR_OK) | 625 &nmatches, &matches, -1, def->flags)) != THERR_OK) |
626 { | 626 { |
627 THERR("Regex match returned error: %s\n", | 627 THERR("Regex match returned error: %s\n", |
628 th_error_str(res)); | 628 th_error_str(res)); |
643 } | 643 } |
644 | 644 |
645 | 645 |
646 void test_regex_list2(const test_regex_def2 *list) | 646 void test_regex_list2(const test_regex_def2 *list) |
647 { | 647 { |
648 printf("========================================\n"); | 648 printf("\n========================================\n\n"); |
649 | 649 |
650 for (const test_regex_def2 *def = list; def->str != NULL; def++) | 650 for (const test_regex_def2 *def = list; def->str != NULL; def++) |
651 { | 651 { |
652 th_regex_t *expr = NULL; | 652 th_regex_t *expr = NULL; |
653 th_regex_match_t *matches = NULL; | 653 th_regex_match_t *matches = NULL; |
957 | 957 |
958 { | 958 { |
959 const char *str = "z*k+abba fabboa? [a-zA-Z_-] \\{\\} k{4} ([0-9]+ yay){1,2} foo(bar|zoo)?"; | 959 const char *str = "z*k+abba fabboa? [a-zA-Z_-] \\{\\} k{4} ([0-9]+ yay){1,2} foo(bar|zoo)?"; |
960 th_regex_t *expr = NULL; | 960 th_regex_t *expr = NULL; |
961 int res = th_regex_compile(&expr, str); | 961 int res = th_regex_compile(&expr, str); |
962 | |
962 printf("REGEX: \"%s\"\n", str); | 963 printf("REGEX: \"%s\"\n", str); |
964 | |
963 if (res == THERR_OK) | 965 if (res == THERR_OK) |
964 th_regex_dump(&testio, 1, expr); | 966 th_regex_dump(&testio, 1, expr); |
965 else | 967 else |
966 printf("ERROR: %s\n", th_error_str(res)); | 968 printf("ERROR: %s\n", th_error_str(res)); |
969 | |
967 th_regex_free(expr); | 970 th_regex_free(expr); |
968 } | 971 } |
969 | 972 |
970 #if 0 | 973 { |
974 static const test_regex_def1 tlist[] = | |
975 { | |
976 { "abcfoabcccg" , 1, 0 }, | |
977 { "abcbcfoabcccg" , 1, 0 }, | |
978 { "abcbcfoabccg abcbcfoabccccg" , 2, 0 }, | |
979 { "ffdsafS abcbcfoabccg zasdf" , 1, 0 }, | |
980 { NULL , 0, 0 } | |
981 }; | |
982 | |
983 test_regex_list1(tlist, "a(bc){1,2}fo[oab]*cc?g"); | |
984 } | |
985 | |
971 { | 986 { |
972 static const test_regex_def1 tlist[] = | 987 static const test_regex_def1 tlist[] = |
973 { | 988 { |
974 { "abcfoabccg" , 1, 0 }, | 989 { "abcfoabccg" , 1, 0 }, |
975 { "abcbcfoabccg" , 1, 0 }, | 990 { "abcbcfoabccg" , 1, 0 }, |
976 { "abcbcfoabccgabcbcfoabccg" , 2, 0 }, | 991 { "abcbcfoabccgabcbcfoabccg" , 1, 0 }, |
977 { "ffdsafS abcbcfoabccg zasdf" , 1, 0 }, | |
978 { NULL , 0, 0 } | |
979 }; | |
980 | |
981 test_regex_list1(tlist, "a(bc){1,2}fo[oab]*cc?g"); | |
982 } | |
983 | |
984 { | |
985 static const test_regex_def1 tlist[] = | |
986 { | |
987 { "abcfoabccg" , 1, 0 }, | |
988 { "abcbcfoabccg" , 1, 0 }, | |
989 { "abcbcfoabccgabcbcfoabccg" , 2, 0 }, | |
990 { "ffdsafS abcbcfoabccg zasdf" , 0, 0 }, | 992 { "ffdsafS abcbcfoabccg zasdf" , 0, 0 }, |
991 { NULL , 0, 0 } | 993 { NULL , 0, 0 } |
992 }; | 994 }; |
993 | 995 |
994 test_regex_list1(tlist, "^a(bc){1,2}fo[oab]*cc?g"); | 996 test_regex_list1(tlist, "^a(bc){1,2}fo[oab]*cc?g"); |
1004 { NULL , 0, 0 } | 1006 { NULL , 0, 0 } |
1005 }; | 1007 }; |
1006 | 1008 |
1007 test_regex_list1(tlist, "g$"); | 1009 test_regex_list1(tlist, "g$"); |
1008 } | 1010 } |
1009 #endif | |
1010 | 1011 |
1011 { | 1012 { |
1012 static const test_regex_def1 tlist[] = | 1013 static const test_regex_def1 tlist[] = |
1013 { | 1014 { |
1014 { "zoobar" , 1, 0 }, | 1015 { "zoobar" , 1, 0 }, |
1017 { "hoho zoobar bar" , 1, 0 }, | 1018 { "hoho zoobar bar" , 1, 0 }, |
1018 { NULL , 0, 0 } | 1019 { NULL , 0, 0 } |
1019 }; | 1020 }; |
1020 | 1021 |
1021 test_regex_list1(tlist, "zoo.*?bar"); | 1022 test_regex_list1(tlist, "zoo.*?bar"); |
1022 // test_regex_list(tlist, "zoo.*?bar"); | 1023 test_regex_list1(tlist, "zoo.*bar"); |
1023 } | 1024 } |
1024 } | 1025 } |
1025 #endif | 1026 #endif |
1026 | 1027 |
1027 // | 1028 // |