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 committed by Valentin Lorentz
parent 2d718d31bb
commit dae8dfd2e7
2 changed files with 13 additions and 0 deletions

View File

@ -99,6 +99,15 @@ class Format(callbacks.Plugin):
translate = wrap(translate, ['something', 'something', 'text']) translate = wrap(translate, ['something', 'something', 'text'])
@internationalizeDocstring @internationalizeDocstring
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): def upper(self, irc, msg, args, text):
"""<text> """<text>

View File

@ -54,6 +54,10 @@ class FormatTestCase(PluginTestCase):
def testTranslate(self): def testTranslate(self):
self.assertResponse('translate 123 456 1234567890', '4564567890') 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): def testUpper(self):
self.assertResponse('upper foo', 'FOO') self.assertResponse('upper foo', 'FOO')