mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-07 19:49: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 ' \
|
raise callbacks.Error, 'Command must be sent in a channel or ' \
|
||||||
'include a channel in its arguments.'
|
'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:
|
if len(args) < required:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
if len(args) < required + optional:
|
if len(args) < required + optional:
|
||||||
ret = list(args) + ([''] * (required + optional - len(args)))
|
ret = list(args) + ([''] * (required + optional - len(args)))
|
||||||
elif len(args) >= required + optional:
|
elif len(args) >= required + optional:
|
||||||
ret = list(args[:required + optional - 1])
|
if not wildcard:
|
||||||
ret.append(' '.join(args[required + optional - 1:]))
|
ret = list(args[:required + optional - 1])
|
||||||
if len(ret) == 1:
|
ret.append(' '.join(args[required + optional - 1:]))
|
||||||
return ret[0]
|
else:
|
||||||
else:
|
ret = list(args)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
class AliasError(Exception):
|
class AliasError(Exception):
|
||||||
pass
|
pass
|
||||||
@ -119,11 +119,9 @@ def makeNewAlias(name, alias):
|
|||||||
channel = getChannel(msg, args)
|
channel = getChannel(msg, args)
|
||||||
alias = alias.replace('$channel', channel)
|
alias = alias.replace('$channel', channel)
|
||||||
tokens = callbacks.tokenize(alias)
|
tokens = callbacks.tokenize(alias)
|
||||||
if not wildcard and biggestDollar or biggestAt:
|
if biggestDollar or biggestAt:
|
||||||
args = getArgs(args, required=biggestDollar, optional=biggestAt)
|
args = getArgs(args, required=biggestDollar, optional=biggestAt,
|
||||||
# Gotta have a mutable sequence (for replace).
|
wildcard=wildcard)
|
||||||
if biggestDollar + biggestAt == 1: # We got a string, no tuple.
|
|
||||||
args = [args]
|
|
||||||
def regexpReplace(m):
|
def regexpReplace(m):
|
||||||
idx = int(m.group(1))
|
idx = int(m.group(1))
|
||||||
return args[idx-1]
|
return args[idx-1]
|
||||||
|
@ -85,6 +85,10 @@ class AliasTestCase(ChannelPluginTestCase):
|
|||||||
self.assertNotError('alias add swap "echo $2 $1 $*"')
|
self.assertNotError('alias add swap "echo $2 $1 $*"')
|
||||||
self.assertResponse('swap 1 2 3 4 5', '2 1 3 4 5')
|
self.assertResponse('swap 1 2 3 4 5', '2 1 3 4 5')
|
||||||
self.assertError('alias add foo "echo $1 @1 $*"')
|
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):
|
def testChannel(self):
|
||||||
self.assertNotError('alias add channel echo $channel')
|
self.assertNotError('alias add channel echo $channel')
|
||||||
|
Loading…
Reference in New Issue
Block a user