]> mj.ucw.cz Git - libucw.git/commitdiff
Converted regex module testing to the new test framework.
authorMartin Mares <mj@ucw.cz>
Mon, 15 Mar 2004 22:57:11 +0000 (22:57 +0000)
committerMartin Mares <mj@ucw.cz>
Mon, 15 Mar 2004 22:57:11 +0000 (22:57 +0000)
lib/Makefile
lib/regex-test.c [deleted file]
lib/regex.c
lib/regex.t [new file with mode: 0644]

index 1095da23b06fcd90370e3ab6b7988efc169eab8d..8791d2406b2cb4975bb22dbf472d717241260b9a 100644 (file)
@@ -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 (file)
index dc75690..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *     Sherlock Library -- Regular Expressions Test
- *
- *     (c) 2001 Robert Spalek <robert@ucw.cz>
- */
-
-#include "lib/lib.h"
-
-#include <stdio.h>
-
-#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;
-}
index b74fb6a290f5abdfe6b0fa5b3f70aec4942056f5..43ef8694ac2609a7b653e9253ae1d68e36ef1014 100644 (file)
@@ -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 (file)
index 0000000..02f5d31
--- /dev/null
@@ -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:   a<aabb>b
+       aabb<>b
+       NO MATCH
+       aa<>bb