diff options
Diffstat (limited to 'regtest_terex.sh')
| -rwxr-xr-x | regtest_terex.sh | 108 |
1 files changed, 72 insertions, 36 deletions
diff --git a/regtest_terex.sh b/regtest_terex.sh index ca499d8..29a88c5 100755 --- a/regtest_terex.sh +++ b/regtest_terex.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/local/bin/bash # # Copyright (c) 2002, Stooges & Cueless CO., All rights reserved. # @@ -74,10 +74,6 @@ cat<<-EOF>$rgsrc #include <string.h> #include "regalone.h" #include "regex.h" - #ifdef REGEX_UTF8 - # define re_comp re_ucomp - # define re_exec re_uexec - #endif size_t hexescapes2bin(unsigned char *t, char *src, size_t mxlen) { char *s, *xs; @@ -108,10 +104,11 @@ cat<<-EOF>$rgsrc char buf[1024*2]; //memset(&cre, '\0', sizeof(cre)); - nmatch = atoi(argv[1]); - relen = hexescapes2bin(re, argv[2], sizeof(re)/sizeof(char)); - datlen = hexescapes2bin(dat, argv[3], sizeof(dat)/sizeof(char)); + nmatch = atoi(argv[2]); + relen = hexescapes2bin(re, argv[3], sizeof(re)/sizeof(char)); + datlen = hexescapes2bin(dat, argv[4], sizeof(dat)/sizeof(char)); cflags = REG_ADVANCED | (nmatch ? 0 : REG_NOSUB); + if ( atoi(argv[1]) != 0 ) cflags |= REG_RAW; rc = re_comp(&cre, re, relen, cflags); if ( rc != REG_OKAY ) { @@ -127,7 +124,7 @@ cat<<-EOF>$rgsrc nmatch, cre.re_nsub); return 1; } - rc = re_exec(&cre, dat, datlen, NULL, 100, pmatch, 0); + rc = re_exec(&cre, dat, datlen, NULL, 100, pmatch, cflags & REG_RAW); if ( rc != REG_OKAY ) { regerror(rc, &cre, buf, sizeof(buf)); @@ -143,7 +140,7 @@ cat<<-EOF>$rgsrc sprintf(&buf[strlen(buf)], "%s%.*s", i>1 ? ":" : "", (int)(pmatch[i].rm_eo-pmatch[i].rm_so), - argv[3]+pmatch[i].rm_so); + argv[4]+pmatch[i].rm_so); printf("%s\n", buf); } regfree(&cre); @@ -153,51 +150,73 @@ EOF PATH=.:$PATH LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH export PATH LD_LIBRARY_PATH -# Either this one -#$CC -Wall -g -O0 -I. -I$H/inc -L. -lterex -o $rgbin $rgsrc # Test ascii ch -# Or this one -$CC -Wall -g -O0 -I. -I$H/inc -L. -lteurex -DREGEX_UTF8 -o $rgbin $rgsrc # Test wide ch +$CC -Wall -g -O0 -I. -I$H/inc -L. -lterex -o $rgbin $rgsrc #----------------------------------- -resp=`$rgbin 0 "clavo" "Pablito clavo un clavito" 2>&1` msg="Simple match" +resp=`$rgbin 0 0 "clavo" "Pablito clavo un clavito" 2>&1` test -z "$resp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 0 "clavo" "Pablito clavo un clavito" 2>&1` +test -z "$resp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- -resp=`$rgbin 0 \ +msg="yyyy-mm-dd between 1900-01-01 and 2099-12-31" +resp=`$rgbin 0 0 \ "(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])" \ "1960-10-12" 2>&1` -msg="yyyy-mm-dd between 1900-01-01 and 2099-12-31" test -z "$resp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 0 \ + "(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])" \ + "1960-10-12" 2>&1` +test -z "$resp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- -resp=`$rgbin 0 \ +msg="yyyy-mm-dd out of 1900-01-01 and 2099-12-31" +resp=`$rgbin 0 0 \ "(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])" \ "El arzobispo 1960-14-12 de Constantinopla" 2>&1` -msg="yyyy-mm-dd out of 1900-01-01 and 2099-12-31" if echo "$resp"|grep "failed to match">/dev/null; then f_ok "$msg"; else f_no "$msg" "$resp"; fi +resp=`$rgbin 1 0 \ + "(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])" \ + "El arzobispo 1960-14-12 de Constantinopla" 2>&1` +if echo "$resp"|grep "failed to match">/dev/null; +then f_ok "$msg (raw)"; else f_no "$msg (raw)" "$resp"; fi #----------------------------------- -resp=`$rgbin 0 "^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$" "432" 2>&1` msg="1..999" +resp=`$rgbin 0 0 "^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$" "432" 2>&1` test -z "$resp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 0 "^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$" "432" 2>&1` +test -z "$resp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- -resp=`$rgbin 0 "^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$" " 4321" 2>&1` msg="Bad 1..999" +resp=`$rgbin 0 0 "^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$" " 4321" 2>&1` if echo "$resp"|grep "failed to match">/dev/null; then f_ok "$msg"; else f_no "$msg" "$resp"; fi +resp=`$rgbin 1 0 "^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$" " 4321" 2>&1` +if echo "$resp"|grep "failed to match">/dev/null; +then f_ok "$msg (raw)"; else f_no "$msg (raw)" "$resp"; fi #----------------------------------- -resp=`$rgbin 0 "word1\W+(?:\w+\W+){1,3}?word2" \ - "word1 clavo un clavito word2" 2>&1` msg="Quantifier: One to three words between 'word1' and 'word2'" +resp=`$rgbin 0 0 "word1\W+(?:\w+\W+){1,3}?word2" \ + "word1 clavo un clavito word2" 2>&1` test -z "$resp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 0 "word1\W+(?:\w+\W+){1,3}?word2" \ + "word1 clavo un clavito word2" 2>&1` +test -z "$resp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- -resp=`$rgbin 0 "a?a?a?a?a?aaaaaaaaaaaaaaa" \ - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 2>&1` msg="Pathological: a?^6a^15 against aaaaaaaaaaaaaaaaaa..." +resp=`$rgbin 0 0 "a?a?a?a?a?aaaaaaaaaaaaaaa" \ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 2>&1` test -z "$resp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 0 "a?a?a?a?a?aaaaaaaaaaaaaaa" \ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 2>&1` +test -z "$resp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- -resp=`$rgbin 0 "(a|aa)*b" \ - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" 2>&1` msg="Pathological: (a|aa)*b against aaaaaaaaaaaaaaaaaa...b" +resp=`$rgbin 0 0 "(a|aa)*b" \ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" 2>&1` test -z "$resp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 0 "(a|aa)*b" \ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" 2>&1` +test -z "$resp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- cat<<-EOF>$datsrc #include <stdio.h> @@ -243,9 +262,11 @@ while test $i -lt 5; do test $i -eq 0 && expectedresp=$num || expectedresp=$expectedresp:$num i=`expr $i + 1` done -resp=`$rgbin 5 "$totre" "$totdat" 2>&1` msg="5 group patterns taken with bracket ranges" +resp=`$rgbin 0 5 "$totre" "$totdat" 2>&1` test "$resp" = "$expectedresp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 5 "$totre" "$totdat" 2>&1` +test "$resp" = "$expectedresp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- i=0 totre="[a-zA-Z]+" @@ -258,9 +279,11 @@ while test $i -lt 10; do test $i -eq 0 && expectedresp=$num || expectedresp=$expectedresp:$num i=`expr $i + 1` done -resp=`$rgbin 10 "$totre" "$totdat" 2>&1` msg="10 group patterns taken with bracket ranges" +resp=`$rgbin 0 10 "$totre" "$totdat" 2>&1` test "$resp" = "$expectedresp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 10 "$totre" "$totdat" 2>&1` +test "$resp" = "$expectedresp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- i=0 totre="[a-zA-Z]+" @@ -273,9 +296,11 @@ while test $i -lt 99; do test $i -eq 0 && expectedresp=$num || expectedresp=$expectedresp:$num i=`expr $i + 1` done -resp=`$rgbin 99 "$totre" "$totdat" 2>&1` msg="99 group patterns taken with bracket ranges" +resp=`$rgbin 0 99 "$totre" "$totdat" 2>&1` test "$resp" = "$expectedresp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 99 "$totre" "$totdat" 2>&1` +test "$resp" = "$expectedresp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- i=0 totre="[[:alpha:]]+" @@ -288,24 +313,35 @@ while test $i -lt 99; do test $i -eq 0 && expectedresp=$num || expectedresp=$expectedresp:$num i=`expr $i + 1` done -resp=`$rgbin 99 "$totre" "$totdat" 2>&1` msg="99 group patterns taken with character classes" +resp=`$rgbin 0 99 "$totre" "$totdat" 2>&1` test "$resp" = "$expectedresp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 99 "$totre" "$totdat" 2>&1` +test "$resp" = "$expectedresp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- -resp=`$rgbin 0 "clavo" "Pablito\00clavo un clavito" 2>&1` msg="Binary data" +resp=`$rgbin 0 0 "clavo" $'Pablito\01clavo un clavito' 2>&1` test -z "$resp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 0 "clavo" $'Pablito\01clavo un clavito' 2>&1` +test -z "$resp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- -resp=`$rgbin 0 "cl\xFFavo" "Pablito\x00cl\xFFavo un clavito" 2>&1` msg="Binary RE and data" +resp=`$rgbin 0 0 $'cl\xFFavo' $'Pablito\x01cl\xFFavo un clavito' 2>&1` test -z "$resp" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 0 $'cl\xFFavo' $'Pablito\x01cl\xFFavo un clavito' 2>&1` +test -z "$resp" && f_ok "$msg (raw)" || f_no "$msg (raw)" "$resp" #----------------------------------- -resp=`$rgbin 1 "(?i)(clavo)" "Pablito ClAvO un clavito" 2>&1` msg="One group pattern with case-insensitive matching" +resp=`$rgbin 0 1 "(?i)(clavo)" "Pablito ClAvO un clavito" 2>&1` test "$resp" = "ClAvO" && f_ok "$msg" || f_no "$msg" "$resp" +resp=`$rgbin 1 1 "(?i)(clavo)" "Pablito ClAvO un clavito" 2>&1` +test "$resp" = "ClAvO" && f_ok "$msg (raw)" || f_no "$msg" "$resp (raw)" +#----------------------------------- +resp=`$rgbin 1 1 $'([\x01\x5F\xFF]+)' $'ABC\x5F' 2>&1` +msg="Raw character class" +test "$resp" = $'\x5F' && f_ok "$msg" || f_no "$msg" "$resp" #----------------------------------- -# Will only work if REGEX_UTF8 -resp=`$rgbin 1 '([[:alpha:]]+)' 'абвгд' 2>&1` +resp=`$rgbin 0 1 '([[:alpha:]]+)' 'абвгд' 2>&1` msg="Unicode character class" test "$resp" = "абвгд" && f_ok "$msg" || f_no "$msg" "$resp" #----------------------------------- |
