summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_regex.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1996-12-20 22:00:21 (GMT)
committerBarry Warsaw <barry@python.org>1996-12-20 22:00:21 (GMT)
commit4b722788ae2bbd5595aef38f4fd7221a3ab88372 (patch)
tree8321e9cc292503b7ede51395a4e35566c3ca9c03 /Lib/test/test_regex.py
parent7f33e403a4c49c9265d44a7d9eb29e84c024e5c6 (diff)
downloadcpython-4b722788ae2bbd5595aef38f4fd7221a3ab88372.zip
cpython-4b722788ae2bbd5595aef38f4fd7221a3ab88372.tar.gz
cpython-4b722788ae2bbd5595aef38f4fd7221a3ab88372.tar.bz2
added test of the regex module
[NOTE: testall.py and autotest.py might could go away soon, I've played with Guido's new regrtest.py script and it seems to work well. I'll wait until Guido gives the word to completely switch over -- and change the Makefile too!]
Diffstat (limited to 'Lib/test/test_regex.py')
-rw-r--r--Lib/test/test_regex.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/Lib/test/test_regex.py b/Lib/test/test_regex.py
new file mode 100644
index 0000000..9d25d92
--- /dev/null
+++ b/Lib/test/test_regex.py
@@ -0,0 +1,62 @@
+from test_support import verbose
+import regex
+from regex_syntax import *
+
+re = 'a+b+c+'
+print 'no match:', regex.match(re, 'hello aaaabcccc world')
+print 'successful search:', regex.search(re, 'hello aaaabcccc world')
+try:
+ cre = regex.compile('\(' + re)
+except regex.error:
+ print 'caught expected exception'
+else:
+ print 'expected regex.error not raised'
+
+print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
+prev = regex.set_syntax(RE_SYNTAX_AWK)
+print 'successful awk syntax:', regex.search('(a+)|(b+)', 'cdb')
+regex.set_syntax(prev)
+print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
+
+re = '\(<one>[0-9]+\) *\(<two>[0-9]+\)'
+print 'matching with group names and compile()'
+cre = regex.compile(re)
+print cre.match('801 999')
+try:
+ print cre.group('one')
+except regex.error:
+ print 'caught expected exception'
+else:
+ print 'expected regex.error not raised'
+
+print 'matching with group names and symcomp()'
+cre = regex.symcomp(re)
+print cre.match('801 999')
+print cre.group(0)
+print cre.group('one')
+print cre.group(1, 2)
+print cre.group('one', 'two')
+print 'realpat:', cre.realpat
+print 'groupindex:', cre.groupindex
+
+re = 'world'
+cre = regex.compile(re)
+print 'not case folded search:', cre.search('HELLO WORLD')
+cre = regex.compile(re, regex.casefold)
+print 'case folded search:', cre.search('HELLO WORLD')
+
+print '__members__:', cre.__members__
+print 'regs:', cre.regs
+print 'last:', cre.last
+print 'translate:', `cre.translate`
+print 'givenpat:', cre.givenpat
+
+print 'match with pos:', cre.match('hello world', 7)
+print 'search with pos:', cre.search('hello world there world', 7)
+print 'bogus group:', cre.group(0, 1, 3)
+try:
+ print 'no name:', cre.group('one')
+except regex.error:
+ print 'caught expected exception'
+else:
+ print 'expected regex.error not raised'