wrap() String.len to vastly simplify the function and prevent responding with -1 when we get no arguments.

Add a test to make sure we respond with the help when called with no arguments.
This commit is contained in:
James Vega 2007-07-10 14:10:30 +00:00
parent 99696986f6
commit 068f029355
2 changed files with 4 additions and 6 deletions

View File

@ -108,16 +108,13 @@ class String(callbacks.Plugin):
irc.reply(utils.str.soundex(text, length)) irc.reply(utils.str.soundex(text, length))
soundex = wrap(soundex, ['somethingWithoutSpaces', additional('int', 4)]) soundex = wrap(soundex, ['somethingWithoutSpaces', additional('int', 4)])
def len(self, irc, msg, args): def len(self, irc, msg, args, text):
"""<text> """<text>
Returns the length of <text>. Returns the length of <text>.
""" """
total = 0 irc.reply(str(len(text)))
for arg in args: len = wrap(len, ['text'])
total += len(arg)
total += len(args)-1 # spaces between the arguments.
irc.reply(str(total))
def re(self, irc, msg, args, ff, text): def re(self, irc, msg, args, ff, text):
"""<regexp> <text> """<regexp> <text>

View File

@ -77,6 +77,7 @@ class StringTestCase(PluginTestCase):
plugins = ('String', 'Format', 'Status') plugins = ('String', 'Format', 'Status')
def testLen(self): def testLen(self):
self.assertResponse('len foo', '3') self.assertResponse('len foo', '3')
self.assertHelp('len')
def testNoErrors(self): def testNoErrors(self):
self.assertNotError('levenshtein Python Perl') self.assertNotError('levenshtein Python Perl')