1 # regular expression test set
2 # Lines are at least three fields, separated by one or more tabs. "" stands
3 # for an empty field. First field is an RE. Second field is flags. If
4 # C flag given, regcomp() is expected to fail, and the third field is the
5 # error name (minus the leading REG_).
7 # Otherwise it is expected to succeed, and the third field is the string to
8 # try matching it against. If there is no fourth field, the match is
9 # expected to fail. If there is a fourth field, it is the substring that
10 # the RE is expected to match. If there is a fifth field, it is a comma-
11 # separated list of what the subexpressions should match, with - indicating
12 # no match for that one. In both the fourth and fifth fields, a (sub)field
13 # starting with @ indicates that the (sub)expression is expected to match
14 # a null string followed by the stuff after the @; this provides a way to
15 # test where null strings match. The character `N' in REs and strings
16 # is newline, `S' is space, `T' is tab, `Z' is NUL.
18 # The full list of flags:
19 # - placeholder, does nothing
20 # b RE is a BRE, not an ERE
21 # & try it as both an ERE and a BRE
22 # C regcomp() error expected, third field is error name
24 # m ("mundane") REG_NOSPEC
25 # s REG_NOSUB (not really testable)
29 # # REG_STARTEND (see below)
32 # For REG_STARTEND, the start/end offsets are those of the substring
41 # parentheses and perversions thereof
51 # gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
54 # end gagging (in a just world, those *should* give EPAREN)
61 # anchoring and REG_NEWLINE
72 # stop retching, those are legitimate (although disgusting)
83 \($\)\(^\) bn aNNb @Nb
95 # certain syntax errors and non-errors
126 # metacharacters, backslashes
132 # The following test is wrong. Using \b in an BRE or ERE is undefined.
139 # trailing $ is a peculiar special case for the BRE code
149 # back references, ugh
152 a\(b*\)c\1d b abbcbbd abbcbbd bb
154 a\(b*\)c\1d b abbcbbbd
156 a\([bc]\)\1d b abcdabbd abbd b
157 a\(\([bc]\)\2\)*d b abbccd abbccd
158 a\(\([bc]\)\2\)*d b abbcbd
159 # actually, this next one probably ought to fail, but the spec is unclear
160 a\(\(b\)*\2\)*d b abbbd abbbd
161 # here is a case that no NFA implementation does right
162 \(ab*\)[ab]*\1 b ababaaa ababaaa a
163 # check out normal matching in the presence of back refs
164 \(a\)\1bcd b aabcd aabcd
165 \(a\)\1bc*d b aabcd aabcd
166 \(a\)\1bc*d b aabd aabd
167 \(a\)\1bc*d b aabcccd aabcccd
168 \(a\)\1bc*[ce]d b aabcccd aabcccd
169 ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd
171 # ordinary repetitions
182 # the dreaded bounded repetitions
183 # The following two tests are not correct:
186 # '{' is always a special char outside bracket expressions. So test ony BRE:
191 # Same reason as for the two tests above:
206 # These four tests checks for undefined behavior. Our implementation does
207 # something different.
216 # These two tests probably fails due to an arbitrary limit on the number of
217 # repetitions in the other implementation.
223 ab\{0,0\}c b abcac ac
225 ab\{0,1\}c b abcac abc
226 ab{0,3}c - abbcac abbc
227 ab\{0,3\}c b abbcac abbc
229 ab\{1,1\}c b acabc abc
231 ab\{1,3\}c b acabc abc
232 ab{2,2}c - abcabbc abbc
233 ab\{2,2\}c b abcabbc abbc
234 ab{2,4}c - abcabbc abbc
235 ab\{2,4\}c b abcabbc abbc
236 ((a{1,10}){1,10}){1,10} - a a a,a
238 # multiple repetitions
239 # Wow, there is serious disconnect here. The ERE grammar is like this:
240 # ERE_expression : one_char_or_coll_elem_ERE
243 # | '(' extended_reg_exp ')'
244 # | ERE_expression ERE_dupl_symbol
246 # where ERE_dupl_symbol is any of the repetition methods. It is clear from
247 # this that consecutive repetition is OK. On top of this, the one test not
248 # marked as failing must fail. For BREs the situation is different, so we
249 # use the four tests.
268 a\{1\}\{1\} bC BADRPT
272 # brackets, and numerous perversions thereof
287 a[[.-.]--]c & a-c a-c
288 # I don't thing the error value should be ERANGE since a[1-] would be
289 # valid, too. Expect EBRACK.
297 a[[.x,.]] &C ECOLLATE
298 # This test is invalid. "one" is no collating symbol in any standardized
300 # a[[.one.]]b & a1b a1b
301 a[[.notdef.]]b &C ECOLLATE
303 a[[:alpha:]]c & abc abc
304 a[[:notdef:]]c &C ECTYPE
307 a[[:alpha:] &C EBRACK
308 a[[:alpha,:] &C ECTYPE
311 a[[:alph:]] &C ECTYPE
312 a[[:alphabet:]] &C ECTYPE
313 [[:alnum:]]+ - -%@a0X- a0X
314 [[:alpha:]]+ - -%@aX0- aX
315 [[:blank:]]+ - aSSTb SST
316 [[:cntrl:]]+ - aNTb NT
317 [[:digit:]]+ - a019b 019
318 [[:graph:]]+ - Sa%bS a%b
319 [[:lower:]]+ - AabC ab
320 [[:print:]]+ - NaSbN aSb
321 [[:punct:]]+ - S%-&T %-&
322 [[:space:]]+ - aSNTb SNT
323 [[:upper:]]+ - aBCd BC
324 [[:xdigit:]]+ - p0f3Cq 0f3C
330 a[[=b,=]] &C ECOLLATE
331 # This test is invalid. "one" is no collating symbol in any standardized
333 #a[[=one=]]b & a1b a1b
339 # just gotta have one DFA-buster, of course
340 a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
341 # and an inline expansion in case somebody gets tricky
342 a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
343 # and in case somebody just slips in an NFA...
344 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
345 # fish for anomalies as the number of states passes 32
346 12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789
347 123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890
348 1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901
349 12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012
350 123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123
351 # and one really big one, beyond any plausible word width
352 1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890
353 # fish for problems as brackets go past 8
354 [ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm
355 [ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo
356 [ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq
357 [ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq
359 # subtleties of matching
363 a[Bc]*d i abBCcd abBCcd
364 0[[:upper:]]1 &i 0a1 0a1
365 0[[:lower:]]1 &i 0A1 0A1
371 [abc]b[abc] - abc abc
372 [abc]b[abd] - abd abd
374 (wee|week)(knights|night) - weeknights weeknights
375 (we|wee|week|frob)(knights|night|day) - weeknights weeknights
376 a[bc]d - xyzaaabcaababdacd abd
382 # Let's have some fun -- try to match a C comment.
383 # first the obvious, which looks okay at first glance...
384 /\*.*\*/ - /*x*/ /*x*/
386 /\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/
387 # okay, we must not match */ inside; try to do that...
388 /\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/
389 /\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/
391 /\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/
392 # and a still fancier version, which does it right (I think)...
393 /\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/
394 /\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/
395 /\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/
396 /\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/
397 /\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/
398 /\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/
402 a(b)(c)d - abcd abcd b,c
403 a(((b)))c - abc abc b,b,b
404 a(b|(c))d - abd abd b,-
405 a(b*|c|e)d - abbd abbd bb
406 a(b*|c|e)d - acd acd c
407 a(b*|c|e)d - ad ad @d
411 a(b+)c - abbbc abbbc bbb
413 (a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de
414 # the regression tester only asks for 9 subexpressions
415 a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j
416 a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k
417 a([bc]?)c - abc abc b
419 a([bc]+)c - abc abc b
420 a([bc]+)c - abcc abcc bc
421 a([bc]+)bc - abcbc abcbc bc
422 a(bb+|b)b - abb abb b
423 a(bbb+|bb+|b)b - abb abb b
424 a(bbb+|bb+|b)b - abbb abbb bb
425 a(bbb+|bb+|b)bb - abbb abbb b
426 (.*).* - abcdef abcdef abcdef
429 # do we get the right subexpression when it is used more than once?
431 a(b|c)*d - abcd abcd c
433 a(b|c)+d - abcd abcd c
435 a(b|c?)+d - abcd abcd c
436 a(b|c){0,0}d - ad ad -
437 a(b|c){0,1}d - ad ad -
438 a(b|c){0,1}d - abd abd b
439 a(b|c){0,2}d - ad ad -
440 a(b|c){0,2}d - abcd abcd c
441 a(b|c){0,}d - ad ad -
442 a(b|c){0,}d - abcd abcd c
443 a(b|c){1,1}d - abd abd b
444 a(b|c){1,1}d - acd acd c
445 a(b|c){1,2}d - abd abd b
446 a(b|c){1,2}d - abcd abcd c
447 a(b|c){1,}d - abd abd b
448 a(b|c){1,}d - abcd abcd c
449 a(b|c){2,2}d - acbd acbd b
450 a(b|c){2,2}d - abcd abcd c
451 a(b|c){2,4}d - abcd abcd c
452 a(b|c){2,4}d - abcbd abcbd b
453 a(b|c){2,4}d - abcbcd abcbcd c
454 a(b|c){2,}d - abcd abcd c
455 a(b|c){2,}d - abcbd abcbd b
456 a(b+|((c)*))+d - abd abd b,-,-
457 a(b+|((c)*))+d - abcd abcd c,c,c
459 # check out the STARTEND option
469 # plain strings, with the NOSPEC flag
477 # cases involving NULs
485 # word boundaries (ick)
492 [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc
493 [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc
494 [[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc
495 [[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc
496 [[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_
497 [[:<:]]a_b[[:>:]] & x_a_b
499 # past problems, and suspected problems
500 (A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1
501 abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop
502 abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv
503 (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
504 CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11
505 Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz
507 -\{0,1\}[0-9]*$ b -5 -5
508 a*a*a*a*a*a*a* & aaaaaa aaaaaa
510 \(\b\)\{0,0\} b abc @abc -
512 a(.*)b(\1){0}c - abc abc @bc,-
513 a(.*)b(\1){0}c - axbc axbc x,-
515 a\(\(b*\)\)c\1d b abbcbbd abbcbbd bb,bb
516 a\(\([bc]\)\)\2d b abcdabbd abbd b,b
517 a\(\(\(\([bc]\)\)\3\)\)*d b abbccd abbccd cc,cc,c,c
518 a(b)(c)d - abcd abcd b,c
519 a(((b)))c - abc abc b,b,b
520 a(((b|(((c))))))d - abd abd b,b,b,-,-,-
521 a(((b*|c|e)))d - abbd abbd bb,bb,bb
522 a((b|c)){0,0}d - ad ad -,-
523 a((b|c)){0,1}d - abd abd b,b
524 a((b|c)){0,2}d - abcd abcd c,c
525 a((b+|((c)*)))+d - abd abd b,b,-,-
526 a((b+|((c)*)))+d - abcd abcd c,c,c,c
527 (((\b))){0} - x @x -,-,-
528 a(((.*)))b((\2)){0}c - abc abc @bc,@bc,@bc,-,-
529 a(((.*)))b((\1)){0}c - axbc axbc x,x,x,-,-