1#
2#  Copyright (c) 2002 by The XFree86 Project, Inc.
3#
4#  Permission is hereby granted, free of charge, to any person obtaining a
5#  copy of this software and associated documentation files (the "Software"),
6#  to deal in the Software without restriction, including without limitation
7#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8#  and/or sell copies of the Software, and to permit persons to whom the
9#  Software is furnished to do so, subject to the following conditions:
10#
11#  The above copyright notice and this permission notice shall be included in
12#  all copies or substantial portions of the Software.
13#
14#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17#  THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18#  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19#  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20#  SOFTWARE.
21#
22#  Except as contained in this notice, the name of the XFree86 Project shall
23#  not be used in advertising or otherwise to promote the sale, use or other
24#  dealings in this Software without prior written authorization from the
25#  XFree86 Project.
26#
27#  Author: Paulo César Pereira de Andrade
28#
29#
30# $XFree86: xc/programs/xedit/lisp/re/tests.txt,v 1.1 2002/09/08 02:29:50 paulo Exp $
31
32# Some tests for the library:
33#	lines starting with # are comments
34#	lines starting with / are a regular expression pattern
35#		The pattern must end with / and may be followed by:
36#			i -> ignore case
37#			n -> create newline sensitive regex
38#	lines starting with > are a string input to the last pattern
39#		To test newline sensitive matching, add \n to the string.
40#	lines starting with a number are the expected result
41#		If more than one line, every subsequent line is the
42#		value of an "subresult".
43#	:NOMATCH means that the string input should not match
44
45# Simple string
46/abc/
47>abc
480,3: abc
49>aaaaaaaaaaaaaaabc
5014,17: abc
51>xxxxxxxxxxxxxxaaaaaaaaaaaaaaaaabcxx
5230,33: abc
53
54# String list
55/abc|bcd|cde/
56>abc
570,3: abc
58>aabc
591,4: abc
60>xxxbcdef
613,6: bcd
62>abdzzzcdabcde
638,11: abc
64>xxxxabdecdabdcde
6513,16: cde
66
67# Complex string
68/a?bc|ab?c|abc?/
69>abc
700,3: abc
71>xxxb
72:NOMATCH
73>xxxbc
743,5: bc
75>sssssab
765,7: ab
77
78# Another complex string
79/a*bc|ab*c|abc*/
80>aaaaaaabc
810,9: aaaaaaabc
82>xaaaaaaabc
831,10: aaaaaaabc
84>xyzaaaaaaabc
853,12: aaaaaaabc
86>abbc
870,4: abbc
88>xxabbbbbc
892,9: abbbbbc
90>abcccccccccc
910,12: abcccccccccc
92>abccccccccccd
930,12: abcccccccccc
94>xxxxxxxaaaaaaaaaabbbbbbbbbbbccccccccccc
9516,29: abbbbbbbbbbbc
96>xxxbbbbbbbbbc
9711,13: bc
98
99# Another complex string
100/a+bc|ab+c|abc+/
101>xxxbc
102:NOMATCH
103>xaaabc
1041,6: aaabc
105>zzzzaaaaabbc
1068,12: abbc
107>zzzzaaaabbbbbbcccc
1087,15: abbbbbbc
109
110# Simple pattern
111/a.c/
112>abc
1130,3: abc
114>aaac
1151,4: aac
116>xac
117:NOMATCH
118>xaac
1191,4: aac
120>xxabc
1212,5: abc
122>xxxaxc
1233,6: axc
124
125# Another simple pattern
126/a*c/
127>c
1280,1: c
129>xxxxxxxxc
1308,9: c
131>xxxxxxxcc
1327,8: c
133>ac
1340,2: ac
135>aaaac
1360,5: aaaac
137>xac
1381,3: ac
139>xxxaac
1403,6: aac
141>xxac
1422,4: ac
143>xxxxac
1444,6: ac
145
146# Another simple pattern
147/a+c/
148>xxaac
1492,5: aac
150>xxxaaaac
1513,8: aaaac
152>xaaaabac
1536,8: ac
154>xxxc
155:NOMATCH
156>xxxxaaaaccc
1574,9: aaaac
158
159# Another simple pattern
160/a{4}b/
161>xabxxaabxxxaaabxxxxaaaab
16219,24: aaaab
163>aaabaaaab
1644,9: aaaab
165
166# Another simple pattern
167/a{4,}b/
168>xxxaaaab
1693,8: aaaab
170>zaaabzzzaaaaaaaaaaaaaaaab
1718,25: aaaaaaaaaaaaaaaab
172
173# Another simple pattern
174/a{,4}b/
175>b
1760,1: b
177>xxxxxxxxb
1788,9: b
179>xaaaaaaaaab
1806,11: aaaab
181>xxxab
1823,5: ab
183>aaaaaxaaab
1846,10: aaab
185
186# Another simple pattern
187/a{2,4}b/
188>xab
189:NOMATCH
190>xaab
1911,4: aab
192>xaaab
1931,5: aaab
194>xxaaaab
1952,7: aaaab
196>xxxaaaaab
1974,9: aaaab
198
199# Some simple grouping tests
200/foo(bar|baz)fee/
201>feebarbazfoobarfee
2029,18: foobarfee
20312,15: bar
204>foofooobazfeefoobazfee
20513,22: foobazfee
206/f(oo|ee)ba[rz]/
207>barfoebaz
208:NOMATCH
209>bazfoobar
2103,9: foobar
2114,6: oo
212>barfeebaz
2133,9: feebaz
2144,6: ee
215/\<(int|char)\>/
216>aint character int foo
21715,18: int
21815,18: int
219
220# Some complex repetitions
221/foo.*bar/
222>barfoblaboofoobarfoobarfoobar
22311,17: foobar
224/foo.+bar/
225>foobar
226:NOMATCH
227>fobbarfooxbarfooybar
2286,13: fooxbar
229/foo.?bar/
230>xfoobar
2311,7: foobar
232>xxfooxxbar
233:NOMATCH
234>yyyfootbar
2353,10: footbar
236
237# Some nested complex repetitions
238/a.*b.*c/
239>abc
2400,3: abc
241>xxxxxxxxxabbbbbbbccaaaaabbbc
2429,18: abbbbbbbc
243/a.+b.*c/
244>xxxabc 
245:NOMATCH
246>xxaxbbc
2472,7: axbbc
248/a.+b.?c/
249>xaabc
2501,5: aabc
251>xxaabbc
2522,7: aabbc
253
254# Very complex repetitions
255/(foo.*|bar)fee/
256# XXX NOTE
257# This pattern does not return the correct offset for the group.
258# Support for this may and may not be added.
259
260>barfoofee
2613,9: foofee
262>foobarfee
2630,9: foobarfee
264>xxfobarfee
2654,10: barfee
266>barfooooooobarfee
2673,17: fooooooobarfee
268>xxfobarfeefoobar
2694,10: barfee
270/(foo.+|bar)fee/
271>barfoofee
272:NOMATCH
273>barfooxfee
2743,10: fooxfee
275/(foo.?|bar)fee/
276>foobar
277:NOMATCH
278>bafoofee
2792,8:foofee
280>bafooofeebarfee
2812,9: fooofee
282>bafoofeebarfee
2832,8: foofee
284
285# Simple backreference
286/(a|b|c)\1/
287>aa
2880,2: aa
2890,1: a
290/(a|b|c)(a|b|c)\1\2/
291>acac
2920,4: acac
2930,1: a
2941,2: c
295>xxxxacac
2964,8: acac
2974,5: a
2985,6: c
299>xxacabacbcacbbacbcaaccabcaca
30024,28: caca
30124,25: c
30225,26: a
303>xyabcccc
3044,8: cccc
3054,5: c
3065,6: c
307
308# Complex backreference
309/(a*b)\1/
310>xxxaaaaabaaaaab
3113,15: aaaaabaaaaab
3123,9: aaaaab
313/(ab+c)\1/
314>xaaabbbcabbbc
3153,13: abbbcabbbc
3163,8: abbbc
317/(ab?c)\1/
318>abcac
319:NOMATCH
320>abcacabcabc
3215,11: abcabc
3225,8: abc
323>abcacac
3243,7: acac
3253,5: acac
326
327# Very complex backreference
328/a(.*)b\1/
329>xxxab
3303,5: ab
3314,4: 
332>xxxxazzzbzzz
3334,12: azzzbzzz
3345,8: zzz
335
336# Case testing
337/abc/i
338>AbC
3390,3: AbC
340/[0-9][a-z]+/i
341>xxx0aaZxYT9
3423,10: 0aaZxYT
343/a.b/i
344>aaaaaaaaaaaxB
34510,13: axB
346/a.*z/i
347>xxxAaaaaZ
3483,9: AaaaaZ
349>xxaaaZaaa
3502,6: aaaZ
351/\<(lambda|defun|defmacro)\>/i
352>    (lambda
3535,11: lambda
3545,11: lambda
355/\<(nil|t)\>/i
356>it Nil
3573,6: Nil
3583,6: Nil
359/\<(begin|end)\>/i
360>beginning the ending EnD
36121,24: EnD
36221,24: EnD
363
364# Some newline tests
365/a.*/n
366>a\naaa
3670,1:a
368>xyza\naa
3693,4: a
370/a.+/n
371>a\naaa
3722,5: aaa
373>xyza\naa
3745,7: aa
375/a.?/n
376>a\naaa
3770,1: a
378>xyza\naa
3793,4: a
380
381# Newline tests envolving complex patterns
382/a.*b.*c/n
383>xxaa\nzyacb\nabc
38411,14: abc
385>xxxab\nabc\nc
3866,9: abc
387/a.+b.*c/n
388>ab\nbc\nabbc
3896,10: abbc
390/a.?b.*c/n
391>ab\ncabbc\ncc
3924,8: abbc
393/^foo$/n
394>bar\nfoobar\nfoo
39511,14: foo
396
397# Not so complex test involving a newline...
398/^\s*#\s*(define|include)\s+.+/n
399>#define\n#include x
4008,18: #include x
4019,16: include
402
403# Check if large strings are working
404/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
405>zzzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzzz
4063,259: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
407/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~/
408>String here: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~/
40913,333: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~
410
411
412# Some complex repetitions not supported
413# Listed here only to make sure the library is not crashing on these
414#  Repetitions that match an empty match, or an empty string cannot follow
415# a complex repetition. A complex repetition is:
416#	.* or .+ or .?
417#	.{...} is not supported.
418/(.*)(\d*)/
419:BADRPT
420/(.*).(\d*)/
421:BADRPT
422/(.*)\<(\d*)/
423:BADRPT
424/(.*)\s(\d*)/
425:BADRPT
426/(.*)\D(\d*)/
427:BADRPT
428
429# This is a more clear pattern and partially works
430/(.*)\D(\d+)/
431>abcW12
4320,6: abcW12
4330,3: abc
4344,6: 12
435>abcW12abcW12
4360,6: abcW12
4370,3: abc
4384,6: 12
439# This wasn't working in the previous version, but now with only minimal
440# matches supported, it works.
441>abcW12abcW12a
4420,6: abcW12
4430,3: abc
4444,6: 12
445
446# Note the minimal match
447/.*\d/
448>a1a1a1aaaaaaa
4490,2: a1
450# Check match offsets
451/(.*)\d/
452>a1a1a1aaaaaaa
4530,2: a1
4540,1: a
455/.*(\d)/
456>a1a1a1aaaaaaa
4570,2: a1
4581,2: 1
459
460/.*(\d+)/
461:BADRPT
462
463# Regression fix, was matching empty string
464/\\\d{3}|\\./
465>\\
466:NOMATCH
467
468/\\.|\\\d{3}/
469>\\
470:NOMATCH
471