[Python-checkins] python/dist/src/Lib/test test_re.py,1.39,1.40
niemeyer@users.sourceforge.net
niemeyer@users.sourceforge.net
Sun, 27 Apr 2003 05:34:16 -0700
- Previous message: [Python-checkins] python/dist/src/Lib/test test_bisect.py,1.7,1.8 test_bool.py,1.9,1.10 test_os.py,1.15,1.16 test_support.py,1.50,1.51
- Next message: [Python-checkins] python/dist/src/Modules _sre.c,2.93,2.94
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv31416/Lib/test
Modified Files:
test_re.py
Log Message:
Applied patch #725106, by Greg Chapman, fixing capturing groups
within repeats of alternatives. The only change to the original
patch was to convert the tests to the new test_re.py file.
This patch fixes cases like:
>>> re.match('((a)|b)*', 'abc').groups()
('b', '')
Which is wrong (it's impossible to match the empty string),
and incompatible with other regex systems, like the following
examples show:
% perl -e '"abc" =~ /^((a)|b)*/; print "$1 $2\n";'
b a
% echo "abc" | sed -r -e "s/^((a)|b)*/\1 \2|/"
b a|c
Index: test_re.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_re.py,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** test_re.py 25 Apr 2003 16:00:14 -0000 1.39
--- test_re.py 27 Apr 2003 12:34:14 -0000 1.40
***************
*** 277,280 ****
--- 277,299 ----
('a:', 'a'))
+ def test_bug_725106(self):
+ # capturing groups in alternatives in repeats
+ self.assertEqual(re.match('^((a)|b)*', 'abc').groups(),
+ ('b', 'a'))
+ self.assertEqual(re.match('^(([ab])|c)*', 'abc').groups(),
+ ('c', 'b'))
+ self.assertEqual(re.match('^((d)|[ab])*', 'abc').groups(),
+ ('b', None))
+ self.assertEqual(re.match('^((a)c|[ab])*', 'abc').groups(),
+ ('b', None))
+ self.assertEqual(re.match('^((a)|b)*?c', 'abc').groups(),
+ ('b', 'a'))
+ self.assertEqual(re.match('^(([ab])|c)*?d', 'abcd').groups(),
+ ('c', 'b'))
+ self.assertEqual(re.match('^((d)|[ab])*?c', 'abc').groups(),
+ ('b', None))
+ self.assertEqual(re.match('^((a)c|[ab])*?c', 'abc').groups(),
+ ('b', None))
+
def test_finditer(self):
iter = re.finditer(r":+", "a:b::c:::d")
- Previous message: [Python-checkins] python/dist/src/Lib/test test_bisect.py,1.7,1.8 test_bool.py,1.9,1.10 test_os.py,1.15,1.16 test_support.py,1.50,1.51
- Next message: [Python-checkins] python/dist/src/Modules _sre.c,2.93,2.94
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]