From 5f2d2a9c5e403bbc6bba2c257787c4b05bc4b640 Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Thu, 3 Jun 2010 16:08:25 -0400 Subject: [PATCH] Utilities: add countargs function, returns number of arguments supplied. also add tests for it. --- plugins/Utilities/plugin.py | 8 ++++++++ plugins/Utilities/test.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/plugins/Utilities/plugin.py b/plugins/Utilities/plugin.py index 2c1e45e80..4846e4519 100644 --- a/plugins/Utilities/plugin.py +++ b/plugins/Utilities/plugin.py @@ -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): + """ [ ...] + + Counts the arguments given. + """ + irc.reply(len(things)) + countargs = wrap(countargs, [any('anything')]) + def apply(self, irc, msg, args, command, rest): """ diff --git a/plugins/Utilities/test.py b/plugins/Utilities/test.py index 2a7ab6751..9f7c5db14 100644 --- a/plugins/Utilities/test.py +++ b/plugins/Utilities/test.py @@ -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: