mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Apply substitute rules in sequence
This commit is contained in:
parent
19eb729db3
commit
8e0558b804
2 changed files with 11 additions and 3 deletions
|
|
@ -34,9 +34,7 @@ class Substitute(BeetsPlugin):
|
||||||
"""Do the actual replacing."""
|
"""Do the actual replacing."""
|
||||||
if text:
|
if text:
|
||||||
for pattern, replacement in self.substitute_rules:
|
for pattern, replacement in self.substitute_rules:
|
||||||
new_text, subs_made = pattern.subn(replacement, text)
|
text = pattern.sub(replacement, text)
|
||||||
if subs_made > 0:
|
|
||||||
return new_text
|
|
||||||
return text
|
return text
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -78,3 +78,13 @@ class SubstitutePluginTest(PluginTestCase):
|
||||||
("b", "y"),
|
("b", "y"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_rules_applied_in_sequence(self):
|
||||||
|
self.run_substitute(
|
||||||
|
{"a": "b", "b": "c", "d": "a"},
|
||||||
|
[
|
||||||
|
("a", "c"),
|
||||||
|
("b", "c"),
|
||||||
|
("d", "a"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue