mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Make different randomdates and randomints in the same string give different values
add tests to make sure it happens
This commit is contained in:
parent
ff57e4b67b
commit
def70e1ff5
@ -316,6 +316,13 @@ _whoRe = re.compile ("\$who", re.I)
|
|||||||
_botnickRe = re.compile("\$botnick", re.I)
|
_botnickRe = re.compile("\$botnick", re.I)
|
||||||
_todayRe = re.compile("\$today", re.I)
|
_todayRe = re.compile("\$today", re.I)
|
||||||
_nowRe = re.compile("\$now", re.I)
|
_nowRe = re.compile("\$now", re.I)
|
||||||
|
def randInt(m):
|
||||||
|
return str(random.randint(-1000, 1000))
|
||||||
|
|
||||||
|
def randDate(m):
|
||||||
|
t = pow(2,30)*random.random()+time.time()/4.0
|
||||||
|
return time.ctime(t)
|
||||||
|
|
||||||
def standardSubstitute(irc, msg, text):
|
def standardSubstitute(irc, msg, text):
|
||||||
"""Do the standard set of substitutions on text, and return it"""
|
"""Do the standard set of substitutions on text, and return it"""
|
||||||
if ircutils.isChannel(msg.args[0]):
|
if ircutils.isChannel(msg.args[0]):
|
||||||
@ -327,9 +334,8 @@ def standardSubstitute(irc, msg, text):
|
|||||||
text = _randomnickRe.sub(user, text)
|
text = _randomnickRe.sub(user, text)
|
||||||
else:
|
else:
|
||||||
text = _randomnickRe.sub('anyone', text)
|
text = _randomnickRe.sub('anyone', text)
|
||||||
t = pow(2,30)*random.random()+time.time()/4.0
|
text = _randomdateRe.sub(randDate, text)
|
||||||
text = _randomdateRe.sub(time.ctime(t), text)
|
text = _randomintRe.sub(randInt, text)
|
||||||
text = _randomintRe.sub(str(random.randint(-1000, 1000)), text)
|
|
||||||
text = _whoRe.sub(msg.nick, text)
|
text = _whoRe.sub(msg.nick, text)
|
||||||
text = _botnickRe.sub(irc.nick, text)
|
text = _botnickRe.sub(irc.nick, text)
|
||||||
text = _todayRe.sub(time.ctime(), text)
|
text = _todayRe.sub(time.ctime(), text)
|
||||||
|
@ -100,21 +100,24 @@ class FunctionsTestCase(unittest.TestCase):
|
|||||||
nick = 'foobar'
|
nick = 'foobar'
|
||||||
def testStandardSubstitute(self):
|
def testStandardSubstitute(self):
|
||||||
msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
|
msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
|
||||||
s = plugins.standardSubstitute(self.irc, msg, '$randomint')
|
|
||||||
try:
|
|
||||||
int(s)
|
|
||||||
except ValueError:
|
|
||||||
self.fail('$randomnick wasn\'t an int.')
|
|
||||||
s = plugins.standardSubstitute(self.irc, msg, '$randomInt')
|
s = plugins.standardSubstitute(self.irc, msg, '$randomInt')
|
||||||
try:
|
try:
|
||||||
int(s)
|
int(s)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.fail('$randomnick wasn\'t an int.')
|
self.fail('$randomint wasn\'t an int.')
|
||||||
self.assertEqual(plugins.standardSubstitute(self.irc, msg, '$botnick'),
|
self.assertEqual(plugins.standardSubstitute(self.irc, msg, '$botnick'),
|
||||||
self.irc.nick)
|
self.irc.nick)
|
||||||
self.assertEqual(plugins.standardSubstitute(self.irc, msg, '$who'),
|
self.assertEqual(plugins.standardSubstitute(self.irc, msg, '$who'),
|
||||||
msg.nick)
|
msg.nick)
|
||||||
self.assert_(plugins.standardSubstitute(self.irc, msg, '$randomdate'))
|
self.assert_(plugins.standardSubstitute(self.irc, msg, '$randomdate'))
|
||||||
|
q = plugins.standardSubstitute(self.irc, msg, '$randomdate\t$randomdate')
|
||||||
|
dl = q.split('\t')
|
||||||
|
if dl[0] == dl[1]:
|
||||||
|
self.fail ('Two $randomdates in the same string were the same')
|
||||||
|
q = plugins.standardSubstitute(self.irc, msg, '$randomint\t$randomint')
|
||||||
|
dl = q.split('\t')
|
||||||
|
if dl[0] == dl[1]:
|
||||||
|
self.fail ('Two $randomints in the same string were the same')
|
||||||
self.assert_(plugins.standardSubstitute(self.irc, msg, '$today'))
|
self.assert_(plugins.standardSubstitute(self.irc, msg, '$today'))
|
||||||
self.assert_(plugins.standardSubstitute(self.irc, msg, '$now'))
|
self.assert_(plugins.standardSubstitute(self.irc, msg, '$now'))
|
||||||
n = plugins.standardSubstitute(self.irc, msg, '$randomnick')
|
n = plugins.standardSubstitute(self.irc, msg, '$randomnick')
|
||||||
|
Loading…
Reference in New Issue
Block a user