xref: /freebsd/lib/libc/regex/grot/tests (revision 8ca5c256cb0a0ac117493557f3fc397f68f16759)
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
226# multiple repetitions
227a**		&C	BADRPT
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{1}{1}		C	BADRPT
237a*{1}		C	BADRPT
238a+{1}		C	BADRPT
239a?{1}		C	BADRPT
240a{1}*		C	BADRPT
241a{1}+		C	BADRPT
242a{1}?		C	BADRPT
243a*{b}		-	a{b}	a{b}
244a\{1\}\{1\}	bC	BADRPT
245a*\{1\}		bC	BADRPT
246a\{1\}*		bC	BADRPT
247
248# brackets, and numerous perversions thereof
249a[b]c		&	abc	abc
250a[ab]c		&	abc	abc
251a[^ab]c		&	adc	adc
252a[]b]c		&	a]c	a]c
253a[[b]c		&	a[c	a[c
254a[-b]c		&	a-c	a-c
255a[^]b]c		&	adc	adc
256a[^-b]c		&	adc	adc
257a[b-]c		&	a-c	a-c
258a[b		&C	EBRACK
259a[]		&C	EBRACK
260a[1-3]c		&	a2c	a2c
261a[3-1]c		&C	ERANGE
262a[1-3-5]c	&C	ERANGE
263a[[.-.]--]c	&	a-c	a-c
264a[1-		&C	ERANGE
265a[[.		&C	EBRACK
266a[[.x		&C	EBRACK
267a[[.x.		&C	EBRACK
268a[[.x.]		&C	EBRACK
269a[[.x.]]	&	ax	ax
270a[[.x,.]]	&C	ECOLLATE
271a[[.one.]]b	&	a1b	a1b
272a[[.notdef.]]b	&C	ECOLLATE
273a[[.].]]b	&	a]b	a]b
274a[[:alpha:]]c	&	abc	abc
275a[[:notdef:]]c	&C	ECTYPE
276a[[:		&C	EBRACK
277a[[:alpha	&C	EBRACK
278a[[:alpha:]	&C	EBRACK
279a[[:alpha,:]	&C	ECTYPE
280a[[:]:]]b	&C	ECTYPE
281a[[:-:]]b	&C	ECTYPE
282a[[:alph:]]	&C	ECTYPE
283a[[:alphabet:]]	&C	ECTYPE
284[[:alnum:]]+	-	-%@a0X-	a0X
285[[:alpha:]]+	-	-%@aX0-	aX
286[[:blank:]]+	-	aSSTb	SST
287[[:cntrl:]]+	-	aNTb	NT
288[[:digit:]]+	-	a019b	019
289[[:graph:]]+	-	Sa%bS	a%b
290[[:lower:]]+	-	AabC	ab
291[[:print:]]+	-	NaSbN	aSb
292[[:punct:]]+	-	S%-&T	%-&
293[[:space:]]+	-	aSNTb	SNT
294[[:upper:]]+	-	aBCd	BC
295[[:xdigit:]]+	-	p0f3Cq	0f3C
296a[[=b=]]c	&	abc	abc
297a[[=		&C	EBRACK
298a[[=b		&C	EBRACK
299a[[=b=		&C	EBRACK
300a[[=b=]		&C	EBRACK
301a[[=b,=]]	&C	ECOLLATE
302a[[=one=]]b	&	a1b	a1b
303
304# complexities
305a(((b)))c	-	abc	abc
306a(b|(c))d	-	abd	abd
307a(b*|c)d	-	abbd	abbd
308# just gotta have one DFA-buster, of course
309a[ab]{20}	-	aaaaabaaaabaaaabaaaab	aaaaabaaaabaaaabaaaab
310# and an inline expansion in case somebody gets tricky
311a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab]	-	aaaaabaaaabaaaabaaaab	aaaaabaaaabaaaabaaaab
312# and in case somebody just slips in an NFA...
313a[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
314# fish for anomalies as the number of states passes 32
31512345678901234567890123456789	-	a12345678901234567890123456789b	12345678901234567890123456789
316123456789012345678901234567890	-	a123456789012345678901234567890b	123456789012345678901234567890
3171234567890123456789012345678901	-	a1234567890123456789012345678901b	1234567890123456789012345678901
31812345678901234567890123456789012	-	a12345678901234567890123456789012b	12345678901234567890123456789012
319123456789012345678901234567890123	-	a123456789012345678901234567890123b	123456789012345678901234567890123
320# and one really big one, beyond any plausible word width
3211234567890123456789012345678901234567890123456789012345678901234567890	-	a1234567890123456789012345678901234567890123456789012345678901234567890b	1234567890123456789012345678901234567890123456789012345678901234567890
322# fish for problems as brackets go past 8
323[ab][cd][ef][gh][ij][kl][mn]	-	xacegikmoq	acegikm
324[ab][cd][ef][gh][ij][kl][mn][op]	-	xacegikmoq	acegikmo
325[ab][cd][ef][gh][ij][kl][mn][op][qr]	-	xacegikmoqy	acegikmoq
326[ab][cd][ef][gh][ij][kl][mn][op][q]	-	xacegikmoqy	acegikmoq
327
328# subtleties of matching
329abc		&	xabcy	abc
330a\(b\)?c\1d	b	acd
331aBc		i	Abc	Abc
332a[Bc]*d		i	abBCcd	abBCcd
3330[[:upper:]]1	&i	0a1	0a1
3340[[:lower:]]1	&i	0A1	0A1
335a[^b]c		&i	abc
336a[^b]c		&i	aBc
337a[^b]c		&i	adc	adc
338[a]b[c]		-	abc	abc
339[a]b[a]		-	aba	aba
340[abc]b[abc]	-	abc	abc
341[abc]b[abd]	-	abd	abd
342a(b?c)+d	-	accd	accd
343(wee|week)(knights|night)	-	weeknights	weeknights
344(we|wee|week|frob)(knights|night|day)	-	weeknights	weeknights
345a[bc]d		-	xyzaaabcaababdacd	abd
346a[ab]c		-	aaabc	abc
347abc		s	abc	abc
348
349# subexpressions
350a(b)(c)d	-	abcd	abcd	b,c
351a(((b)))c	-	abc	abc	b,b,b
352a(b|(c))d	-	abd	abd	b,-
353a(b*|c|e)d	-	abbd	abbd	bb
354a(b*|c|e)d	-	acd	acd	c
355a(b*|c|e)d	-	ad	ad	@d
356a(b?)c		-	abc	abc	b
357a(b?)c		-	ac	ac	@c
358a(b+)c		-	abc	abc	b
359a(b+)c		-	abbbc	abbbc	bbb
360a(b*)c		-	ac	ac	@c
361(a|ab)(bc([de]+)f|cde)	-	abcdef	abcdef	a,bcdef,de
362# the regression tester only asks for 9 subexpressions
363a(b)(c)(d)(e)(f)(g)(h)(i)(j)k	-	abcdefghijk	abcdefghijk	b,c,d,e,f,g,h,i,j
364a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l	-	abcdefghijkl	abcdefghijkl	b,c,d,e,f,g,h,i,j,k
365a([bc]?)c	-	abc	abc	b
366a([bc]?)c	-	ac	ac	@c
367a([bc]+)c	-	abc	abc	b
368a([bc]+)c	-	abcc	abcc	bc
369a([bc]+)bc	-	abcbc	abcbc	bc
370a(bb+|b)b	-	abb	abb	b
371a(bbb+|bb+|b)b	-	abb	abb	b
372a(bbb+|bb+|b)b	-	abbb	abbb	bb
373a(bbb+|bb+|b)bb	-	abbb	abbb	b
374(.*).*		-	abcdef	abcdef	abcdef
375(a*)*		-	bc	@b	@b
376
377# do we get the right subexpression when it is used more than once?
378a(b|c)*d	-	ad	ad	-
379a(b|c)*d	-	abcd	abcd	c
380a(b|c)+d	-	abd	abd	b
381a(b|c)+d	-	abcd	abcd	c
382a(b|c?)+d	-	ad	ad	@d
383a(b|c?)+d	-	abcd	abcd	@d
384a(b|c){0,0}d	-	ad	ad	-
385a(b|c){0,1}d	-	ad	ad	-
386a(b|c){0,1}d	-	abd	abd	b
387a(b|c){0,2}d	-	ad	ad	-
388a(b|c){0,2}d	-	abcd	abcd	c
389a(b|c){0,}d	-	ad	ad	-
390a(b|c){0,}d	-	abcd	abcd	c
391a(b|c){1,1}d	-	abd	abd	b
392a(b|c){1,1}d	-	acd	acd	c
393a(b|c){1,2}d	-	abd	abd	b
394a(b|c){1,2}d	-	abcd	abcd	c
395a(b|c){1,}d	-	abd	abd	b
396a(b|c){1,}d	-	abcd	abcd	c
397a(b|c){2,2}d	-	acbd	acbd	b
398a(b|c){2,2}d	-	abcd	abcd	c
399a(b|c){2,4}d	-	abcd	abcd	c
400a(b|c){2,4}d	-	abcbd	abcbd	b
401a(b|c){2,4}d	-	abcbcd	abcbcd	c
402a(b|c){2,}d	-	abcd	abcd	c
403a(b|c){2,}d	-	abcbd	abcbd	b
404a(b+|((c)*))+d	-	abd	abd	@d,@d,-
405a(b+|((c)*))+d	-	abcd	abcd	@d,@d,-
406
407# check out the STARTEND option
408[abc]		&#	a(b)c	b
409[abc]		&#	a(d)c
410[abc]		&#	a(bc)d	b
411[abc]		&#	a(dc)d	c
412.		&#	a()c
413b.*c		&#	b(bc)c	bc
414b.*		&#	b(bc)c	bc
415.*c		&#	b(bc)c	bc
416
417# plain strings, with the NOSPEC flag
418abc		m	abc	abc
419abc		m	xabcy	abc
420abc		m	xyz
421a*b		m	aba*b	a*b
422a*b		m	ab
423""		mC	EMPTY
424
425# cases involving NULs
426aZb		&	a	a
427aZb		&p	a
428aZb		&p#	(aZb)	aZb
429aZ*b		&p#	(ab)	ab
430a.b		&#	(aZb)	aZb
431a.*		&#	(aZb)c	aZb
432
433# word boundaries (ick)
434[[:<:]]a	&	a	a
435[[:<:]]a	&	ba
436[[:<:]]a	&	-a	a
437a[[:>:]]	&	a	a
438a[[:>:]]	&	ab
439a[[:>:]]	&	a-	a
440[[:<:]]a.c[[:>:]]	&	axcd-dayc-dazce-abc	abc
441[[:<:]]a.c[[:>:]]	&	axcd-dayc-dazce-abc-q	abc
442[[:<:]]a.c[[:>:]]	&	axc-dayc-dazce-abc	axc
443
444# past problems
445(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A])	-	A1	A1
446abcdefghijklmnop	i	abcdefghijklmnop	abcdefghijklmnop
447abcdefghijklmnopqrstuv	i	abcdefghijklmnopqrstuv	abcdefghijklmnopqrstuv
448(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
449CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a	-	CC11	CC11
450