Allow abbreviation in getLiteral.

This commit is contained in:
Jeremy Fincher 2004-10-26 23:17:58 +00:00
parent c809b7a14e
commit ba1bb34729
2 changed files with 14 additions and 4 deletions

View File

@ -475,10 +475,12 @@ def getMatch(irc, msg, args, state, regexp, errmsg):
irc.error(errmsg, Raise=True)
def getLiteral(irc, msg, args, state, literals, errmsg=None):
# ??? Should we allow abbreviations?
if isinstance(literals, basestring):
literals = (literals,)
if args[0] in literals:
state.args.append(args.pop(0))
abbrevs = utils.abbrev(literals)
if args[0] in abbrevs:
state.args.append(abbrevs[args.pop(0)])
elif errmsg is not None:
irc.error(errmsg, Raise=True)
else:
@ -710,7 +712,6 @@ class commalist(context):
args[:] = original
raise
class getopts(context):
"""The empty string indicates that no argument is taken; None indicates
that there is no converter for the argument."""

View File

@ -111,7 +111,16 @@ class CommandsTestCase(SupyTestCase):
self.assertState(spec, ['12,11,10,', '9'], [[12, 11, 10, 9]])
spec.append('int')
self.assertState(spec, ['12,11,10', '9'], [[12, 11, 10], 9])
def testLiteral(self):
spec = [('literal', ['foo', 'bar', 'baz'])]
self.assertState(spec, ['foo'], ['foo'])
self.assertState(spec, ['fo'], ['foo'])
self.assertState(spec, ['f'], ['foo'])
self.assertState(spec, ['bar'], ['bar'])
self.assertState(spec, ['baz'], ['baz'])
self.assertRaises(callbacks.ArgumentError,
self.assertState, spec, ['ba'], ['baz'])
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: