Fix for some bad tests; added support, fixed a long-latent bug that I thought was being tested for but wasn't.

This commit is contained in:
Jeremy Fincher 2003-10-09 05:00:56 +00:00
parent b63730975c
commit aa7efcbad9
2 changed files with 17 additions and 17 deletions

View File

@ -124,17 +124,19 @@ def findBiggestAt(alias):
def makeNewAlias(name, alias):
if findAliasCommand(name, alias):
raise RecursiveAlias
doChannel = '$channel' in alias
biggestDollar = findBiggestDollar(alias)
biggestAt = findBiggestAt(alias)
wildcard = '$*' in alias
if biggestAt and wildcard:
raise AliasError, 'Can\'t use $* and optional args (@1, etc.)'
def f(self, irc, msg, args):
alias_ = alias
if doChannel:
alias_ = alias.replace('$nick', msg.nick)
if '$channel' in alias:
channel = privmsgs.getChannel(msg, args)
alias_ = alias.replace('$channel', channel)
alias_ = alias_.replace('$channel', channel)
if not (biggestDollar or biggestAt or wildcard):
irc.reply(msg, alias_)
return
if not wildcard and biggestDollar or biggestAt:
args = privmsgs.getArgs(args, needed=biggestDollar,
optional=biggestAt)
@ -144,15 +146,10 @@ def makeNewAlias(name, alias):
def replace(m):
idx = int(m.group(1))
return utils.dqrepr(args[idx-1])
#debug.printf((args, alias_))
alias_ = dollarRe.sub(replace, alias_)
#debug.printf((args, alias_))
args = args[biggestDollar:]
#debug.printf((args, alias_))
alias_ = atRe.sub(replace, alias_)
#debug.printf((args, alias_))
alias_ = alias_.replace('$*', ' '.join(map(utils.dqrepr, args)))
#debug.printf((args, alias_))
self.Proxy(irc.irc, msg, callbacks.tokenize(alias_))
#f = new.function(f.func_code, f.func_globals, alias)
f.__doc__ ='<an alias, %s>\n\nAlias for %r' % \

View File

@ -66,7 +66,7 @@ class FunctionsTest(unittest.TestCase):
self.assertEqual(Alias.findBiggestDollar('$10 bar $1'), 10)
class AliasTestCase(PluginTestCase, PluginDocumentation):
class AliasTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('Alias', 'FunCommands', 'Utilities', 'MiscCommands')
def testAliasHelp(self):
self.assertNotError('alias slashdot foo')
@ -76,12 +76,7 @@ class AliasTestCase(PluginTestCase, PluginDocumentation):
def testSimpleAlias(self):
pi = '3.1456926535897932384626433832795028841971693'
self.assertNotError('alias pi %s' % pi)
self.assertReponse('pi', pi)
def testSimpleAlias(self):
s = 'foobar'
self.assertNotError('alias foo "rot13 %s"' % s)
self.assertResponse('foo', s.encode('rot13'))
self.assertResponse('pi', pi)
def testDollars(self):
self.assertNotError('alias rot26 "rot13 [rot13 $1]"')
@ -116,9 +111,17 @@ class AliasTestCase(PluginTestCase, PluginDocumentation):
self.assertNotError('mytell #foo bugs')
self.assertNoResponse('blah blah blah', 2)
def testChannel(self):
self.assertNotError('alias channel $channel')
self.assertResponse('channel', self.channel)
def testNick(self):
self.assertNotError('alias sendingnick $nick')
self.assertResponse('sendingnick', self.nick)
def testAddRemoveAlias(self):
cb = self.irc.getCallback('Alias')
cb.addAlias(self.irc, 'foobar', 'rot13 foobar', freeze=True)
cb.addAlias(self.irc, 'foobar', 'sbbone', freeze=True)
self.assertResponse('foobar', 'sbbone')
self.assertRaises(Alias.AliasError, cb.removeAlias, 'foobar')
cb.removeAlias('foobar', evenIfFrozen=True)