From dae8dfd2e7c35756a2b11ac6d8ca865a0dad50db Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Sun, 11 Apr 2010 02:27:22 -0400 Subject: [PATCH] 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. --- plugins/Format/plugin.py | 9 +++++++++ plugins/Format/test.py | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/plugins/Format/plugin.py b/plugins/Format/plugin.py index 5e3e4611a..0a00f38cb 100644 --- a/plugins/Format/plugin.py +++ b/plugins/Format/plugin.py @@ -99,6 +99,15 @@ class Format(callbacks.Plugin): translate = wrap(translate, ['something', 'something', 'text']) @internationalizeDocstring + def replace(self, irc, msg, args, bad, good, text): + """ + + Replaces all non-overlapping occurrences of + with in . + """ + irc.reply(text.replace(bad, good)) + replace = wrap(replace, ['something', 'something', 'text']) + def upper(self, irc, msg, args, text): """ diff --git a/plugins/Format/test.py b/plugins/Format/test.py index 3bbf14602..f891e0dd7 100644 --- a/plugins/Format/test.py +++ b/plugins/Format/test.py @@ -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')