1*9a7741deSElliott Hughesecho T.re: tests of regular expression code 2*9a7741deSElliott Hughes 3*9a7741deSElliott Hughesawk ' 4*9a7741deSElliott HughesBEGIN { 5*9a7741deSElliott Hughes FS = "\t" 6*9a7741deSElliott Hughes awk = "../a.out" 7*9a7741deSElliott Hughes} 8*9a7741deSElliott HughesNF == 0 { 9*9a7741deSElliott Hughes next 10*9a7741deSElliott Hughes} 11*9a7741deSElliott Hughes$1 != "" { # new test 12*9a7741deSElliott Hughes re = $1 13*9a7741deSElliott Hughes} 14*9a7741deSElliott Hughes$2 != "" { # either ~ or !~ 15*9a7741deSElliott Hughes op = $2 16*9a7741deSElliott Hughes if (op == "~") 17*9a7741deSElliott Hughes neg = "!" 18*9a7741deSElliott Hughes else if (op == "!~") 19*9a7741deSElliott Hughes neg = "" 20*9a7741deSElliott Hughes} 21*9a7741deSElliott Hughes$3 != "" { # new test string 22*9a7741deSElliott Hughes str = $3 23*9a7741deSElliott Hughes} 24*9a7741deSElliott Hughes$3 == "\"\"" { # explicit empty line 25*9a7741deSElliott Hughes $3 = "" 26*9a7741deSElliott Hughes} 27*9a7741deSElliott HughesNF > 2 { # generate a test 28*9a7741deSElliott Hughes input = $3 29*9a7741deSElliott Hughes test = sprintf("./echo '"'"'%s'"'"' | %s '"'"'%s/%s/ {print \"%d fails %s %s %s\"}'"'"'", 30*9a7741deSElliott Hughes input, awk, neg, re, NR, re, op, input) 31*9a7741deSElliott Hughes # printf(" %3d %s %s %s:\n", NR, re, op, input) 32*9a7741deSElliott Hughes # print "test is |" test "|" 33*9a7741deSElliott Hughes system(test) 34*9a7741deSElliott Hughes # system("bprint -c ../a.out") 35*9a7741deSElliott Hughes nt++ 36*9a7741deSElliott Hughes} 37*9a7741deSElliott HughesEND { print " " nt, "tests" } 38*9a7741deSElliott Hughes' <<\!!!! 39*9a7741deSElliott Hughes ~ a 40*9a7741deSElliott Hughes aa 41*9a7741deSElliott Hughes aaa 42*9a7741deSElliott Hughes "" 43*9a7741deSElliott Hughesa ~ a 44*9a7741deSElliott Hughes ba 45*9a7741deSElliott Hughes bab 46*9a7741deSElliott Hughes !~ "" 47*9a7741deSElliott Hughes x 48*9a7741deSElliott Hughes xxxxx 49*9a7741deSElliott Hughes= ~ = 50*9a7741deSElliott Hughes b= 51*9a7741deSElliott Hughes b=b 52*9a7741deSElliott Hughes !~ "" 53*9a7741deSElliott Hughes x 54*9a7741deSElliott Hughes xxxxx 55*9a7741deSElliott Hughes. ~ x 56*9a7741deSElliott Hughes xxx 57*9a7741deSElliott Hughes !~ "" 58*9a7741deSElliott Hughes.a ~ xa 59*9a7741deSElliott Hughes xxa 60*9a7741deSElliott Hughes xax 61*9a7741deSElliott Hughes !~ a 62*9a7741deSElliott Hughes ax 63*9a7741deSElliott Hughes "" 64*9a7741deSElliott Hughes$ ~ x 65*9a7741deSElliott Hughes "" 66*9a7741deSElliott Hughes.$ ~ x 67*9a7741deSElliott Hughes xx 68*9a7741deSElliott Hughes !~ "" 69*9a7741deSElliott Hughesa$ ~ a 70*9a7741deSElliott Hughes ba 71*9a7741deSElliott Hughes bbba 72*9a7741deSElliott Hughes !~ ab 73*9a7741deSElliott Hughes x 74*9a7741deSElliott Hughes "" 75*9a7741deSElliott Hughes^ ~ x 76*9a7741deSElliott Hughes "" 77*9a7741deSElliott Hughes ^ 78*9a7741deSElliott Hughes^a$ ~ a 79*9a7741deSElliott Hughes !~ xa 80*9a7741deSElliott Hughes ax 81*9a7741deSElliott Hughes xax 82*9a7741deSElliott Hughes "" 83*9a7741deSElliott Hughes^a.$ ~ ax 84*9a7741deSElliott Hughes aa 85*9a7741deSElliott Hughes !~ xa 86*9a7741deSElliott Hughes aaa 87*9a7741deSElliott Hughes axy 88*9a7741deSElliott Hughes "" 89*9a7741deSElliott Hughes^$ ~ "" 90*9a7741deSElliott Hughes !~ x 91*9a7741deSElliott Hughes ^ 92*9a7741deSElliott Hughes^.a ~ xa 93*9a7741deSElliott Hughes xaa 94*9a7741deSElliott Hughes !~ a 95*9a7741deSElliott Hughes "" 96*9a7741deSElliott Hughes^.*a ~ a 97*9a7741deSElliott Hughes xa 98*9a7741deSElliott Hughes xxxxxxa 99*9a7741deSElliott Hughes !~ "" 100*9a7741deSElliott Hughes^.+a ~ xa 101*9a7741deSElliott Hughes xxxxxxa 102*9a7741deSElliott Hughes !~ "" 103*9a7741deSElliott Hughes a 104*9a7741deSElliott Hughes ax 105*9a7741deSElliott Hughesa* ~ "" 106*9a7741deSElliott Hughes a 107*9a7741deSElliott Hughes aaaa 108*9a7741deSElliott Hughes xa 109*9a7741deSElliott Hughes xxxx 110*9a7741deSElliott Hughesaa* ~ a 111*9a7741deSElliott Hughes aaa 112*9a7741deSElliott Hughes xa 113*9a7741deSElliott Hughes !~ xxxx 114*9a7741deSElliott Hughes "" 115*9a7741deSElliott Hughes\$ ~ x$ 116*9a7741deSElliott Hughes $ 117*9a7741deSElliott Hughes $x 118*9a7741deSElliott Hughes x$x 119*9a7741deSElliott Hughes !~ "" 120*9a7741deSElliott Hughes x 121*9a7741deSElliott Hughes\. ~ . 122*9a7741deSElliott Hughes !~ x 123*9a7741deSElliott Hughes "" 124*9a7741deSElliott Hughesxr+y ~ xry 125*9a7741deSElliott Hughes xrry 126*9a7741deSElliott Hughes xrrrrrry 127*9a7741deSElliott Hughes !~ ry 128*9a7741deSElliott Hughes xy 129*9a7741deSElliott Hughes xr 130*9a7741deSElliott Hughesxr?y ~ xy 131*9a7741deSElliott Hughes xry 132*9a7741deSElliott Hughes !~ xrry 133*9a7741deSElliott Hughesa?b?c? ~ "" 134*9a7741deSElliott Hughes x 135*9a7741deSElliott Hughes^a?b?x ~ x 136*9a7741deSElliott Hughes ax 137*9a7741deSElliott Hughes bx 138*9a7741deSElliott Hughes abx 139*9a7741deSElliott Hughes xa 140*9a7741deSElliott Hughes !~ "" 141*9a7741deSElliott Hughes ab 142*9a7741deSElliott Hughes aba 143*9a7741deSElliott Hughes[0-9] ~ 1 144*9a7741deSElliott Hughes 567 145*9a7741deSElliott Hughes x0y 146*9a7741deSElliott Hughes !~ abc 147*9a7741deSElliott Hughes "" 148*9a7741deSElliott Hughes[^0-9] !~ 1 149*9a7741deSElliott Hughes 567 150*9a7741deSElliott Hughes "" 151*9a7741deSElliott Hughes ~ abc 152*9a7741deSElliott Hughes x0y 153*9a7741deSElliott Hughes[0-25-69] ~ 0 154*9a7741deSElliott Hughes 1 155*9a7741deSElliott Hughes 2 156*9a7741deSElliott Hughes 5 157*9a7741deSElliott Hughes 6 158*9a7741deSElliott Hughes 9 159*9a7741deSElliott Hughes !~ 3 160*9a7741deSElliott Hughes 4 161*9a7741deSElliott Hughes 7 162*9a7741deSElliott Hughes 8 163*9a7741deSElliott Hughes[[:lower:]] ~ a 164*9a7741deSElliott Hughes b 165*9a7741deSElliott Hughes z 166*9a7741deSElliott Hughes !~ A 167*9a7741deSElliott Hughes Z 168*9a7741deSElliott Hughes 1 169*9a7741deSElliott Hughes : 170*9a7741deSElliott Hughes [ 171*9a7741deSElliott Hughes ] 172*9a7741deSElliott Hughes[[:upper:]] ~ A 173*9a7741deSElliott Hughes B 174*9a7741deSElliott Hughes Z 175*9a7741deSElliott Hughes !~ a 176*9a7741deSElliott Hughes z 177*9a7741deSElliott Hughes 1 178*9a7741deSElliott Hughes : 179*9a7741deSElliott Hughes [ 180*9a7741deSElliott Hughes ] 181*9a7741deSElliott Hughes[[:digit:]] ~ 0 182*9a7741deSElliott Hughes 1 183*9a7741deSElliott Hughes 9 184*9a7741deSElliott Hughes !~ d 185*9a7741deSElliott Hughes : 186*9a7741deSElliott Hughes [ 187*9a7741deSElliott Hughes ] 188*9a7741deSElliott Hughesx[0-9]+y ~ x0y 189*9a7741deSElliott Hughes x23y 190*9a7741deSElliott Hughes x12345y 191*9a7741deSElliott Hughes !~ 0y 192*9a7741deSElliott Hughes xy 193*9a7741deSElliott Hughesx[0-9]?y ~ xy 194*9a7741deSElliott Hughes x1y 195*9a7741deSElliott Hughes !~ x23y 196*9a7741deSElliott Hughesx[[]y ~ x[y 197*9a7741deSElliott Hughes !~ xy 198*9a7741deSElliott Hughes x[[]y 199*9a7741deSElliott Hughes x]y 200*9a7741deSElliott Hughesx[[-]y ~ x[y 201*9a7741deSElliott Hughes x-y 202*9a7741deSElliott Hughes !~ xy 203*9a7741deSElliott Hughes x[[]y 204*9a7741deSElliott Hughes x]y 205*9a7741deSElliott Hughesx[[-a]y ~ x[y 206*9a7741deSElliott Hughes xay 207*9a7741deSElliott Hughes x]y 208*9a7741deSElliott Hughes !~ xy 209*9a7741deSElliott Hughes x[[]y 210*9a7741deSElliott Hughes x-y 211*9a7741deSElliott Hughesx[]-a]y ~ x]y 212*9a7741deSElliott Hughes xay 213*9a7741deSElliott Hughes !~ xy 214*9a7741deSElliott Hughes x[y 215*9a7741deSElliott Hughes x-y 216*9a7741deSElliott Hughesx[]]y ~ x]y 217*9a7741deSElliott Hughes !~ xy 218*9a7741deSElliott Hughes x[]]y 219*9a7741deSElliott Hughes x[y 220*9a7741deSElliott Hughesx[^[]y ~ xay 221*9a7741deSElliott Hughes !~ x[y 222*9a7741deSElliott Hughesx[-]y ~ x-y 223*9a7741deSElliott Hughes !~ xy 224*9a7741deSElliott Hughes x+y 225*9a7741deSElliott Hughesx[^-]y ~ x+y 226*9a7741deSElliott Hughes !~ x-y 227*9a7741deSElliott Hughes xy 228*9a7741deSElliott Hughesx[][]y ~ x[y 229*9a7741deSElliott Hughes x]y 230*9a7741deSElliott Hughes !~ xy 231*9a7741deSElliott Hughes x][y 232*9a7741deSElliott Hughes x[]y 233*9a7741deSElliott Hughesx[z-a]y ~ xy 234*9a7741deSElliott Hughes !~ x 235*9a7741deSElliott Hughes y 236*9a7741deSElliott Hughes xay 237*9a7741deSElliott Hughes xzy 238*9a7741deSElliott Hughes x-y 239*9a7741deSElliott Hughes[0\-9] ~ 0 240*9a7741deSElliott Hughes - 241*9a7741deSElliott Hughes 9 242*9a7741deSElliott Hughes !~ 1 243*9a7741deSElliott Hughes "" 244*9a7741deSElliott Hughes[-1] ~ - 245*9a7741deSElliott Hughes 1 246*9a7741deSElliott Hughes !~ 0 247*9a7741deSElliott Hughes[0-] ~ 0 248*9a7741deSElliott Hughes - 249*9a7741deSElliott Hughes !~ 1 250*9a7741deSElliott Hughes[^-0] ~ x 251*9a7741deSElliott Hughes ^ 252*9a7741deSElliott Hughes !~ - 253*9a7741deSElliott Hughes 0 254*9a7741deSElliott Hughes "" 255*9a7741deSElliott Hughes[^0-] ~ x 256*9a7741deSElliott Hughes ^ 257*9a7741deSElliott Hughes !~ - 258*9a7741deSElliott Hughes 0 259*9a7741deSElliott Hughes "" 260*9a7741deSElliott Hughesx|y ~ x 261*9a7741deSElliott Hughes y 262*9a7741deSElliott Hughes xy 263*9a7741deSElliott Hughes !~ a 264*9a7741deSElliott Hughes "" 265*9a7741deSElliott Hughes^abc|xyz$ ~ abc 266*9a7741deSElliott Hughes abcd 267*9a7741deSElliott Hughes axyz 268*9a7741deSElliott Hughes xyz 269*9a7741deSElliott Hughes !~ xabc 270*9a7741deSElliott Hughes xyza 271*9a7741deSElliott Hughes^(abc|xyz)$ ~ abc 272*9a7741deSElliott Hughes xyz 273*9a7741deSElliott Hughes !~ abcxyz 274*9a7741deSElliott Hughes abcx 275*9a7741deSElliott Hughes cxyz 276*9a7741deSElliott Hughes^x\|y$ ~ x|y 277*9a7741deSElliott Hughes !~ xy 278*9a7741deSElliott Hughes^x\\y$ ~ x\y 279*9a7741deSElliott Hughes !~ xy 280*9a7741deSElliott Hughes x\\y 281*9a7741deSElliott Hughes xay 282*9a7741deSElliott Hughes\141\142 ~ ab 283*9a7741deSElliott Hughes xab 284*9a7741deSElliott Hughes abx 285*9a7741deSElliott Hughes !~ a 286*9a7741deSElliott Hughes b 287*9a7741deSElliott Hughes ax 288*9a7741deSElliott Hughes axb 289*9a7741deSElliott Hughesx\056y ~ x.y 290*9a7741deSElliott Hughes !~ x. 291*9a7741deSElliott Hughes .x 292*9a7741deSElliott Hughes xxx 293*9a7741deSElliott Hughes xby because \056 is not the metacharacter . 294*9a7741deSElliott Hughes xcy ditto 295*9a7741deSElliott Hughes[\60-\62\65-6\71] ~ 0 296*9a7741deSElliott Hughes 1 297*9a7741deSElliott Hughes 2 298*9a7741deSElliott Hughes 5 299*9a7741deSElliott Hughes 6 300*9a7741deSElliott Hughes 9 301*9a7741deSElliott Hughes !~ 3 302*9a7741deSElliott Hughes 4 303*9a7741deSElliott Hughes 7 304*9a7741deSElliott Hughes 8 305*9a7741deSElliott Hughes[\60-2\65-6\71] ~ 0 306*9a7741deSElliott Hughes 1 307*9a7741deSElliott Hughes 2 308*9a7741deSElliott Hughes 5 309*9a7741deSElliott Hughes 6 310*9a7741deSElliott Hughes 9 311*9a7741deSElliott Hughes !~ 3 312*9a7741deSElliott Hughes 4 313*9a7741deSElliott Hughes 7 314*9a7741deSElliott Hughes 8 315*9a7741deSElliott Hughes[\x30-\x32\x35-6\71] ~ 0 316*9a7741deSElliott Hughes 1 317*9a7741deSElliott Hughes 2 318*9a7741deSElliott Hughes 5 319*9a7741deSElliott Hughes 6 320*9a7741deSElliott Hughes 9 321*9a7741deSElliott Hughes !~ 3 322*9a7741deSElliott Hughes 4 323*9a7741deSElliott Hughes 7 324*9a7741deSElliott Hughes 8 325*9a7741deSElliott Hughes[\x30-2\x35-6\x39] ~ 0 326*9a7741deSElliott Hughes 1 327*9a7741deSElliott Hughes 2 328*9a7741deSElliott Hughes 5 329*9a7741deSElliott Hughes 6 330*9a7741deSElliott Hughes 9 331*9a7741deSElliott Hughes !~ 3 332*9a7741deSElliott Hughes 4 333*9a7741deSElliott Hughes 7 334*9a7741deSElliott Hughes 8 335*9a7741deSElliott Hughes\f !~ x 336*9a7741deSElliott Hughes\b !~ x 337*9a7741deSElliott Hughes\r !~ x 338*9a7741deSElliott Hughes\n !~ x 339*9a7741deSElliott Hughes...) ~ abc) 340*9a7741deSElliott Hughes!!!! 341