diff options
author | Guido van Rossum <guido@python.org> | 1997-06-03 18:07:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-06-03 18:07:49 (GMT) |
commit | 876736cd0d2f4f5578a0508585a51771c654e5b7 (patch) | |
tree | c440273ce8b16ed1f2e686ee6af71e6d581ea914 /Lib/test/test_regex.py | |
parent | 71160aaffe494ef77ccdbef7ad639f65bd083705 (diff) | |
download | cpython-876736cd0d2f4f5578a0508585a51771c654e5b7.zip cpython-876736cd0d2f4f5578a0508585a51771c654e5b7.tar.gz cpython-876736cd0d2f4f5578a0508585a51771c654e5b7.tar.bz2 |
AMK's regex test suite
Diffstat (limited to 'Lib/test/test_regex.py')
-rw-r--r-- | Lib/test/test_regex.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Lib/test/test_regex.py b/Lib/test/test_regex.py index 078ca40..4be6026 100644 --- a/Lib/test/test_regex.py +++ b/Lib/test/test_regex.py @@ -60,3 +60,51 @@ except regex.error: print 'caught expected exception' else: print 'expected regex.error not raised' + +from regex_tests import * +if verbose: print 'Running regex_tests test suite' + +for t in tests: + 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=regex.compile(pattern) + except regex.error: + if outcome==SYNTAX_ERROR: pass # Expected a syntax error + else: + # Regex syntax errors aren't yet reported, so for + # the official test suite they'll be quietly ignored. + pass + #print '=== Syntax error:', t + 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==-1: pass # No match, as expected + else: print '=== Succeeded incorrectly', t + elif outcome==SUCCEED: + if result!=-1: + # Matched, as expected, so now we compute the + # result string and compare it to our expected result. + start, end = obj.regs[0] + found=s[start:end] + groups=obj.group(1,2,3,4,5,6,7,8,9,10) + vardict=vars() + for i in range(len(groups)): + vardict['g'+str(i+1)]=str(groups[i]) + repl=eval(repl) + if repl!=expected: + print '=== grouping error', t, repr(repl)+' should be '+repr(expected) + else: + print '=== Failed incorrectly', t |