summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-07-11 19:34:44 (GMT)
committerGuido van Rossum <guido@python.org>1997-07-11 19:34:44 (GMT)
commit8e0ce30ce41e7674b4c2266e55d3c02f9e478531 (patch)
tree0a0f567ea4ada18b6f619737dc755ebf8a5cb40e /Lib/test/test_re.py
parent007c80e5b7f4da404bf3682a3a0cf67e24135c73 (diff)
downloadcpython-8e0ce30ce41e7674b4c2266e55d3c02f9e478531.zip
cpython-8e0ce30ce41e7674b4c2266e55d3c02f9e478531.tar.gz
cpython-8e0ce30ce41e7674b4c2266e55d3c02f9e478531.tar.bz2
test suite for re.py
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
new file mode 100644
index 0000000..63acff8
--- /dev/null
+++ b/Lib/test/test_re.py
@@ -0,0 +1,56 @@
+from test_support import verbose
+import re
+import traceback
+
+from re_tests import *
+if verbose: print 'Running regex_tests test suite'
+
+for t in tests:
+ print t
+ pattern=s=outcome=repl=expected=None
+ if len(t)==5:
+ pattern, s, outcome, repl, expected = t
+ elif len(t)==3:
+ pattern, s, outcome = t
+ else:
+ raise ValueError, ('Test tuples should have 3 or 5 fields',t)
+
+ try:
+ obj=re.compile(pattern)
+ except re.error:
+ if outcome==SYNTAX_ERROR: pass # Expected a syntax error
+ else:
+ print '=== Syntax error:', t
+ except:
+ print '*** Unexpected error ***'
+ traceback.print_exc()
+ else:
+ try:
+ result=obj.search(s)
+ except regex.error, msg:
+ print '=== Unexpected exception', t, repr(msg)
+ if outcome==SYNTAX_ERROR:
+ # This should have been a syntax error; forget it.
+ pass
+ elif outcome==FAIL:
+ if result is None: pass # No match, as expected
+ else: print '=== Succeeded incorrectly', t
+ elif outcome==SUCCEED:
+ if result is not None:
+ # Matched, as expected, so now we compute the
+ # result string and compare it to our expected result.
+ start, end = result.span(0)
+ vardict={'found': result.group(0)}
+ for i in range(1, 100):
+ try:
+ gi = result.group(i)
+ except IndexError:
+ break
+ else:
+ vardict['g%d' % i] = gi
+ repl=eval(repl, vardict)
+ if repl!=expected:
+ print '=== grouping error', t,
+ print repr(repl)+' should be '+repr(expected)
+ else:
+ print '=== Failed incorrectly', t