mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
add replace function to format that takes varying-length strings to replace.
add test for it add error test for format.translate for different length translate args.
This commit is contained in:
parent
643be43466
commit
8e84da8391
@ -90,6 +90,15 @@ class Format(callbacks.Plugin):
|
||||
irc.reply(text.translate(string.maketrans(bad, good)))
|
||||
translate = wrap(translate, ['something', 'something', 'text'])
|
||||
|
||||
def replace(self, irc, msg, args, bad, good, text):
|
||||
"""<substring to translate> <substring to replace it with> <text>
|
||||
|
||||
Replaces all non-overlapping occurrences of <substring to translate>
|
||||
with <substring to replace it with> in <text>.
|
||||
"""
|
||||
irc.reply(text.replace(bad, good))
|
||||
replace = wrap(replace, ['something', 'something', 'text'])
|
||||
|
||||
def upper(self, irc, msg, args, text):
|
||||
"""<text>
|
||||
|
||||
|
@ -54,6 +54,10 @@ class FormatTestCase(PluginTestCase):
|
||||
|
||||
def testTranslate(self):
|
||||
self.assertResponse('translate 123 456 1234567890', '4564567890')
|
||||
self.assertError('translate 123 1234 123125151')
|
||||
|
||||
def testReplace(self):
|
||||
self.assertResponse('replace # %23 bla#foo', 'bla%23foo')
|
||||
|
||||
def testUpper(self):
|
||||
self.assertResponse('upper foo', 'FOO')
|
||||
|
Loading…
Reference in New Issue
Block a user