summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2005-06-02 13:38:45 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2005-06-02 13:38:45 (GMT)
commit3554cad009c84889ee0397a77a69ab30307b57ae (patch)
treec3b77a8231938afbd807527645d70eaac85f9e0f /Lib
parentc30faa812c507c94d744419bce7c497f1a283d95 (diff)
downloadcpython-3554cad009c84889ee0397a77a69ab30307b57ae.zip
cpython-3554cad009c84889ee0397a77a69ab30307b57ae.tar.gz
cpython-3554cad009c84889ee0397a77a69ab30307b57ae.tar.bz2
[Bug #1177831] Exercise (?(id)yes|no) for a group other than the first one
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_re.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 07bc63b..c86f502 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -235,6 +235,16 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'a').groups(),
('a', ''))
+ # Tests for bug #1177831: exercise groups other than the first group
+ p = re.compile('(?P<g1>a)(?P<g2>b)?((?(g2)c|d))')
+ self.assertEqual(p.match('abc').groups(),
+ ('a', 'b', 'c'))
+ self.assertEqual(p.match('ad').groups(),
+ ('a', None, 'd'))
+ self.assertEqual(p.match('abd'), None)
+ self.assertEqual(p.match('ac'), None)
+
+
def test_re_groupref(self):
self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', '|a|').groups(),
('|', 'a'))