From ad014f5f33ed7f3079c6b7e688d12baf708ee3b3 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 15 Mar 2004 22:57:11 +0000 Subject: [PATCH] Converted regex module testing to the new test framework. --- lib/Makefile | 2 +- lib/regex-test.c | 44 ------------------------------------------- lib/regex.c | 11 +++++++++-- lib/regex.t | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 47 deletions(-) delete mode 100644 lib/regex-test.c create mode 100644 lib/regex.t diff --git a/lib/Makefile b/lib/Makefile index 1095da23..8791d240 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,6 +2,7 @@ DIRS+=lib PROGS+=obj/lib/db-tool obj/lib/buckettool +TESTS+=obj/lib/regex-ut LIBSH_MODS=alloc alloc_str ctmatch db fastbuf fb-file fb-mem lists \ log log2 md5 md5hex mmap pagecache patimatch patmatch pool \ @@ -23,7 +24,6 @@ obj/lib/buckettool: obj/lib/buckettool.o $(LIBSH) obj/lib/conf-test: obj/lib/conf-test.o $(LIBSH) obj/lib/sort-test: obj/lib/sort-test.o $(LIBSH) obj/lib/lfs-test: obj/lib/lfs-test.o $(LIBSH) -obj/lib/regex-test: obj/lib/regex-test.o $(LIBSH) obj/lib/hash-test: obj/lib/hash-test.o $(LIBSH) obj/lib/str-test: obj/lib/str-test.o $(LIBSH) obj/lib/asort-test: obj/lib/asort-test.o $(LIBSH) diff --git a/lib/regex-test.c b/lib/regex-test.c deleted file mode 100644 index dc756905..00000000 --- a/lib/regex-test.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Sherlock Library -- Regular Expressions Test - * - * (c) 2001 Robert Spalek - */ - -#include "lib/lib.h" - -#include - -#define PREPARE(patt, icase) r = rx_compile(patt, icase); printf("\npattern: %s, icase=%d\n", patt, icase) -#define TEST(txt, should) printf(txt ": %d (should %d)\n", rx_match(r, txt), should) - -int -main(void) -{ - regex *r; - - PREPARE("a.*b.*c", 0); - TEST("abc", 1); - TEST("ajkhkbbbbbc", 1); - TEST("Aabc", 0); - rx_free(r); - - PREPARE("a.*b.*c", 1); - TEST("aBc", 1); - TEST("ajkhkbBBBBC", 1); - TEST("Aabc", 1); - rx_free(r); - - PREPARE("(ahoj|nebo)", 1); - TEST("Ahoj", 1); - TEST("nEBo", 1); - TEST("ahoja", 0); - TEST("(ahoj|nebo)", 0); - rx_free(r); - - PREPARE("\\(ahoj\\)", 0); - TEST("(ahoj)", 1); - TEST("ahoj", 0); - rx_free(r); - - return 0; -} diff --git a/lib/regex.c b/lib/regex.c index b74fb6a2..43ef8694 100644 --- a/lib/regex.c +++ b/lib/regex.c @@ -312,9 +312,16 @@ rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen) int main(int argc, char **argv) { regex *r; - byte buf1[256], buf2[256]; + byte buf1[4096], buf2[4096]; + int opt_i = 0; - r = rx_compile(argv[1], 0); + if (!strcmp(argv[1], "-i")) + { + opt_i = 1; + argv++; + argc--; + } + r = rx_compile(argv[1], opt_i); while (fgets(buf1, sizeof(buf1), stdin)) { char *p = strchr(buf1, '\n'); diff --git a/lib/regex.t b/lib/regex.t new file mode 100644 index 00000000..02f5d31f --- /dev/null +++ b/lib/regex.t @@ -0,0 +1,49 @@ +# Tests for the regex module + +Run: obj/lib/regex-t 'a.*b.*c' +In: abc + ajkhkbbbbbc + Aabc +Out: MATCH + MATCH + NO MATCH + +Run: obj/lib/regex-t -i 'a.*b.*c' +In: aBc + ajkhkbBBBBC + Aabc +Out: MATCH + MATCH + MATCH + +Run: obj/lib/regex-t -i '(ahoj|nebo)' +In: Ahoj + nEBo + ahoja + (ahoj|nebo) +Out: MATCH + MATCH + NO MATCH + NO MATCH + +Run: obj/lib/regex-t '\(ahoj\)' +In: (ahoj) + ahoj +Out: MATCH + NO MATCH + +Run: obj/lib/regex-t '(.*b)*' +In: ababababab + abababababa +Out: MATCH + NO MATCH + +Run: obj/lib/regex-t '(.*)((aabb)|cc)(b.*)' '\1<\3>\4' +In: aaabbb + aabbccb + abcabc + aaccbb +Out: ab + aabb<>b + NO MATCH + aa<>bb -- 2.39.2