From 3554cad009c84889ee0397a77a69ab30307b57ae Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Thu, 2 Jun 2005 13:38:45 +0000 Subject: [PATCH] [Bug #1177831] Exercise (?(id)yes|no) for a group other than the first one --- Lib/test/test_re.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 07bc63b277a..c86f502c50d 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('(?Pa)(?Pb)?((?(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'))