tests 12 KB

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