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))
soundex = wrap(soundex, ['somethingWithoutSpaces', additional('int', 4)])
def len(self, irc, msg, args):
def len(self, irc, msg, args, text):
"""<text>
Returns the length of <text>.
"""
total = 0
for arg in args:
total += len(arg)
total += len(args)-1 # spaces between the arguments.
irc.reply(str(total))
irc.reply(str(len(text)))
len = wrap(len, ['text'])
def re(self, irc, msg, args, ff, text):
"""<regexp> <text>

View File

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