Skip to content

Commit a34a9c2

Browse files
committed
Add test for using full group match
1 parent 7e53406 commit a34a9c2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/framework/filetools.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,10 +1486,13 @@ def test_apply_regex_substitutions(self):
14861486
self.assertEqual(new_testtxt, expected_testtxt)
14871487
# Supports capture groups
14881488
ft.write_file(testfile, testtxt)
1489-
repl = ('This si( .*)\n(.*)mkae right$', r'This is\1.\n\2make right')
1490-
ft.apply_regex_substitutions(testfile, [repl], backup=False, on_missing_match=ERROR, single_line=False)
1489+
repls = [
1490+
('This si( .*)\n(.*)mkae right$', r'This is\1.\n\2make right'),
1491+
('Lea(ve)', r'Do \g<0>\1'), # Reference to full match
1492+
]
1493+
ft.apply_regex_substitutions(testfile, repls, backup=False, on_missing_match=ERROR, single_line=False)
14911494
new_testtxt = ft.read_file(testfile)
1492-
self.assertEqual(new_testtxt, expected_testtxt)
1495+
self.assertEqual(new_testtxt, expected_testtxt.replace('Leave', 'Do Leaveve'))
14931496

14941497
# make sure apply_regex_substitutions can patch files that include UTF-8 characters
14951498
testtxt = b"foo \xe2\x80\x93 bar" # This is an UTF-8 "-"

0 commit comments

Comments
 (0)