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:
Daniel Folkinshteyn 2010-04-11 02:27:22 -04:00
parent 643be43466
commit 8e84da8391
2 changed files with 13 additions and 0 deletions

View File

@ -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>

View File

@ -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')