echo T.re: tests of regular expression code
awk '
BEGIN {
FS = "\t"
awk = "../a.out"
}
NF == 0 {
next
}
$1 != "" { # new test
re = $1
}
$2 != "" { # either ~ or !~
op = $2
if (op == "~")
neg = "!"
else if (op == "!~")
neg = ""
}
$3 != "" { # new test string
str = $3
}
$3 == "\"\"" { # explicit empty line
$3 = ""
}
NF > 2 { # generate a test
input = $3
test = sprintf("./echo '"'"'%s'"'"' | %s '"'"'%s/%s/ {print \"%d fails %s %s %s\"}'"'"'",
input, awk, neg, re, NR, re, op, input)
# printf(" %3d %s %s %s:\n", NR, re, op, input)
# print "test is |" test "|"
system(test)
# system("bprint -c ../a.out")
nt++
}
END { print " " nt, "tests" }
' <<\!!!!
~ a
aa
aaa
""
a ~ a
ba
bab
!~ ""
x
xxxxx
= ~ =
b=
b=b
!~ ""
x
xxxxx
. ~ x
xxx
!~ ""
.a ~ xa
xxa
xax
!~ a
ax
""
$ ~ x
""
.$ ~ x
xx
!~ ""
a$ ~ a
ba
bbba
!~ ab
x
""
^ ~ x
""
^
^a$ ~ a
!~ xa
ax
xax
""
^a.$ ~ ax
aa
!~ xa
aaa
axy
""
^$ ~ ""
!~ x
^
^.a ~ xa
xaa
!~ a
""
^.*a ~ a
xa
xxxxxxa
!~ ""
^.+a ~ xa
xxxxxxa
!~ ""
a
ax
a* ~ ""
a
aaaa
xa
xxxx
aa* ~ a
aaa
xa
!~ xxxx
""
\$ ~ x$
$
$x
x$x
!~ ""
x
\. ~ .
!~ x
""
xr+y ~ xry
xrry
xrrrrrry
!~ ry
xy
xr
xr?y ~ xy
xry
!~ xrry
a?b?c? ~ ""
x
^a?b?x ~ x
ax
bx
abx
xa
!~ ""
ab
aba
[0-9] ~ 1
567
x0y
!~ abc
""
[^0-9] !~ 1
567
""
~ abc
x0y
[0-25-69] ~ 0
1
2
5
6
9
!~ 3
4
7
8
[[:lower:]] ~ a
b
z
!~ A
Z
1
:
[
]
[[:upper:]] ~ A
B
Z
!~ a
z
1
:
[
]
[[:digit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