From 8e84da839113e82e469aa0ba2edaddca5c4c4e22 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 83c19115d..ebe42c407 100644 --- a/plugins/Format/plugin.py +++ b/plugins/Format/plugin.py @@ -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): + """ + + 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')