1### 2# Copyright (c) 2002-2005, Jeremiah Fincher 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are met: 7# 8# * Redistributions of source code must retain the above copyright notice, 9# this list of conditions, and the following disclaimer. 10# * Redistributions in binary form must reproduce the above copyright notice, 11# this list of conditions, and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# * Neither the name of the author of this software nor the name of 14# contributors to this software may be used to endorse or promote products 15# derived from this software without specific prior written consent. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28### 29 30from supybot.test import * 31 32import supybot.irclib as irclib 33from supybot.utils.iter import all 34import supybot.ircutils as ircutils 35 36class holder: 37 users = set(map(str, range(1000))) 38 39class FunctionsTestCase(SupyTestCase): 40 class irc: 41 class state: 42 channels = {'#foo': holder()} 43 nick = 'foobar' 44 network = 'testnet' 45 46 @retry() 47 def testStandardSubstitute(self): 48 f = ircutils.standardSubstitute 49 msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy') 50 s = f(self.irc, msg, '$rand') 51 try: 52 int(s) 53 except ValueError: 54 self.fail('$rand wasn\'t an int.') 55 s = f(self.irc, msg, '$randomInt') 56 try: 57 int(s) 58 except ValueError: 59 self.fail('$randomint wasn\'t an int.') 60 self.assertEqual(f(self.irc, msg, '$botnick'), self.irc.nick) 61 self.assertEqual(f(self.irc, msg, '$who'), msg.nick) 62 self.assertEqual(f(self.irc, msg, '$WHO'), 63 msg.nick, 'stand. sub. not case-insensitive.') 64 self.assertEqual(f(self.irc, msg, '$nick'), msg.nick) 65 self.assertNotEqual(f(self.irc, msg, '$randomdate'), '$randomdate') 66 q = f(self.irc,msg,'$randomdate\t$randomdate') 67 dl = q.split('\t') 68 if dl[0] == dl[1]: 69 self.fail ('Two $randomdates in the same string were the same') 70 q = f(self.irc, msg, '$randomint\t$randomint') 71 dl = q.split('\t') 72 if dl[0] == dl[1]: 73 self.fail ('Two $randomints in the same string were the same') 74 self.assertNotEqual(f(self.irc, msg, '$today'), '$today') 75 self.assertNotEqual(f(self.irc, msg, '$now'), '$now') 76 n = f(self.irc, msg, '$randnick') 77 self.failUnless(n in self.irc.state.channels['#foo'].users) 78 n = f(self.irc, msg, '$randomnick') 79 self.failUnless(n in self.irc.state.channels['#foo'].users) 80 n = f(self.irc, msg, '$randomnick '*100) 81 L = n.split() 82 self.failIf(all(L[0].__eq__, L), 'all $randomnicks were the same') 83 c = f(self.irc, msg, '$channel') 84 self.assertEqual(c, msg.args[0]) 85 86 net = f(self.irc, msg, '$network') 87 self.assertEqual(net, self.irc.network) 88 89 90 91 92 93 94 95 96