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