xref: /freebsd/lib/libc/regex/grot/tests (revision beea813ee4a5e7d246ae3905184ba08ed853007e)
1# regular expression test set
2# $FreeBSD$
3# Lines are at least three fields, separated by one or more tabs.  "" stands
4# for an empty field.  First field is an RE.  Second field is flags.  If
5# C flag given, regcomp() is expected to fail, and the third field is the
6# error name (minus the leading REG_).
7#
8# Otherwise it is expected to succeed, and the third field is the string to
9# try matching it against.  If there is no fourth field, the match is
10# expected to fail.  If there is a fourth field, it is the substring that
11# the RE is expected to match.  If there is a fifth field, it is a comma-
12# separated list of what the subexpressions should match, with - indicating
13# no match for that one.  In both the fourth and fifth fields, a (sub)field
14# starting with @ indicates that the (sub)expression is expected to match
15# a null string followed by the stuff after the @; this provides a way to
16# test where null strings match.  The character `N' in REs and strings
17# is newline, `S' is space, `T' is tab, `Z' is NUL.
18#
19# The full list of flags:
20#	-	placeholder, does nothing
21#	b	RE is a BRE, not an ERE
22#	&	try it as both an ERE and a BRE
23#	C	regcomp() error expected, third field is error name
24#	i	REG_ICASE
25#	m	("mundane") REG_NOSPEC
26#	s	REG_NOSUB (not really testable)
27#	n	REG_NEWLINE
28#	^	REG_NOTBOL
29#	$	REG_NOTEOL
30#	#	REG_STARTEND (see below)
31#	p	REG_PEND
32#
33# For REG_STARTEND, the start/end offsets are those of the substring
34# enclosed in ().
35
36# basics
37a		&	a	a
38abc		&	abc	abc
39abc|de		-	abc	abc
40a|b|c		-	abc	a
41
42# parentheses and perversions thereof
43a(b)c		-	abc	abc
44a\(b\)c		b	abc	abc
45a(		C	EPAREN
46a(		b	a(	a(
47a\(		-	a(	a(
48a\(		bC	EPAREN
49a\(b		bC	EPAREN
50a(b		C	EPAREN
51a(b		b	a(b	a(b
52# gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
53a)		-	a)	a)
54)		-	)	)
55# end gagging (in a just world, those *should* give EPAREN)
56a)		b	a)	a)
57a\)		bC	EPAREN
58\)		bC	EPAREN
59a()b		-	ab	ab
60a\(\)b		b	ab	ab
61
62# anchoring and REG_NEWLINE
63^abc$		&	abc	abc
64a^b		-	a^b
65a^b		b	a^b	a^b
66a$b		-	a$b
67a$b		b	a$b	a$b
68^		&	abc	@abc
69$		&	abc	@
70^$		&	""	@
71$^		-	""	@
72\($\)\(^\)	b	""	@
73# stop retching, those are legitimate (although disgusting)
74^^		-	""	@
75$$		-	""	@
76b$		&	abNc
77b$		&n	abNc	b
78^b$		&	aNbNc
79^b$		&n	aNbNc	b
80^$		&n	aNNb	@Nb
81^$		n	abc
82^$		n	abcN	@
83$^		n	aNNb	@Nb
84\($\)\(^\)	bn	aNNb	@Nb
85^^		n^	aNNb	@Nb
86$$		n	aNNb	@NN
87^a		^	a
88a$		$	a
89^a		^n	aNb
90^b		^n	aNb	b
91a$		$n	bNa
92b$		$n	bNa	b
93a*(^b$)c*	-	b	b
94a*\(^b$\)c*	b	b	b
95
96# certain syntax errors and non-errors
97|		C	EMPTY
98|		b	|	|
99*		C	BADRPT
100*		b	*	*
101+		C	BADRPT
102?		C	BADRPT
103""		&C	EMPTY
104()		-	abc	@abc
105\(\)		b	abc	@abc
106a||b		C	EMPTY
107|ab		C	EMPTY
108ab|		C	EMPTY
109(|a)b		C	EMPTY
110(a|)b		C	EMPTY
111(*a)		C	BADRPT
112(+a)		C	BADRPT
113(?a)		C	BADRPT
114({1}a)		C	BADRPT
115\(\{1\}a\)	bC	BADRPT
116(a|*b)		C	BADRPT
117(a|+b)		C	BADRPT
118(a|?b)		C	BADRPT
119(a|{1}b)	C	BADRPT
120^*		C	BADRPT
121^*		b	*	*
122^+		C	BADRPT
123^?		C	BADRPT
124^{1}		C	BADRPT
125^\{1\}		bC	BADRPT
126
127# metacharacters, backslashes
128a.c		&	abc	abc
129a[bc]d		&	abd	abd
130a\*c		&	a*c	a*c
131a\\b		&	a\b	a\b
132a\\\*b		&	a\*b	a\*b
133a\bc		&	abc	abc
134a\		&C	EESCAPE
135a\\bc		&	a\bc	a\bc
136\{		bC	BADRPT
137# trailing $ is a peculiar special case for the BRE code
138a$		&	a	a
139a$		&	a$
140a\$		&	a
141a\$		&	a$	a$
142a\\$		&	a
143a\\$		&	a$
144a\\$		&	a\$
145a\\$		&	a\	a\
146
147# back references, ugh
148a\(b\)\2c	bC	ESUBREG
149a\(b\1\)c	bC	ESUBREG
150a\(b*\)c\1d	b	abbcbbd	abbcbbd	bb
151a\(b*\)c\1d	b	abbcbd
152a\(b*\)c\1d	b	abbcbbbd
153^\(.\)\1	b	abc
154a\([bc]\)\1d	b	abcdabbd	abbd	b
155a\(\([bc]\)\2\)*d	b	abbccd	abbccd
156a\(\([bc]\)\2\)*d	b	abbcbd
157# actually, this next one probably ought to fail, but the spec is unclear
158a\(\(b\)*\2\)*d		b	abbbd	abbbd
159# here is a case that no NFA implementation does right
160\(ab*\)[ab]*\1	b	ababaaa	ababaaa	a
161# check out normal matching in the presence of back refs
162\(a\)\1bcd	b	aabcd	aabcd
163\(a\)\1bc*d	b	aabcd	aabcd
164\(a\)\1bc*d	b	aabd	aabd
165\(a\)\1bc*d	b	aabcccd	aabcccd
166\(a\)\1bc*[ce]d	b	aabcccd	aabcccd
167^\(a\)\1b\(c\)*cd$	b	aabcccd	aabcccd
168
169# ordinary repetitions
170ab*c		&	abc	abc
171ab+c		-	abc	abc
172ab?c		-	abc	abc
173a\(*\)b		b	a*b	a*b
174a\(**\)b	b	ab	ab
175a\(***\)b	bC	BADRPT
176*a		b	*a	*a
177**a		b	a	a
178***a		bC	BADRPT
179
180# the dreaded bounded repetitions
181{		&	{	{
182{abc		&	{abc	{abc
183{1		C	BADRPT
184{1}		C	BADRPT
185a{b		&	a{b	a{b
186a{1}b		-	ab	ab
187a\{1\}b		b	ab	ab
188a{1,}b		-	ab	ab
189a\{1,\}b	b	ab	ab
190a{1,2}b		-	aab	aab
191a\{1,2\}b	b	aab	aab
192a{1		C	EBRACE
193a\{1		bC	EBRACE
194a{1a		C	EBRACE
195a\{1a		bC	EBRACE
196a{1a}		C	BADBR
197a\{1a\}		bC	BADBR
198a{,2}		-	a{,2}	a{,2}
199a\{,2\}		bC	BADBR
200a{,}		-	a{,}	a{,}
201a\{,\}		bC	BADBR
202a{1,x}		C	BADBR
203a\{1,x\}	bC	BADBR
204a{1,x		C	EBRACE
205a\{1,x		bC	EBRACE
206a{300}		C	BADBR
207a\{300\}	bC	BADBR
208a{1,0}		C	BADBR
209a\{1,0\}	bC	BADBR
210ab{0,0}c	-	abcac	ac
211ab\{0,0\}c	b	abcac	ac
212ab{0,1}c	-	abcac	abc
213ab\{0,1\}c	b	abcac	abc
214ab{0,3}c	-	abbcac	abbc
215ab\{0,3\}c	b	abbcac	abbc
216ab{1,1}c	-	acabc	abc
217ab\{1,1\}c	b	acabc	abc
218ab{1,3}c	-	acabc	abc
219ab\{1,3\}c	b	acabc	abc
220ab{2,2}c	-	abcabbc	abbc
221ab\{2,2\}c	b	abcabbc	abbc
222ab{2,4}c	-	abcabbc	abbc
223ab\{2,4\}c	b	abcabbc	abbc
224((a{1,10}){1,10}){1,10}	-	a	a	a,a
225((a{1,10}){1,10}){1,10}bb	-	aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb	aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb
226
227# multiple repetitions
228a**		&C	BADRPT
229a++		C	BADRPT
230a??		C	BADRPT
231a*+		C	BADRPT
232a*?		C	BADRPT
233a+*		C	BADRPT
234a+?		C	BADRPT
235a?*		C	BADRPT
236a?+		C	BADRPT
237a{1}{1}		C	BADRPT
238a*{1}		C	BADRPT
239a+{1}		C	BADRPT
240a?{1}		C	BADRPT
241a{1}*		C	BADRPT
242a{1}+		C	BADRPT
243a{1}?		C	BADRPT
244a*{b}		-	a{b}	a{b}
245a\{1\}\{1\}	bC	BADRPT
246a*\{1\}		bC	BADRPT
247a\{1\}*		bC	BADRPT
248
249# brackets, and numerous perversions thereof
250a[b]c		&	abc	abc
251a[ab]c		&	abc	abc
252a[^ab]c		&	adc	adc
253a[]b]c		&	a]c	a]c
254a[[b]c		&	a[c	a[c
255a[-b]c		&	a-c	a-c
256a[^]b]c		&	adc	adc
257a[^-b]c		&	adc	adc
258a[b-]c		&	a-c	a-c
259a[b		&C	EBRACK
260a[]		&C	EBRACK
261a[1-3]c		&	a2c	a2c
262a[3-1]c		&C	ERANGE
263a[1-3-5]c	&C	ERANGE
264a[[.-.]--]c	&	a-c	a-c
265a[1-		&C	ERANGE
266a[[.		&C	EBRACK
267a[[.x		&C	EBRACK
268a[[.x.		&C	EBRACK
269a[[.x.]		&C	EBRACK
270a[[.x.]]	&	ax	ax
271a[[.x,.]]	&C	ECOLLATE
272a[[.one.]]b	&	a1b	a1b
273a[[.notdef.]]b	&C	ECOLLATE
274a[[.].]]b	&	a]b	a]b
275a[[:alpha:]]c	&	abc	abc
276a[[:notdef:]]c	&C	ECTYPE
277a[[:		&C	EBRACK
278a[[:alpha	&C	EBRACK
279a[[:alpha:]	&C	EBRACK
280a[[:alpha,:]	&C	ECTYPE
281a[[:]:]]b	&C	ECTYPE
282a[[:-:]]b	&C	ECTYPE
283a[[:alph:]]	&C	ECTYPE
284a[[:alphabet:]]	&C	ECTYPE
285[[:alnum:]]+	-	-%@a0X-	a0X
286[[:alpha:]]+	-	-%@aX0-	aX
287[[:blank:]]+	-	aSSTb	SST
288[[:cntrl:]]+	-	aNTb	NT
289[[:digit:]]+	-	a019b	019
290[[:graph:]]+	-	Sa%bS	a%b
291[[:lower:]]+	-	AabC	ab
292[[:print:]]+	-	NaSbN	aSb
293[[:punct:]]+	-	S%-&T	%-&
294[[:space:]]+	-	aSNTb	SNT
295[[:upper:]]+	-	aBCd	BC
296[[:xdigit:]]+	-	p0f3Cq	0f3C
297a[[=b=]]c	&	abc	abc
298a[[=		&C	EBRACK
299a[[=b		&C	EBRACK
300a[[=b=		&C	EBRACK
301a[[=b=]		&C	EBRACK
302a[[=b,=]]	&C	ECOLLATE
303a[[=one=]]b	&	a1b	a1b
304
305# complexities
306a(((b)))c	-	abc	abc
307a(b|(c))d	-	abd	abd
308a(b*|c)d	-	abbd	abbd
309# just gotta have one DFA-buster, of course
310a[ab]{20}	-	aaaaabaaaabaaaabaaaab	aaaaabaaaabaaaabaaaab
311# and an inline expansion in case somebody gets tricky
312a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab]	-	aaaaabaaaabaaaabaaaab	aaaaabaaaabaaaabaaaab
313# and in case somebody just slips in an NFA...
314a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night)	-	aaaaabaaaabaaaabaaaabweeknights	aaaaabaaaabaaaabaaaabweeknights
315# fish for anomalies as the number of states passes 32
31612345678901234567890123456789	-	a12345678901234567890123456789b	12345678901234567890123456789
317123456789012345678901234567890	-	a123456789012345678901234567890b	123456789012345678901234567890
3181234567890123456789012345678901	-	a1234567890123456789012345678901b	1234567890123456789012345678901
31912345678901234567890123456789012	-	a12345678901234567890123456789012b	12345678901234567890123456789012
320123456789012345678901234567890123	-	a123456789012345678901234567890123b	123456789012345678901234567890123
321# and one really big one, beyond any plausible word width
3221234567890123456789012345678901234567890123456789012345678901234567890	-	a1234567890123456789012345678901234567890123456789012345678901234567890b	1234567890123456789012345678901234567890123456789012345678901234567890
323# fish for problems as brackets go past 8
324[ab][cd][ef][gh][ij][kl][mn]	-	xacegikmoq	acegikm
325[ab][cd][ef][gh][ij][kl][mn][op]	-	xacegikmoq	acegikmo
326[ab][cd][ef][gh][ij][kl][mn][op][qr]	-	xacegikmoqy	acegikmoq
327[ab][cd][ef][gh][ij][kl][mn][op][q]	-	xacegikmoqy	acegikmoq
328
329# subtleties of matching
330abc		&	xabcy	abc
331a\(b\)?c\1d	b	acd
332aBc		i	Abc	Abc
333a[Bc]*d		i	abBCcd	abBCcd
3340[[:upper:]]1	&i	0a1	0a1
3350[[:lower:]]1	&i	0A1	0A1
336a[^b]c		&i	abc
337a[^b]c		&i	aBc
338a[^b]c		&i	adc	adc
339[a]b[c]		-	abc	abc
340[a]b[a]		-	aba	aba
341[abc]b[abc]	-	abc	abc
342[abc]b[abd]	-	abd	abd
343a(b?c)+d	-	accd	accd
344(wee|week)(knights|night)	-	weeknights	weeknights
345(we|wee|week|frob)(knights|night|day)	-	weeknights	weeknights
346a[bc]d		-	xyzaaabcaababdacd	abd
347a[ab]c		-	aaabc	abc
348abc		s	abc	abc
349
350# subexpressions
351a(b)(c)d	-	abcd	abcd	b,c
352a(((b)))c	-	abc	abc	b,b,b
353a(b|(c))d	-	abd	abd	b,-
354a(b*|c|e)d	-	abbd	abbd	bb
355a(b*|c|e)d	-	acd	acd	c
356a(b*|c|e)d	-	ad	ad	@d
357a(b?)c		-	abc	abc	b
358a(b?)c		-	ac	ac	@c
359a(b+)c		-	abc	abc	b
360a(b+)c		-	abbbc	abbbc	bbb
361a(b*)c		-	ac	ac	@c
362(a|ab)(bc([de]+)f|cde)	-	abcdef	abcdef	a,bcdef,de
363# the regression tester only asks for 9 subexpressions
364a(b)(c)(d)(e)(f)(g)(h)(i)(j)k	-	abcdefghijk	abcdefghijk	b,c,d,e,f,g,h,i,j
365a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l	-	abcdefghijkl	abcdefghijkl	b,c,d,e,f,g,h,i,j,k
366a([bc]?)c	-	abc	abc	b
367a([bc]?)c	-	ac	ac	@c
368a([bc]+)c	-	abc	abc	b
369a([bc]+)c	-	abcc	abcc	bc
370a([bc]+)bc	-	abcbc	abcbc	bc
371a(bb+|b)b	-	abb	abb	b
372a(bbb+|bb+|b)b	-	abb	abb	b
373a(bbb+|bb+|b)b	-	abbb	abbb	bb
374a(bbb+|bb+|b)bb	-	abbb	abbb	b
375(.*).*		-	abcdef	abcdef	abcdef
376(a*)*		-	bc	@b	@b
377
378# do we get the right subexpression when it is used more than once?
379a(b|c)*d	-	ad	ad	-
380a(b|c)*d	-	abcd	abcd	c
381a(b|c)+d	-	abd	abd	b
382a(b|c)+d	-	abcd	abcd	c
383a(b|c?)+d	-	ad	ad	@d
384a(b|c?)+d	-	abcd	abcd	@d
385a(b|c){0,0}d	-	ad	ad	-
386a(b|c){0,1}d	-	ad	ad	-
387a(b|c){0,1}d	-	abd	abd	b
388a(b|c){0,2}d	-	ad	ad	-
389a(b|c){0,2}d	-	abcd	abcd	c
390a(b|c){0,}d	-	ad	ad	-
391a(b|c){0,}d	-	abcd	abcd	c
392a(b|c){1,1}d	-	abd	abd	b
393a(b|c){1,1}d	-	acd	acd	c
394a(b|c){1,2}d	-	abd	abd	b
395a(b|c){1,2}d	-	abcd	abcd	c
396a(b|c){1,}d	-	abd	abd	b
397a(b|c){1,}d	-	abcd	abcd	c
398a(b|c){2,2}d	-	acbd	acbd	b
399a(b|c){2,2}d	-	abcd	abcd	c
400a(b|c){2,4}d	-	abcd	abcd	c
401a(b|c){2,4}d	-	abcbd	abcbd	b
402a(b|c){2,4}d	-	abcbcd	abcbcd	c
403a(b|c){2,}d	-	abcd	abcd	c
404a(b|c){2,}d	-	abcbd	abcbd	b
405a(b+|((c)*))+d	-	abd	abd	@d,@d,-
406a(b+|((c)*))+d	-	abcd	abcd	@d,@d,-
407
408# check out the STARTEND option
409[abc]		&#	a(b)c	b
410[abc]		&#	a(d)c
411[abc]		&#	a(bc)d	b
412[abc]		&#	a(dc)d	c
413.		&#	a()c
414b.*c		&#	b(bc)c	bc
415b.*		&#	b(bc)c	bc
416.*c		&#	b(bc)c	bc
417
418# plain strings, with the NOSPEC flag
419abc		m	abc	abc
420abc		m	xabcy	abc
421abc		m	xyz
422a*b		m	aba*b	a*b
423a*b		m	ab
424""		mC	EMPTY
425
426# cases involving NULs
427aZb		&	a	a
428aZb		&p	a
429aZb		&p#	(aZb)	aZb
430aZ*b		&p#	(ab)	ab
431a.b		&#	(aZb)	aZb
432a.*		&#	(aZb)c	aZb
433
434# word boundaries (ick)
435[[:<:]]a	&	a	a
436[[:<:]]a	&	ba
437[[:<:]]a	&	-a	a
438a[[:>:]]	&	a	a
439a[[:>:]]	&	ab
440a[[:>:]]	&	a-	a
441[[:<:]]a.c[[:>:]]	&	axcd-dayc-dazce-abc	abc
442[[:<:]]a.c[[:>:]]	&	axcd-dayc-dazce-abc-q	abc
443[[:<:]]a.c[[:>:]]	&	axc-dayc-dazce-abc	axc
444
445# past problems
446(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A])	-	A1	A1
447abcdefghijklmnop	i	abcdefghijklmnop	abcdefghijklmnop
448abcdefghijklmnopqrstuv	i	abcdefghijklmnopqrstuv	abcdefghijklmnopqrstuv
449(ALAK)|(ALT[AB])|(CC[123]1)|(CM[123]1)|(GAMC)|(LC[23][EO ])|(SEM[1234])|(SL[ES][12])|(SLWW)|(SLF )|(SLDT)|(VWH[12])|(WH[34][EW])|(WP1[ESN])	-	CC11	CC11
450CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a	-	CC11	CC11
451