mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 09:10:28 +00:00
![Warner Losh](/assets/img/avatar_default.png)
Changes since the last import: July 27, 2021: As per IEEE Std 1003.1-2008, -F "str" is now consistent with -v FS="str" when str is null. Thanks to Warner Losh. July 24, 2021: Fix readrec's definition of a record. This fixes an issue with NetBSD's RS regular expression support that can cause an infinite read loop. Thanks to Miguel Pineiro Jr. Fix regular expression RS ^-anchoring. RS ^-anchoring needs to know if it is reading the first record of a file. This change restores a missing line that was overlooked when porting NetBSD's RS regex functionality. Thanks to Miguel Pineiro Jr. Fix size computation in replace_repeat() for special case REPEAT_WITH_Q. Thanks to Todd C. Miller. Also, for the first time, import all the tests. Sponsored by: Netflix
341 lines
2.7 KiB
C++
Executable file
341 lines
2.7 KiB
C++
Executable file
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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