
just checked in a test script for sre. the test_sre file is a copy of test_re, with some minor changes:
-- disabled one test (caused by bug #8; see below)
-- added T (template mode, experimental, unsupported) and U (unicode locale) flags to the flag test
-- removed keyword arguments in pattern test loop:
result = obj.search(s, pos=result.start(0), endpos=result.end(0)+1)
was changed to:
result = obj.search(s, result.start(0), result.end(0)+1)
as far as I can tell, the docs don't mention anything about keyword arguments...
-- added unicode pattern / target string / locale tests to the pattern test loop.
however, the current version SRE doesn't fully pass the test. here's an annotated version of Lib/test/output/test_sre:
1) test_support -- test failed re module pickle 2) test_support -- test failed re module cPickle
under SRE, patterns are C objects, not class instances. to allow pickling, I need to modify copy_reg (either by modifing the file itself, or by updating the registry when SRE is first imported). see patch #100650 for more info,
3) === Syntax error: ('(?P<foo_123>a)(?P=foo_123)', 'aa', 0, 'g1', 'a')
this is a bug in the SRE parser. should be easy to fix.
4) === Failed incorrectly ('^(.+)?B', 'AB', 0, 'g1', 'A')
this is a bug in the engine (nested repetitions). needs further research.
5) === Failed incorrectly ('(a+)+\1', 'aa', 0, 'found+"-"+g1', 'aa-a')
this is a bug in the engine or in the parser. needs further research.
6) === grouping error ('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', 0, 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/') 'd:msgs/tdir/sub1/-trial/' should be 'd:msgs/tdir/sub1/-tdir/'
same as #5.
7) === Syntax error: ('(?P<id>aa)(?P=id)', 'aaaa', 0, 'found+"-"+id', 'aaaa-aa')
same as #3.
8) === grouping error ('([abc])*bcd', 'abcd', 0, 'found+"-"+g1', 'abcd-a') 'abcd-c' should be 'abcd-a'
this is a bug in the engine. should be easy to fix, I think. in fact, I could have sworn that I'd fixed it already.
9) === grouping error ('(?i)([abc])*bcd', 'ABCD', 0, 'found+"-"+g1', 'ABCD-A') 'ABCD-C' should be 'ABCD-A'
same as #8
10) === Syntax error: ('a(?!b).', 'abad', 0, 'found', 'ad')
this is bug in the parser. should be easy to fix.
11) === Syntax error: ('a(?=d).', 'abad', 0, 'found', 'ad')
same as (or at least related to) #10
12) === Syntax error: ('a(?=c|d).', 'abad', 0, 'found', 'ad')
same as #11
13) === Failed incorrectly ('^(.+)?B', 'AB', 0, 'g1', 'A')
same as #4 (literally!).
...
fwiw, *all* RE-based code I've played with seem to work. ymmv. let me know asap if it does.
</F>
participants (1)
-
Fredrik Lundh