mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
add tests for appropriate behavior
Signed-off-by: James Vega <jamessan@users.sourceforge.net>
(cherry picked from commit 8d64d08645
)
This commit is contained in:
parent
7869b962d1
commit
fb8d0d320a
@ -62,18 +62,18 @@ def getChannel(msg, args=()):
|
||||
raise callbacks.Error, 'Command must be sent in a channel or ' \
|
||||
'include a channel in its arguments.'
|
||||
|
||||
def getArgs(args, required=1, optional=0):
|
||||
def getArgs(args, required=1, optional=0, wildcard=0):
|
||||
if len(args) < required:
|
||||
raise callbacks.ArgumentError
|
||||
if len(args) < required + optional:
|
||||
ret = list(args) + ([''] * (required + optional - len(args)))
|
||||
elif len(args) >= required + optional:
|
||||
ret = list(args[:required + optional - 1])
|
||||
ret.append(' '.join(args[required + optional - 1:]))
|
||||
if len(ret) == 1:
|
||||
return ret[0]
|
||||
else:
|
||||
return ret
|
||||
if not wildcard:
|
||||
ret = list(args[:required + optional - 1])
|
||||
ret.append(' '.join(args[required + optional - 1:]))
|
||||
else:
|
||||
ret = list(args)
|
||||
return ret
|
||||
|
||||
class AliasError(Exception):
|
||||
pass
|
||||
@ -119,11 +119,9 @@ def makeNewAlias(name, alias):
|
||||
channel = getChannel(msg, args)
|
||||
alias = alias.replace('$channel', channel)
|
||||
tokens = callbacks.tokenize(alias)
|
||||
if not wildcard and biggestDollar or biggestAt:
|
||||
args = getArgs(args, required=biggestDollar, optional=biggestAt)
|
||||
# Gotta have a mutable sequence (for replace).
|
||||
if biggestDollar + biggestAt == 1: # We got a string, no tuple.
|
||||
args = [args]
|
||||
if biggestDollar or biggestAt:
|
||||
args = getArgs(args, required=biggestDollar, optional=biggestAt,
|
||||
wildcard=wildcard)
|
||||
def regexpReplace(m):
|
||||
idx = int(m.group(1))
|
||||
return args[idx-1]
|
||||
|
@ -85,7 +85,11 @@ class AliasTestCase(ChannelPluginTestCase):
|
||||
self.assertNotError('alias add swap "echo $2 $1 $*"')
|
||||
self.assertResponse('swap 1 2 3 4 5', '2 1 3 4 5')
|
||||
self.assertError('alias add foo "echo $1 @1 $*"')
|
||||
|
||||
self.assertNotError('alias add moo echo $1 $*')
|
||||
self.assertError('moo')
|
||||
self.assertResponse('moo foo', 'foo')
|
||||
self.assertResponse('moo foo bar', 'foo bar')
|
||||
|
||||
def testChannel(self):
|
||||
self.assertNotError('alias add channel echo $channel')
|
||||
self.assertResponse('alias channel', self.channel)
|
||||
|
Loading…
Reference in New Issue
Block a user