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 committed by Valentin Lorentz
parent 6381266cfd
commit 957998f483
4 changed files with 36 additions and 2 deletions

View File

@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Supybot-fr\n"
"POT-Creation-Date: 2011-02-20 11:27+CET\n"
"POT-Creation-Date: 2011-02-20 11:29+CET\n"
"PO-Revision-Date: \n"
"Last-Translator: Valentin Lorentz <progval@gmail.com>\n"
"Language-Team: Supybot-fr <progval@gmail.com>\n"
@ -91,6 +91,17 @@ msgstr ""
#: plugin.py:122
msgid ""
"<arg> [<arg> ...]\n"
"\n"
" Counts the arguments given.\n"
" "
msgstr ""
"<argument> [<argument> ...]\n"
"\n"
"Retorune le nombre d'<argument>s donnés."
#: plugin.py:131
msgid ""
"<command> <text>\n"
"\n"
" Tokenizes <text> and calls <command> with the resulting arguments.\n"

View File

@ -5,7 +5,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2011-02-20 11:27+CET\n"
"POT-Creation-Date: 2011-02-20 11:29+CET\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -82,6 +82,15 @@ msgstr ""
#: plugin.py:122
#, docstring
msgid ""
"<arg> [<arg> ...]\n"
"\n"
" Counts the arguments given.\n"
" "
msgstr ""
#: plugin.py:131
#, docstring
msgid ""
"<command> <text>\n"
"\n"
" Tokenizes <text> and calls <command> with the resulting arguments.\n"

View File

@ -117,6 +117,15 @@ class Utilities(callbacks.Plugin):
irc.error('%s' % (e,))
sample = wrap(sample, ['positiveInt', many('anything')])
@internationalizeDocstring
def countargs(self, irc, msg, args, things):
"""<arg> [<arg> ...]
Counts the arguments given.
"""
irc.reply(len(things))
countargs = wrap(countargs, [any('anything')])
@internationalizeDocstring
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: