tests.txt   [plain text]


#
#  Copyright (c) 2002 by The XFree86 Project, Inc.
#
#  Permission is hereby granted, free of charge, to any person obtaining a
#  copy of this software and associated documentation files (the "Software"),
#  to deal in the Software without restriction, including without limitation
#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
#  and/or sell copies of the Software, and to permit persons to whom the
#  Software is furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
#  THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
#  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#  SOFTWARE.
#
#  Except as contained in this notice, the name of the XFree86 Project shall
#  not be used in advertising or otherwise to promote the sale, use or other
#  dealings in this Software without prior written authorization from the
#  XFree86 Project.
#
#  Author: Paulo César Pereira de Andrade
#
#
# $XFree86: xc/programs/xedit/lisp/re/tests.txt,v 1.1 2002/09/08 02:29:50 paulo Exp $

# Some tests for the library:
#	lines starting with # are comments
#	lines starting with / are a regular expression pattern
#		The pattern must end with / and may be followed by:
#			i -> ignore case
#			n -> create newline sensitive regex
#	lines starting with > are a string input to the last pattern
#		To test newline sensitive matching, add \n to the string.
#	lines starting with a number are the expected result
#		If more than one line, every subsequent line is the
#		value of an "subresult".
#	:NOMATCH means that the string input should not match

# Simple string
/abc/
>abc
0,3: abc
>aaaaaaaaaaaaaaabc
14,17: abc
>xxxxxxxxxxxxxxaaaaaaaaaaaaaaaaabcxx
30,33: abc

# String list
/abc|bcd|cde/
>abc
0,3: abc
>aabc
1,4: abc
>xxxbcdef
3,6: bcd
>abdzzzcdabcde
8,11: abc
>xxxxabdecdabdcde
13,16: cde

# Complex string
/a?bc|ab?c|abc?/
>abc
0,3: abc
>xxxb
:NOMATCH
>xxxbc
3,5: bc
>sssssab
5,7: ab

# Another complex string
/a*bc|ab*c|abc*/
>aaaaaaabc
0,9: aaaaaaabc
>xaaaaaaabc
1,10: aaaaaaabc
>xyzaaaaaaabc
3,12: aaaaaaabc
>abbc
0,4: abbc
>xxabbbbbc
2,9: abbbbbc
>abcccccccccc
0,12: abcccccccccc
>abccccccccccd
0,12: abcccccccccc
>xxxxxxxaaaaaaaaaabbbbbbbbbbbccccccccccc
16,29: abbbbbbbbbbbc
>xxxbbbbbbbbbc
11,13: bc

# Another complex string
/a+bc|ab+c|abc+/
>xxxbc
:NOMATCH
>xaaabc
1,6: aaabc
>zzzzaaaaabbc
8,12: abbc
>zzzzaaaabbbbbbcccc
7,15: abbbbbbc

# Simple pattern
/a.c/
>abc
0,3: abc
>aaac
1,4: aac
>xac
:NOMATCH
>xaac
1,4: aac
>xxabc
2,5: abc
>xxxaxc
3,6: axc

# Another simple pattern
/a*c/
>c
0,1: c
>xxxxxxxxc
8,9: c
>xxxxxxxcc
7,8: c
>ac
0,2: ac
>aaaac
0,5: aaaac
>xac
1,3: ac
>xxxaac
3,6: aac
>xxac
2,4: ac
>xxxxac
4,6: ac

# Another simple pattern
/a+c/
>xxaac
2,5: aac
>xxxaaaac
3,8: aaaac
>xaaaabac
6,8: ac
>xxxc
:NOMATCH
>xxxxaaaaccc
4,9: aaaac

# Another simple pattern
/a{4}b/
>xabxxaabxxxaaabxxxxaaaab
19,24: aaaab
>aaabaaaab
4,9: aaaab

# Another simple pattern
/a{4,}b/
>xxxaaaab
3,8: aaaab
>zaaabzzzaaaaaaaaaaaaaaaab
8,25: aaaaaaaaaaaaaaaab

# Another simple pattern
/a{,4}b/
>b
0,1: b
>xxxxxxxxb
8,9: b
>xaaaaaaaaab
6,11: aaaab
>xxxab
3,5: ab
>aaaaaxaaab
6,10: aaab

# Another simple pattern
/a{2,4}b/
>xab
:NOMATCH
>xaab
1,4: aab
>xaaab
1,5: aaab
>xxaaaab
2,7: aaaab
>xxxaaaaab
4,9: aaaab

# Some simple grouping tests
/foo(bar|baz)fee/
>feebarbazfoobarfee
9,18: foobarfee
12,15: bar
>foofooobazfeefoobazfee
13,22: foobazfee
/f(oo|ee)ba[rz]/
>barfoebaz
:NOMATCH
>bazfoobar
3,9: foobar
4,6: oo
>barfeebaz
3,9: feebaz
4,6: ee
/\<(int|char)\>/
>aint character int foo
15,18: int
15,18: int

# Some complex repetitions
/foo.*bar/
>barfoblaboofoobarfoobarfoobar
11,17: foobar
/foo.+bar/
>foobar
:NOMATCH
>fobbarfooxbarfooybar
6,13: fooxbar
/foo.?bar/
>xfoobar
1,7: foobar
>xxfooxxbar
:NOMATCH
>yyyfootbar
3,10: footbar

# Some nested complex repetitions
/a.*b.*c/
>abc
0,3: abc
>xxxxxxxxxabbbbbbbccaaaaabbbc
9,18: abbbbbbbc
/a.+b.*c/
>xxxabc 
:NOMATCH
>xxaxbbc
2,7: axbbc
/a.+b.?c/
>xaabc
1,5: aabc
>xxaabbc
2,7: aabbc

# Very complex repetitions
/(foo.*|bar)fee/
# XXX NOTE
# This pattern does not return the correct offset for the group.
# Support for this may and may not be added.

>barfoofee
3,9: foofee
>foobarfee
0,9: foobarfee
>xxfobarfee
4,10: barfee
>barfooooooobarfee
3,17: fooooooobarfee
>xxfobarfeefoobar
4,10: barfee
/(foo.+|bar)fee/
>barfoofee
:NOMATCH
>barfooxfee
3,10: fooxfee
/(foo.?|bar)fee/
>foobar
:NOMATCH
>bafoofee
2,8:foofee
>bafooofeebarfee
2,9: fooofee
>bafoofeebarfee
2,8: foofee

# Simple backreference
/(a|b|c)\1/
>aa
0,2: aa
0,1: a
/(a|b|c)(a|b|c)\1\2/
>acac
0,4: acac
0,1: a
1,2: c
>xxxxacac
4,8: acac
4,5: a
5,6: c
>xxacabacbcacbbacbcaaccabcaca
24,28: caca
24,25: c
25,26: a
>xyabcccc
4,8: cccc
4,5: c
5,6: c

# Complex backreference
/(a*b)\1/
>xxxaaaaabaaaaab
3,15: aaaaabaaaaab
3,9: aaaaab
/(ab+c)\1/
>xaaabbbcabbbc
3,13: abbbcabbbc
3,8: abbbc
/(ab?c)\1/
>abcac
:NOMATCH
>abcacabcabc
5,11: abcabc
5,8: abc
>abcacac
3,7: acac
3,5: acac

# Very complex backreference
/a(.*)b\1/
>xxxab
3,5: ab
4,4: 
>xxxxazzzbzzz
4,12: azzzbzzz
5,8: zzz

# Case testing
/abc/i
>AbC
0,3: AbC
/[0-9][a-z]+/i
>xxx0aaZxYT9
3,10: 0aaZxYT
/a.b/i
>aaaaaaaaaaaxB
10,13: axB
/a.*z/i
>xxxAaaaaZ
3,9: AaaaaZ
>xxaaaZaaa
2,6: aaaZ
/\<(lambda|defun|defmacro)\>/i
>    (lambda
5,11: lambda
5,11: lambda
/\<(nil|t)\>/i
>it Nil
3,6: Nil
3,6: Nil
/\<(begin|end)\>/i
>beginning the ending EnD
21,24: EnD
21,24: EnD

# Some newline tests
/a.*/n
>a\naaa
0,1:a
>xyza\naa
3,4: a
/a.+/n
>a\naaa
2,5: aaa
>xyza\naa
5,7: aa
/a.?/n
>a\naaa
0,1: a
>xyza\naa
3,4: a

# Newline tests envolving complex patterns
/a.*b.*c/n
>xxaa\nzyacb\nabc
11,14: abc
>xxxab\nabc\nc
6,9: abc
/a.+b.*c/n
>ab\nbc\nabbc
6,10: abbc
/a.?b.*c/n
>ab\ncabbc\ncc
4,8: abbc
/^foo$/n
>bar\nfoobar\nfoo
11,14: foo

# Not so complex test involving a newline...
/^\s*#\s*(define|include)\s+.+/n
>#define\n#include x
8,18: #include x
9,16: include

# Check if large strings are working
/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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nopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~/
13,333: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890~


# Some complex repetitions not supported
# Listed here only to make sure the library is not crashing on these
#  Repetitions that match an empty match, or an empty string cannot follow
# a complex repetition. A complex repetition is:
#	.* or .+ or .?
#	.{...} is not supported.
/(.*)(\d*)/
:BADRPT
/(.*).(\d*)/
:BADRPT
/(.*)\<(\d*)/
:BADRPT
/(.*)\s(\d*)/
:BADRPT
/(.*)\D(\d*)/
:BADRPT

# This is a more clear pattern and partially works
/(.*)\D(\d+)/
>abcW12
0,6: abcW12
0,3: abc
4,6: 12
>abcW12abcW12
0,6: abcW12
0,3: abc
4,6: 12
# This wasn't working in the previous version, but now with only minimal
# matches supported, it works.
>abcW12abcW12a
0,6: abcW12
0,3: abc
4,6: 12

# Note the minimal match
/.*\d/
>a1a1a1aaaaaaa
0,2: a1
# Check match offsets
/(.*)\d/
>a1a1a1aaaaaaa
0,2: a1
0,1: a
/.*(\d)/
>a1a1a1aaaaaaa
0,2: a1
1,2: 1

/.*(\d+)/
:BADRPT