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