3 # regular expression test set
4 # Lines are at least three fields, separated by one or more tabs. "" stands
5 # for an empty field. First field is an RE. Second field is flags. If
6 # C flag given, regcomp() is expected to fail, and the third field is the
7 # error name (minus the leading REG_).
9 # Otherwise it is expected to succeed, and the third field is the string to
10 # try matching it against. If there is no fourth field, the match is
11 # expected to fail. If there is a fourth field, it is the substring that
12 # the RE is expected to match. If there is a fifth field, it is a comma-
13 # separated list of what the subexpressions should match, with - indicating
14 # no match for that one. In both the fourth and fifth fields, a (sub)field
15 # starting with @ indicates that the (sub)expression is expected to match
16 # a null string followed by the stuff after the @; this provides a way to
17 # test where null strings match. The character `N' in REs and strings
18 # is newline, `S' is space, `T' is tab, `Z' is NUL.
20 # The full list of flags:
21 # - placeholder, does nothing
22 # b RE is a BRE, not an ERE
23 # & try it as both an ERE and a BRE
24 # C regcomp() error expected, third field is error name
26 # m ("mundane") REG_NOSPEC
27 # s REG_NOSUB (not really testable)
31 # # REG_STARTEND (see below)
34 # For REG_STARTEND, the start/end offsets are those of the substring
43 # parentheses and perversions thereof
53 # gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
56 # end gagging (in a just world, those *should* give EPAREN)
63 # anchoring and REG_NEWLINE
74 # stop retching, those are legitimate (although disgusting)
85 \($\)\(^\) bn aNNb @Nb
97 # certain syntax errors and non-errors
128 # metacharacters, backslashes
140 # trailing $ is a peculiar special case for the BRE code
150 # back references, ugh
153 a\(b*\)c\1d b abbcbbd abbcbbd bb
155 a\(b*\)c\1d b abbcbbbd
157 a\([bc]\)\1d b abcdabbd abbd b
158 a\(\([bc]\)\2\)*d b abbccd abbccd
159 a\(\([bc]\)\2\)*d b abbcbd
160 # actually, this next one probably ought to fail, but the spec is unclear
161 a\(\(b\)*\2\)*d b abbbd abbbd
162 # here is a case that no NFA implementation does right
163 \(ab*\)[ab]*\1 b ababaaa ababaaa a
164 # check out normal matching in the presence of back refs
165 \(a\)\1bcd b aabcd aabcd
166 \(a\)\1bc*d b aabcd aabcd
167 \(a\)\1bc*d b aabd aabd
168 \(a\)\1bc*d b aabcccd aabcccd
169 \(a\)\1bc*[ce]d b aabcccd aabcccd
170 ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd
172 # ordinary repetitions
183 # the dreaded bounded repetitions
214 ab\{0,0\}c b abcac ac
216 ab\{0,1\}c b abcac abc
217 ab{0,3}c - abbcac abbc
218 ab\{0,3\}c b abbcac abbc
220 ab\{1,1\}c b acabc abc
222 ab\{1,3\}c b acabc abc
223 ab{2,2}c - abcabbc abbc
224 ab\{2,2\}c b abcabbc abbc
225 ab{2,4}c - abcabbc abbc
226 ab\{2,4\}c b abcabbc abbc
227 ((a{1,10}){1,10}){1,10} - a a a,a
229 # multiple repetitions
247 a\{1\}\{1\} bC BADRPT
251 # brackets, and numerous perversions thereof
266 a[[.-.]--]c & a-c a-c
273 a[[.x,.]] &C ECOLLATE
274 a[[.one.]]b & a1b a1b
275 a[[.notdef.]]b &C ECOLLATE
277 a[[:alpha:]]c & abc abc
278 a[[:notdef:]]c &C ECTYPE
281 a[[:alpha:] &C EBRACK
282 a[[:alpha,:] &C ECTYPE
285 a[[:alph:]] &C ECTYPE
286 a[[:alphabet:]] &C ECTYPE
287 [[:alnum:]]+ - -%@a0X- a0X
288 [[:alpha:]]+ - -%@aX0- aX
289 [[:blank:]]+ - aSSTb SST
290 [[:cntrl:]]+ - aNTb NT
291 [[:digit:]]+ - a019b 019
292 [[:graph:]]+ - Sa%bS a%b
293 [[:lower:]]+ - AabC ab
294 [[:print:]]+ - NaSbN aSb
295 [[:punct:]]+ - S%-&T %-&
296 [[:space:]]+ - aSNTb SNT
297 [[:upper:]]+ - aBCd BC
298 [[:xdigit:]]+ - p0f3Cq 0f3C
304 a[[=b,=]] &C ECOLLATE
305 a[[=one=]]b & a1b a1b
311 # just gotta have one DFA-buster, of course
312 a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
313 # and an inline expansion in case somebody gets tricky
314 a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
315 # and in case somebody just slips in an NFA...
316 a[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
317 # fish for anomalies as the number of states passes 32
318 12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789
319 123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890
320 1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901
321 12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012
322 123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123
323 # and one really big one, beyond any plausible word width
324 1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890
325 # fish for problems as brackets go past 8
326 [ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm
327 [ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo
328 [ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq
329 [ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq
331 # subtleties of matching
335 a[Bc]*d i abBCcd abBCcd
336 0[[:upper:]]1 &i 0a1 0a1
337 0[[:lower:]]1 &i 0A1 0A1
343 [abc]b[abc] - abc abc
344 [abc]b[abd] - abd abd
346 (wee|week)(knights|night) - weeknights weeknights
347 (we|wee|week|frob)(knights|night|day) - weeknights weeknights
348 a[bc]d - xyzaaabcaababdacd abd
353 # Let's have some fun -- try to match a C comment.
354 # first the obvious, which looks okay at first glance...
355 /\*.*\*/ - /*x*/ /*x*/
357 /\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/
358 # okay, we must not match */ inside; try to do that...
359 /\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/
360 /\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/
362 /\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/
363 # and a still fancier version, which does it right (I think)...
364 /\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/
365 /\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/
366 /\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/
367 /\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/
368 /\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/
369 /\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/
372 a(b)(c)d - abcd abcd b,c
373 a(((b)))c - abc abc b,b,b
374 a(b|(c))d - abd abd b,-
375 a(b*|c|e)d - abbd abbd bb
376 a(b*|c|e)d - acd acd c
377 a(b*|c|e)d - ad ad @d
381 a(b+)c - abbbc abbbc bbb
383 (a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de
384 # the regression tester only asks for 9 subexpressions
385 a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j
386 a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k
387 a([bc]?)c - abc abc b
389 a([bc]+)c - abc abc b
390 a([bc]+)c - abcc abcc bc
391 a([bc]+)bc - abcbc abcbc bc
392 a(bb+|b)b - abb abb b
393 a(bbb+|bb+|b)b - abb abb b
394 a(bbb+|bb+|b)b - abbb abbb bb
395 a(bbb+|bb+|b)bb - abbb abbb b
396 (.*).* - abcdef abcdef abcdef
399 # do we get the right subexpression when it is used more than once?
401 a(b|c)*d - abcd abcd c
403 a(b|c)+d - abcd abcd c
405 a(b|c?)+d - abcd abcd @d
406 a(b|c){0,0}d - ad ad -
407 a(b|c){0,1}d - ad ad -
408 a(b|c){0,1}d - abd abd b
409 a(b|c){0,2}d - ad ad -
410 a(b|c){0,2}d - abcd abcd c
411 a(b|c){0,}d - ad ad -
412 a(b|c){0,}d - abcd abcd c
413 a(b|c){1,1}d - abd abd b
414 a(b|c){1,1}d - acd acd c
415 a(b|c){1,2}d - abd abd b
416 a(b|c){1,2}d - abcd abcd c
417 a(b|c){1,}d - abd abd b
418 a(b|c){1,}d - abcd abcd c
419 a(b|c){2,2}d - acbd acbd b
420 a(b|c){2,2}d - abcd abcd c
421 a(b|c){2,4}d - abcd abcd c
422 a(b|c){2,4}d - abcbd abcbd b
423 a(b|c){2,4}d - abcbcd abcbcd c
424 a(b|c){2,}d - abcd abcd c
425 a(b|c){2,}d - abcbd abcbd b
426 a(b+|((c)*))+d - abd abd @d,@d,-
427 a(b+|((c)*))+d - abcd abcd @d,@d,-
429 # check out the STARTEND option
439 # plain strings, with the NOSPEC flag
447 # cases involving NULs
455 # word boundaries (ick)
462 [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc
463 [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc
464 [[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc
465 [[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc
466 [[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_
467 [[:<:]]a_b[[:>:]] & x_a_b
469 # past problems, and suspected problems
470 (A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1
471 abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop
472 abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv
473 (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
474 CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11
475 Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz
477 -\{0,1\}[0-9]*$ b -5 -5