Fix replacement of my/me not obeying word boundaries. Also created tests to

ensure it stays fixed.
This commit is contained in:
James Vega 2003-10-29 20:27:09 +00:00
parent 8cc9620a4b
commit afc74b96f0
2 changed files with 39 additions and 16 deletions

View File

@ -154,10 +154,9 @@ class FunDB(callbacks.Privmsg):
else:
(id, insult) = cursor.fetchone()
nick = nick.strip()
if nick in (irc.nick, 'yourself', 'me'):
insultee = msg.nick
else:
insultee = nick
nick = re.sub(r'\b(?:me|%s)\b' % irc.nick, msg.nick, nick)
nick = re.sub(r'\bmy\b', '%s\'s' % msg.nick, nick)
insultee = nick
insult = insult.replace("$who", insultee)
s = '%s: %s (#%s)' % (insultee, insult, id)
irc.reply(msg, s)
@ -427,12 +426,11 @@ class FunDB(callbacks.Privmsg):
irc.error(msg, 'There are currently no available larts.')
else:
(id, lart) = cursor.fetchone()
if nick in (irc.nick, 'me'):
lartee = msg.nick
elif 'my' in nick:
lartee = nick.replace('my', '%s\'s' % msg.nick)
else:
lartee = nick
nick = re.sub(r'\b(?:me|%s)\b' % irc.nick, msg.nick, nick)
reason = re.sub(r'\b(?:me|%s)\b' % irc.nick, msg.nick, reason)
nick = re.sub(r'\bmy\b', '%s\'s' % msg.nick, nick)
reason = re.sub(r'\bmy\b', '%s\'s' % msg.nick, reason)
lartee = nick
lart = lart.replace("$who", lartee)
if len(reason) > 0:
s = '%s for %s (#%s)' % (lart, reason, id)
@ -480,12 +478,11 @@ class FunDB(callbacks.Privmsg):
irc.error(msg, 'There are currently no available praises.')
else:
(id, praise) = cursor.fetchone()
if nick in (msg.nick, 'me'):
praisee = msg.nick
elif 'my' in nick:
praisee = nick.replace('my', '%s\'s' % msg.nick)
else:
praisee = nick
nick = re.sub(r'\b(?:me|%s)\b' % irc.nick, msg.nick, nick)
reason = re.sub(r'\b(?:me|%s)\b' % irc.nick, msg.nick, reason)
nick = re.sub(r'\bmy\b', '%s\'s' % msg.nick, nick)
reason = re.sub(r'\bmy\b', '%s\'s' % msg.nick, reason)
praisee = nick
praise = praise.replace("$who", praisee)
if len(reason) > 0:
s = '%s for %s (#%s)' % (praise, reason, id)

View File

@ -70,6 +70,32 @@ if sqlite is not None:
self.assertRegexp('num lart', 'currently 0')
self.assertError('lart jemfinch')
def testMyMeReplacement(self):
self.assertNotError('add lart jabs $who')
self.assertNotError('add praise pets $who')
self.assertNotError('add insult foo')
self.assertRegexp('lart me', 'jabs test \(#1\)')
self.assertRegexp('praise me', 'pets test \(#1\)')
self.assertRegexp('insult me', 'test: foo \(#1\)')
self.assertRegexp('lart whamme', 'jabs whamme \(#1\)')
self.assertRegexp('praise whamme', 'pets whamme \(#1\)')
self.assertRegexp('insult whamme', 'whamme: foo \(#1\)')
self.assertRegexp('lart my knee', 'jabs test\'s knee \(#1\)')
self.assertRegexp('praise my knee', 'pets test\'s knee \(#1\)')
self.assertRegexp('insult my knee', 'test\'s knee: foo \(#1\)')
self.assertRegexp('lart sammy the snake', 'jabs sammy the snake'\
' \(#1\)')
self.assertRegexp('praise sammy the snake', 'pets sammy the snake'\
' \(#1\)')
self.assertRegexp('insult sammy the snake', 'sammy the snake: foo'\
' \(#1\)')
self.assertRegexp('lart me for my', 'jabs test for test\'s \(#1\)')
self.assertRegexp('praise me for my','pets test for test\'s '\
'\(#1\)')
self.assertNotError('remove lart 1')
self.assertNotError('remove praise 1')
self.assertNotError('remove insult 1')
def testExcuse(self):
self.assertNotError('add excuse Power failure')
self.assertResponse('excuse', 'Power failure (#1)')