1e6d6c18Cody Peter Mello#!/bin/bash
2e6d6c18Cody Peter Mello
3e6d6c18Cody Peter Melloif [[ -z "$AWK" ]]; then
4e6d6c18Cody Peter Mello    printf '$AWK must be set\n' >&2
5e6d6c18Cody Peter Mello    exit 1
6e6d6c18Cody Peter Mellofi
7e6d6c18Cody Peter Mello
8e6d6c18Cody Peter Melloecho T.re: tests of regular expression code
9e6d6c18Cody Peter Mello
10e6d6c18Cody Peter Mello$AWK '
11e6d6c18Cody Peter MelloBEGIN {
12e6d6c18Cody Peter Mello	FS = "\t"
13e6d6c18Cody Peter Mello	awk = ENVIRON["AWK"]
14e6d6c18Cody Peter Mello}
15e6d6c18Cody Peter MelloNF == 0 {
16e6d6c18Cody Peter Mello	next
17e6d6c18Cody Peter Mello}
18e6d6c18Cody Peter Mello$1 != "" {	# new test
19e6d6c18Cody Peter Mello	re = $1
20e6d6c18Cody Peter Mello}
21e6d6c18Cody Peter Mello$2 != "" {	# either ~ or !~
22e6d6c18Cody Peter Mello	op = $2
23e6d6c18Cody Peter Mello	if (op == "~")
24e6d6c18Cody Peter Mello		neg = "!"
25e6d6c18Cody Peter Mello	else if (op == "!~")
26e6d6c18Cody Peter Mello		neg = ""
27e6d6c18Cody Peter Mello}
28e6d6c18Cody Peter Mello$3 != "" {	# new test string
29e6d6c18Cody Peter Mello	str = $3
30e6d6c18Cody Peter Mello}
31e6d6c18Cody Peter Mello$3 == "\"\"" {	# explicit empty line
32e6d6c18Cody Peter Mello	$3 = ""
33e6d6c18Cody Peter Mello}
34e6d6c18Cody Peter MelloNF > 2 {	# generate a test
35e6d6c18Cody Peter Mello	input = $3
36e6d6c18Cody Peter Mello	test = sprintf("printf %%s\\\\n '"'"'%s'"'"' | %s '"'"'%s/%s/ {print \"%d fails %s %s %s\"; exit 1}'"'"'",
37e6d6c18Cody Peter Mello		input, awk, neg, re, NR, re, op, input)
38e6d6c18Cody Peter Mello	# printf(" %3d   %s %s %s:\n", NR, re, op, input)
39e6d6c18Cody Peter Mello	# print "test is |" test "|"
40e6d6c18Cody Peter Mello	tcode = system(test)
41e6d6c18Cody Peter Mello	if (tcode > 0) {
42e6d6c18Cody Peter Mello		ecode = 1
43e6d6c18Cody Peter Mello	}
44e6d6c18Cody Peter Mello	# system("bprint -c ../a.out")
45e6d6c18Cody Peter Mello	nt++
46e6d6c18Cody Peter Mello}
47e6d6c18Cody Peter MelloEND {
48e6d6c18Cody Peter Mello	print "	" nt, "tests"
49e6d6c18Cody Peter Mello	exit ecode
50e6d6c18Cody Peter Mello}
51e6d6c18Cody Peter Mello' <<\!!!!
523ee4fc2Cody Peter Mello	~	a
533ee4fc2Cody Peter Mello		aa
543ee4fc2Cody Peter Mello		aaa
553ee4fc2Cody Peter Mello		""
56e6d6c18Cody Peter Melloa	~	a
57e6d6c18Cody Peter Mello		ba
58e6d6c18Cody Peter Mello		bab
59e6d6c18Cody Peter Mello	!~	""
60e6d6c18Cody Peter Mello		x
61e6d6c18Cody Peter Mello		xxxxx
623ee4fc2Cody Peter Mello=	~	=
633ee4fc2Cody Peter Mello		b=
643ee4fc2Cody Peter Mello		b=b
653ee4fc2Cody Peter Mello	!~	""
663ee4fc2Cody Peter Mello		x
673ee4fc2Cody Peter Mello		xxxxx
68e6d6c18Cody Peter Mello.	~	x
69e6d6c18Cody Peter Mello		xxx
70e6d6c18Cody Peter Mello	!~	""			
71e6d6c18Cody Peter Mello.a	~	xa
72e6d6c18Cody Peter Mello		xxa
73e6d6c18Cody Peter Mello		xax
74e6d6c18Cody Peter Mello	!~	a
75e6d6c18Cody Peter Mello		ax
76e6d6c18Cody Peter Mello		""
77e6d6c18Cody Peter Mello$	~	x
78e6d6c18Cody Peter Mello		""
79e6d6c18Cody Peter Mello.$	~	x
80e6d6c18Cody Peter Mello		xx
81e6d6c18Cody Peter Mello	!~	""
82e6d6c18Cody Peter Melloa$	~	a
83e6d6c18Cody Peter Mello		ba
84e6d6c18Cody Peter Mello		bbba
85e6d6c18Cody Peter Mello	!~	ab
86e6d6c18Cody Peter Mello		x
87e6d6c18Cody Peter Mello		""
88e6d6c18Cody Peter Mello^	~	x
89e6d6c18Cody Peter Mello		""
90e6d6c18Cody Peter Mello		^
91e6d6c18Cody Peter Mello^a$	~	a
92e6d6c18Cody Peter Mello	!~	xa
93e6d6c18Cody Peter Mello		ax
94e6d6c18Cody Peter Mello		xax
95e6d6c18Cody Peter Mello		""
96e6d6c18Cody Peter Mello^a.$	~	ax
97e6d6c18Cody Peter Mello		aa
98e6d6c18Cody Peter Mello	!~	xa
99e6d6c18Cody Peter Mello		aaa
100e6d6c18Cody Peter Mello		axy
101e6d6c18Cody Peter Mello		""
102e6d6c18Cody Peter Mello^$	~	""
103e6d6c18Cody Peter Mello	!~	x
104e6d6c18Cody Peter Mello		^
105e6d6c18Cody Peter Mello^.a	~	xa
106e6d6c18Cody Peter Mello		xaa
107e6d6c18Cody Peter Mello	!~	a
108e6d6c18Cody Peter Mello		""
109e6d6c18Cody Peter Mello^.*a	~	a
110e6d6c18Cody Peter Mello		xa
111e6d6c18Cody Peter Mello		xxxxxxa
112e6d6c18Cody Peter Mello	!~	""
113e6d6c18Cody Peter Mello^.+a	~	xa
114e6d6c18Cody Peter Mello		xxxxxxa
115e6d6c18Cody Peter Mello	!~	""
116e6d6c18Cody Peter Mello		a
117e6d6c18Cody Peter Mello		ax
118e6d6c18Cody Peter Melloa*	~	""
119e6d6c18Cody Peter Mello		a
120e6d6c18Cody Peter Mello		aaaa
121e6d6c18Cody Peter Mello		xa
122e6d6c18Cody Peter Mello		xxxx
123e6d6c18Cody Peter Melloaa*	~	a
124e6d6c18Cody Peter Mello		aaa
125e6d6c18Cody Peter Mello		xa
126e6d6c18Cody Peter Mello	!~	xxxx
127e6d6c18Cody Peter Mello		""
128e6d6c18Cody Peter Mello\$	~	x$
129e6d6c18Cody Peter Mello		$
130e6d6c18Cody Peter Mello		$x
131e6d6c18Cody Peter Mello		x$x
132e6d6c18Cody Peter Mello	!~	""
133e6d6c18Cody Peter Mello		x
134e6d6c18Cody Peter Mello\.	~	.
135e6d6c18Cody Peter Mello	!~	x
136e6d6c18Cody Peter Mello		""
137e6d6c18Cody Peter Melloxr+y	~	xry
138e6d6c18Cody Peter Mello		xrry
139e6d6c18Cody Peter Mello		xrrrrrry
140e6d6c18Cody Peter Mello	!~	ry
141e6d6c18Cody Peter Mello		xy
142e6d6c18Cody Peter Mello		xr
143e6d6c18Cody Peter Melloxr?y	~	xy
144e6d6c18Cody Peter Mello		xry
145e6d6c18Cody Peter Mello	!~	xrry
146e6d6c18Cody Peter Melloa?b?c?	~	""
147e6d6c18Cody Peter Mello		x
148e6d6c18Cody Peter Mello^a?b?x	~	x
149e6d6c18Cody Peter Mello		ax
150e6d6c18Cody Peter Mello		bx
151e6d6c18Cody Peter Mello		abx
152e6d6c18Cody Peter Mello		xa
153e6d6c18Cody Peter Mello	!~	""
154e6d6c18Cody Peter Mello		ab
155e6d6c18Cody Peter Mello		aba			
156e6d6c18Cody Peter Mello[0-9]	~	1
157e6d6c18Cody Peter Mello		567
158e6d6c18Cody Peter Mello		x0y
159e6d6c18Cody Peter Mello	!~	abc
160e6d6c18Cody Peter Mello		""
161e6d6c18Cody Peter Mello[^0-9]	!~	1
162e6d6c18Cody Peter Mello		567
163e6d6c18Cody Peter Mello		""
164e6d6c18Cody Peter Mello	~	abc
165e6d6c18Cody Peter Mello		x0y
166e6d6c18Cody Peter Mello[0-25-69]	~	0
167e6d6c18Cody Peter Mello		1
168e6d6c18Cody Peter Mello		2
169e6d6c18Cody Peter Mello		5
170e6d6c18Cody Peter Mello		6
171e6d6c18Cody Peter Mello		9
172e6d6c18Cody Peter Mello	!~	3
173e6d6c18Cody Peter Mello		4
174e6d6c18Cody Peter Mello		7
175e6d6c18Cody Peter Mello		8
1763ee4fc2Cody Peter Mello[[:lower:]]	~	a
1773ee4fc2Cody Peter Mello		b
1783ee4fc2Cody Peter Mello		z
1793ee4fc2Cody Peter Mello	!~	A
1803ee4fc2Cody Peter Mello		Z
1813ee4fc2Cody Peter Mello		1
1823ee4fc2Cody Peter Mello		:
1833ee4fc2Cody Peter Mello		[
1843ee4fc2Cody Peter Mello		]
1853ee4fc2Cody Peter Mello[[:upper:]]	~	A
1863ee4fc2Cody Peter Mello		B
1873ee4fc2Cody Peter Mello		Z
1883ee4fc2Cody Peter Mello	!~	a
1893ee4fc2Cody Peter Mello		z
1903ee4fc2Cody Peter Mello		1
1913ee4fc2Cody Peter Mello		:
1923ee4fc2Cody Peter Mello		[
1933ee4fc2Cody Peter Mello		]
1943ee4fc2Cody Peter Mello[[:lower:][:upper:]]	~	A
1953ee4fc2Cody Peter Mello		B
1963ee4fc2Cody Peter Mello		Z
1973ee4fc2Cody Peter Mello		a
1983ee4fc2Cody Peter Mello		b
1993ee4fc2Cody Peter Mello		z
2003ee4fc2Cody Peter Mello	!~	1
2013ee4fc2Cody Peter Mello		:
2023ee4fc2Cody Peter Mello		[
2033ee4fc2Cody Peter Mello		]
2043ee4fc2Cody Peter Mello[[:digit:]]	~	0
2053ee4fc2Cody Peter Mello		1
2063ee4fc2Cody Peter Mello		9
2073ee4fc2Cody Peter Mello	!~	d
2083ee4fc2Cody Peter Mello		:
2093ee4fc2Cody Peter Mello		[
2103ee4fc2Cody Peter Mello		]
2113ee4fc2Cody Peter Mello[[:xdigit:]]	~	0
2123ee4fc2Cody Peter Mello		1
2133ee4fc2Cody Peter Mello		9
2143ee4fc2Cody Peter Mello		a
2153ee4fc2Cody Peter Mello		d
2163ee4fc2Cody Peter Mello		f
2173ee4fc2Cody Peter Mello	!~	g
2183ee4fc2Cody Peter Mello		z
2193ee4fc2Cody Peter Mello		:
2203ee4fc2Cody Peter Mello		[
2213ee4fc2Cody Peter Mello		]
2223ee4fc2Cody Peter Mello[[:cntrl:]]	~	
2233ee4fc2Cody Peter Mello		
2243ee4fc2Cody Peter Mello		
2253ee4fc2Cody Peter Mello		
2263ee4fc2Cody Peter Mello	!~	.
2273ee4fc2Cody Peter Mello		Z
2283ee4fc2Cody Peter Mello		G
2293ee4fc2Cody Peter Mello		[
2303ee4fc2Cody Peter Mello		]
2313ee4fc2Cody Peter Mello[[:punct:]]	~	:
2323ee4fc2Cody Peter Mello		,
2333ee4fc2Cody Peter Mello		-
2343ee4fc2Cody Peter Mello		*
2353ee4fc2Cody Peter Mello		@
2363ee4fc2Cody Peter Mello	!~	a
2373ee4fc2Cody Peter Mello		1
2383ee4fc2Cody Peter Mello		U
2393ee4fc2Cody Peter Mello		 
2403ee4fc2Cody Peter Mello		
241e6d6c18Cody Peter Mellox[0-9]+y	~	x0y
242e6d6c18Cody Peter Mello		x23y
243e6d6c18Cody Peter Mello		x12345y
244e6d6c18Cody Peter Mello	!~	0y
245e6d6c18Cody Peter Mello		xy
246e6d6c18Cody Peter Mellox[0-9]?y	~	xy
247e6d6c18Cody Peter Mello		x1y
248e6d6c18Cody Peter Mello	!~	x23y
249e6d6c18Cody Peter Mellox[[]y	~	x[y
250e6d6c18Cody Peter Mello	!~	xy
251e6d6c18Cody Peter Mello		x[[]y
252e6d6c18Cody Peter Mello		x]y
253e6d6c18Cody Peter Mellox[[-]y	~	x[y
254e6d6c18Cody Peter Mello		x-y
255e6d6c18Cody Peter Mello	!~	xy
256e6d6c18Cody Peter Mello		x[[]y
257e6d6c18Cody Peter Mello		x]y
258e6d6c18Cody Peter Mellox[[-a]y	~	x[y
259e6d6c18Cody Peter Mello		xay
260e6d6c18Cody Peter Mello		x]y
261e6d6c18Cody Peter Mello	!~	xy
262e6d6c18Cody Peter Mello		x[[]y
263e6d6c18Cody Peter Mello		x-y
2643ee4fc2Cody Peter Mellox[]-a]y	~	x]y
2653ee4fc2Cody Peter Mello		xay
2663ee4fc2Cody Peter Mello	!~	xy
2673ee4fc2Cody Peter Mello		x[y
2683ee4fc2Cody Peter Mello		x-y
269e6d6c18Cody Peter Mellox[]]y	~	x]y
270e6d6c18Cody Peter Mello	!~	xy
271e6d6c18Cody Peter Mello		x[]]y
272e6d6c18Cody Peter Mello		x[y
273e6d6c18Cody Peter Mellox[^[]y	~	xay
274e6d6c18Cody Peter Mello	!~	x[y
275e6d6c18Cody Peter Mellox[-]y	~	x-y
276e6d6c18Cody Peter Mello	!~	xy
277e6d6c18Cody Peter Mello		x+y
278e6d6c18Cody Peter Mellox[^-]y	~	x+y
279e6d6c18Cody Peter Mello	!~	x-y
280e6d6c18Cody Peter Mello		xy
2813ee4fc2Cody Peter Mellox[][]y	~	x[y
2823ee4fc2Cody Peter Mello		x]y
2833ee4fc2Cody Peter Mello	!~	xy
2843ee4fc2Cody Peter Mello		x][y
2853ee4fc2Cody Peter Mello		x[]y
2863ee4fc2Cody Peter Mellox[z-a]y	~	xy
2873ee4fc2Cody Peter Mello	!~	x
2883ee4fc2Cody Peter Mello		y
2893ee4fc2Cody Peter Mello		xay
2903ee4fc2Cody Peter Mello		xzy
2913ee4fc2Cody Peter Mello		x-y
292e6d6c18Cody Peter Mello[0\-9]	~	0
293e6d6c18Cody Peter Mello		-
294e6d6c18Cody Peter Mello		9
295e6d6c18Cody Peter Mello	!~	1
296e6d6c18Cody Peter Mello		""
297e6d6c18Cody Peter Mello[-1]	~	-
298e6d6c18Cody Peter Mello		1
299e6d6c18Cody Peter Mello	!~	0
300e6d6c18Cody Peter Mello[0-]	~	0
301e6d6c18Cody Peter Mello		-
302e6d6c18Cody Peter Mello	!~	1
303e6d6c18Cody Peter Mello[^-0]	~	x
304e6d6c18Cody Peter Mello		^
305e6d6c18Cody Peter Mello	!~	-
306e6d6c18Cody Peter Mello		0
307e6d6c18Cody Peter Mello		""
308e6d6c18Cody Peter Mello[^0-]	~	x
309e6d6c18Cody Peter Mello		^
310e6d6c18Cody Peter Mello	!~	-
311e6d6c18Cody Peter Mello		0
312e6d6c18Cody Peter Mello		""
313e6d6c18Cody Peter Mellox|y	~	x
314e6d6c18Cody Peter Mello		y
315e6d6c18Cody Peter Mello		xy
316e6d6c18Cody Peter Mello	!~	a
317e6d6c18Cody Peter Mello		""
318e6d6c18Cody Peter Mello^abc|xyz$	~	abc
319e6d6c18Cody Peter Mello		abcd
320e6d6c18Cody Peter Mello		axyz
321e6d6c18Cody Peter Mello		xyz
322e6d6c18Cody Peter Mello	!~	xabc
323e6d6c18Cody Peter Mello		xyza
324e6d6c18Cody Peter Mello^(abc|xyz)$	~	abc
325e6d6c18Cody Peter Mello		xyz
326e6d6c18Cody Peter Mello	!~	abcxyz
327e6d6c18Cody Peter Mello		abcx
328e6d6c18Cody Peter Mello		cxyz
329e6d6c18Cody Peter Mello^x\|y$	~	x|y
330e6d6c18Cody Peter Mello	!~	xy
331e6d6c18Cody Peter Mello^x\\y$	~	x\y
332e6d6c18Cody Peter Mello	!~	xy
333e6d6c18Cody Peter Mello		x\\y
334e6d6c18Cody Peter Mello		xay
335e6d6c18Cody Peter Mello\141\142	~	ab
336e6d6c18Cody Peter Mello		xab
337e6d6c18Cody Peter Mello		abx
338e6d6c18Cody Peter Mello	!~	a
339e6d6c18Cody Peter Mello		b
340e6d6c18Cody Peter Mello		ax
341e6d6c18Cody Peter Mello		axb
342e6d6c18Cody Peter Mellox\056y	~	x.y
343e6d6c18Cody Peter Mello	!~	x.
344e6d6c18Cody Peter Mello		.x
345e6d6c18Cody Peter Mello		xxx
346e6d6c18Cody Peter Mello		xby  because \056 is not the metacharacter .
347e6d6c18Cody Peter Mello		xcy  ditto
348e6d6c18Cody Peter Mello[\60-\62\65-6\71]	~	0
349e6d6c18Cody Peter Mello		1
350e6d6c18Cody Peter Mello		2
351e6d6c18Cody Peter Mello		5
352e6d6c18Cody Peter Mello		6
353e6d6c18Cody Peter Mello		9
3543ee4fc2Cody Peter Mello	!~	3
3553ee4fc2Cody Peter Mello		4
3563ee4fc2Cody Peter Mello		7
3573ee4fc2Cody Peter Mello		8
358e6d6c18Cody Peter Mello[\60-2\65-6\71]	~	0
359e6d6c18Cody Peter Mello		1
360e6d6c18Cody Peter Mello		2
361e6d6c18Cody Peter Mello		5
362e6d6c18Cody Peter Mello		6
363e6d6c18Cody Peter Mello		9
3643ee4fc2Cody Peter Mello	!~	3
3653ee4fc2Cody Peter Mello		4
3663ee4fc2Cody Peter Mello		7
3673ee4fc2Cody Peter Mello		8
368e6d6c18Cody Peter Mello[\x30-\x32\x35-6\71]	~	0
369e6d6c18Cody Peter Mello		1
370e6d6c18Cody Peter Mello		2
371e6d6c18Cody Peter Mello		5
372e6d6c18Cody Peter Mello		6
373e6d6c18Cody Peter Mello		9
3743ee4fc2Cody Peter Mello	!~	3
3753ee4fc2Cody Peter Mello		4
3763ee4fc2Cody Peter Mello		7
3773ee4fc2Cody Peter Mello		8
378e6d6c18Cody Peter Mello[\x30-2\x35-6\x39]	~	0
379e6d6c18Cody Peter Mello		1
380e6d6c18Cody Peter Mello		2
381e6d6c18Cody Peter Mello		5
382e6d6c18Cody Peter Mello		6
383e6d6c18Cody Peter Mello		9
3843ee4fc2Cody Peter Mello	!~	3
3853ee4fc2Cody Peter Mello		4
3863ee4fc2Cody Peter Mello		7
3873ee4fc2Cody Peter Mello		8
388e6d6c18Cody Peter Mello\f	!~	x
389e6d6c18Cody Peter Mello\b	!~	x
390e6d6c18Cody Peter Mello\r	!~	x
391e6d6c18Cody Peter Mello\n	!~	x
392e6d6c18Cody Peter Mello!!!!
393