-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for regex replacement backreferences
- Loading branch information
Showing
5 changed files
with
67 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from perl.translator import translate_string | ||
|
||
|
||
def test_translate__replace(): | ||
assert ( | ||
translate_string("var =~ s/foo/bar/") | ||
== "var = __perl__reset_vars() or re.sub(r'foo', r'bar', var, count=1)" | ||
) | ||
|
||
|
||
def test_translate__replace_with_backref(): | ||
assert ( | ||
translate_string("var =~ s/^foo (.+?) bar/foo $1 bar/") | ||
== "var = __perl__reset_vars() or re.sub(r'^foo (.+?)', r'foo \\g<1> bar')" | ||
) | ||
|
||
|
||
def test_translate__replace_with_named_backref(): | ||
assert translate_string("var =~ s/^foo (?P<named>.+?) bar/foo $named bar/") == ( | ||
"var = __perl__reset_vars() or " | ||
"re.sub(r'^foo (?P<named>.+?) bar', r'foo \\g<named> bar')" | ||
) | ||
|
||
|
||
def test_translate__replace_all(): | ||
assert ( | ||
translate_string("var =~ s/foo/bar/g") | ||
== "var = __perl__reset_vars() or re.sub(r'foo', r'bar', var)" | ||
) |