Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3554cad

Browse files
committed
[Bug #1177831] Exercise (?(id)yes|no) for a group other than the first one
1 parent c30faa8 commit 3554cad

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_re.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ def test_re_groupref_exists(self):
235235
self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'a').groups(),
236236
('a', ''))
237237

238+
# Tests for bug #1177831: exercise groups other than the first group
239+
p = re.compile('(?P<g1>a)(?P<g2>b)?((?(g2)c|d))')
240+
self.assertEqual(p.match('abc').groups(),
241+
('a', 'b', 'c'))
242+
self.assertEqual(p.match('ad').groups(),
243+
('a', None, 'd'))
244+
self.assertEqual(p.match('abd'), None)
245+
self.assertEqual(p.match('ac'), None)
246+
247+
238248
def test_re_groupref(self):
239249
self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', '|a|').groups(),
240250
('|', 'a'))

0 commit comments

Comments
 (0)