[Python-checkins] CVS: python/dist/src/Lib/test test_sre.py,1.2,1.3
Fredrik Lundh
python-dev@python.org
Mon, 3 Jul 2000 11:44:24 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory slayer.i.sourceforge.net:/tmp/cvs-serv30343/Lib/test
Modified Files:
test_sre.py
Log Message:
- added lookbehind support (?<=pattern), (?<!pattern).
the pattern must have a fixed width.
- got rid of array-module dependencies; the match pro-
gram is now stored inside the pattern object, rather
than in an extra string buffer.
- cleaned up a various of potential leaks, api abuses,
and other minors in the engine module.
- use mal's new isalnum macro, rather than my own work-
around.
- untabified test_sre.py. seems like I removed a couple
of trailing spaces in the process...
Index: test_sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_sre.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** test_sre.py 2000/06/30 07:50:59 1.2
--- test_sre.py 2000/07/03 18:44:21 1.3
***************
*** 36,40 ****
try:
assert sre.sub("(?i)b+", "x", "bbbb BBBB") == 'x x'
!
def bump_num(matchobj):
int_value = int(matchobj.group(0))
--- 36,40 ----
try:
assert sre.sub("(?i)b+", "x", "bbbb BBBB") == 'x x'
!
def bump_num(matchobj):
int_value = int(matchobj.group(0))
***************
*** 43,47 ****
assert sre.sub(r'\d+', bump_num, '08.2 -2 23x99y') == '9.3 -3 24x100y'
assert sre.sub(r'\d+', bump_num, '08.2 -2 23x99y', 3) == '9.3 -3 23x99y'
!
assert sre.sub('.', lambda m: r"\n", 'x') == '\\n'
assert sre.sub('.', r"\n", 'x') == '\n'
--- 43,47 ----
assert sre.sub(r'\d+', bump_num, '08.2 -2 23x99y') == '9.3 -3 24x100y'
assert sre.sub(r'\d+', bump_num, '08.2 -2 23x99y', 3) == '9.3 -3 23x99y'
!
assert sre.sub('.', lambda m: r"\n", 'x') == '\\n'
assert sre.sub('.', r"\n", 'x') == '\n'
***************
*** 49,53 ****
s = r"\1\1"
assert sre.sub('(.)', s, 'x') == 'xx'
! assert sre.sub('(.)', sre.escape(s), 'x') == s
assert sre.sub('(.)', lambda m: s, 'x') == s
--- 49,53 ----
s = r"\1\1"
assert sre.sub('(.)', s, 'x') == 'xx'
! assert sre.sub('(.)', sre.escape(s), 'x') == s
assert sre.sub('(.)', lambda m: s, 'x') == s
***************
*** 145,149 ****
if verbose:
print 'Running tests on sre.split'
!
try:
assert sre.split(":", ":a:b::c") == ['', 'a', 'b', '', 'c']
--- 145,149 ----
if verbose:
print 'Running tests on sre.split'
!
try:
assert sre.split(":", ":a:b::c") == ['', 'a', 'b', '', 'c']
***************
*** 165,169 ****
assert sre.split("(:)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c']
! assert sre.split("(:*)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c']
except AssertionError:
raise TestFailed, "qualified sre.split"
--- 165,169 ----
assert sre.split("(:)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c']
! assert sre.split("(:*)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c']
except AssertionError:
raise TestFailed, "qualified sre.split"
***************
*** 187,200 ****
try:
# No groups at all
! m = sre.match('a', 'a') ; assert m.groups() == ()
# A single group
! m = sre.match('(a)', 'a') ; assert m.groups() == ('a',)
pat = sre.compile('((a)|(b))(c)?')
! assert pat.match('a').groups() == ('a', 'a', None, None)
! assert pat.match('b').groups() == ('b', None, 'b', None)
! assert pat.match('ac').groups() == ('a', 'a', None, 'c')
! assert pat.match('bc').groups() == ('b', None, 'b', 'c')
! assert pat.match('bc').groups("") == ('b', "", 'b', 'c')
except AssertionError:
raise TestFailed, "match .groups() method"
--- 187,200 ----
try:
# No groups at all
! m = sre.match('a', 'a') ; assert m.groups() == ()
# A single group
! m = sre.match('(a)', 'a') ; assert m.groups() == ('a',)
pat = sre.compile('((a)|(b))(c)?')
! assert pat.match('a').groups() == ('a', 'a', None, None)
! assert pat.match('b').groups() == ('b', None, 'b', None)
! assert pat.match('ac').groups() == ('a', 'a', None, 'c')
! assert pat.match('bc').groups() == ('b', None, 'b', 'c')
! assert pat.match('bc').groups("") == ('b', "", 'b', 'c')
except AssertionError:
raise TestFailed, "match .groups() method"
***************
*** 202,213 ****
try:
# A single group
! m = sre.match('(a)', 'a')
! assert m.group(0) == 'a' ; assert m.group(0) == 'a'
assert m.group(1) == 'a' ; assert m.group(1, 1) == ('a', 'a')
pat = sre.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
! assert pat.match('a').group(1, 2, 3) == ('a', None, None)
! assert pat.match('b').group('a1', 'b2', 'c3') == (None, 'b', None)
! assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c')
except AssertionError:
raise TestFailed, "match .group() method"
--- 202,213 ----
try:
# A single group
! m = sre.match('(a)', 'a')
! assert m.group(0) == 'a' ; assert m.group(0) == 'a'
assert m.group(1) == 'a' ; assert m.group(1, 1) == ('a', 'a')
pat = sre.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
! assert pat.match('a').group(1, 2, 3) == ('a', None, None)
! assert pat.match('b').group('a1', 'b2', 'c3') == (None, 'b', None)
! assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c')
except AssertionError:
raise TestFailed, "match .group() method"
***************
*** 253,260 ****
assert sre.L == sre.LOCALE
assert sre.M == sre.MULTILINE
! assert sre.S == sre.DOTALL
! assert sre.X == sre.VERBOSE
! assert sre.T == sre.TEMPLATE
! assert sre.U == sre.UNICODE
except AssertionError:
raise TestFailed, 're module constants'
--- 253,260 ----
assert sre.L == sre.LOCALE
assert sre.M == sre.MULTILINE
! assert sre.S == sre.DOTALL
! assert sre.X == sre.VERBOSE
! assert sre.T == sre.TEMPLATE
! assert sre.U == sre.UNICODE
except AssertionError:
raise TestFailed, 're module constants'
***************
*** 273,277 ****
# To save time, only run the first and last 10 tests
#tests = tests[:10] + tests[-10:]
! pass
for t in tests:
--- 273,277 ----
# To save time, only run the first and last 10 tests
#tests = tests[:10] + tests[-10:]
! pass
for t in tests:
***************
*** 281,285 ****
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)
--- 281,285 ----
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)
***************
*** 289,293 ****
except sre.error:
if outcome==SYNTAX_ERROR: pass # Expected a syntax error
! else:
print '=== Syntax error:', t
except KeyboardInterrupt: raise KeyboardInterrupt
--- 289,293 ----
except sre.error:
if outcome==SYNTAX_ERROR: pass # Expected a syntax error
! else:
print '=== Syntax error:', t
except KeyboardInterrupt: raise KeyboardInterrupt
***************
*** 357,361 ****
# break (because it won't match at the end or start of a
# string), so we'll ignore patterns that feature it.
!
if pattern[:2]!='\\B' and pattern[-2:]!='\\B':
obj=sre.compile(pattern)
--- 357,361 ----
# break (because it won't match at the end or start of a
# string), so we'll ignore patterns that feature it.
!
if pattern[:2]!='\\B' and pattern[-2:]!='\\B':
obj=sre.compile(pattern)