1 from test_support
import verbose
3 from regex_syntax
import *
6 print 'no match:', regex
.match(re
, 'hello aaaabcccc world')
7 print 'successful search:', regex
.search(re
, 'hello aaaabcccc world')
9 cre
= regex
.compile('\(' + re
)
11 print 'caught expected exception'
13 print 'expected regex.error not raised'
15 print 'failed awk syntax:', regex
.search('(a+)|(b+)', 'cdb')
16 prev
= regex
.set_syntax(RE_SYNTAX_AWK
)
17 print 'successful awk syntax:', regex
.search('(a+)|(b+)', 'cdb')
18 regex
.set_syntax(prev
)
19 print 'failed awk syntax:', regex
.search('(a+)|(b+)', 'cdb')
21 re
= '\(<one>[0-9]+\) *\(<two>[0-9]+\)'
22 print 'matching with group names and compile()'
23 cre
= regex
.compile(re
)
24 print cre
.match('801 999')
26 print cre
.group('one')
28 print 'caught expected exception'
30 print 'expected regex.error not raised'
32 print 'matching with group names and symcomp()'
33 cre
= regex
.symcomp(re
)
34 print cre
.match('801 999')
36 print cre
.group('one')
38 print cre
.group('one', 'two')
39 print 'realpat:', cre
.realpat
40 print 'groupindex:', cre
.groupindex
43 cre
= regex
.compile(re
)
44 print 'not case folded search:', cre
.search('HELLO WORLD')
45 cre
= regex
.compile(re
, regex
.casefold
)
46 print 'case folded search:', cre
.search('HELLO WORLD')
48 print '__members__:', cre
.__members
__
49 print 'regs:', cre
.regs
50 print 'last:', cre
.last
51 print 'translate:', len(cre
.translate
)
52 print 'givenpat:', cre
.givenpat
54 print 'match with pos:', cre
.match('hello world', 7)
55 print 'search with pos:', cre
.search('hello world there world', 7)
56 print 'bogus group:', cre
.group(0, 1, 3)
58 print 'no name:', cre
.group('one')
60 print 'caught expected exception'
62 print 'expected regex.error not raised'
64 from regex_tests
import *
65 if verbose
: print 'Running regex_tests test suite'
68 pattern
=s
=outcome
=repl
=expected
=None
70 pattern
, s
, outcome
, repl
, expected
= t
72 pattern
, s
, outcome
= t
74 raise ValueError, ('Test tuples should have 3 or 5 fields',t
)
77 obj
=regex
.compile(pattern
)
79 if outcome
==SYNTAX_ERROR
: pass # Expected a syntax error
81 # Regex syntax errors aren't yet reported, so for
82 # the official test suite they'll be quietly ignored.
84 #print '=== Syntax error:', t
88 except regex
.error
, msg
:
89 print '=== Unexpected exception', t
, repr(msg
)
90 if outcome
==SYNTAX_ERROR
:
91 # This should have been a syntax error; forget it.
94 if result
==-1: pass # No match, as expected
95 else: print '=== Succeeded incorrectly', t
96 elif outcome
==SUCCEED
:
98 # Matched, as expected, so now we compute the
99 # result string and compare it to our expected result.
100 start
, end
= obj
.regs
[0]
102 groups
=obj
.group(1,2,3,4,5,6,7,8,9,10)
104 for i
in range(len(groups
)):
105 vardict
['g'+str(i
+1)]=str(groups
[i
])
108 print '=== grouping error', t
, repr(repl
)+' should be '+repr(expected
)
110 print '=== Failed incorrectly', t