Utilities: add countargs function, returns number of arguments supplied.

also add tests for it.
This commit is contained in:
Daniel Folkinshteyn 2010-06-03 16:08:25 -04:00
parent 52b36555f4
commit 5f2d2a9c5e
2 changed files with 13 additions and 0 deletions

View File

@ -104,6 +104,14 @@ class Utilities(callbacks.Plugin):
irc.error('%s' % (e,))
sample = wrap(sample, ['positiveInt', many('anything')])
def countargs(self, irc, msg, args, things):
"""<arg> [<arg> ...]
Counts the arguments given.
"""
irc.reply(len(things))
countargs = wrap(countargs, [any('anything')])
def apply(self, irc, msg, args, command, rest):
"""<command> <text>

View File

@ -65,4 +65,9 @@ class UtilitiesTestCase(PluginTestCase):
self.assertError('sample 5 moo')
self.assertRegexp('sample 2 a b c', '^[a-c] [a-c]$')
def testCountargs(self):
self.assertResponse('countargs a b c', '3')
self.assertResponse('countargs a "b c"', '2')
self.assertResponse('countargs', '0')
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: