Filter: strip spaces in "unbinary" (Closes #1166)

This makes _squish() a shared function to prevent code duplication. Also, remove duplicate testUnbinary function, and add tests for this.
This commit is contained in:
James Lu 2015-09-09 19:32:15 -07:00
parent 879ce460e9
commit ed493e6504
2 changed files with 6 additions and 5 deletions

View File

@ -118,14 +118,16 @@ class Filter(callbacks.Plugin):
irc.reply(self._hebrew_remover(text))
hebrew = wrap(hebrew, ['text'])
def _squish(self, text):
return ''.join(text.split())
@internationalizeDocstring
def squish(self, irc, msg, args, text):
"""<text>
Removes all the spaces from <text>.
"""
text = ''.join(text.split())
irc.reply(text)
irc.reply(self._squish(text))
squish = wrap(squish, ['text'])
@internationalizeDocstring
@ -182,6 +184,7 @@ class Filter(callbacks.Plugin):
Returns the character representation of binary <text>.
Assumes ASCII, 8 digits per character.
"""
text = self._squish(text) # Strip spaces.
try:
L = [chr(int(text[i:(i+8)], 2)) for i in range(0, len(text), 8)]
irc.reply(''.join(L))

View File

@ -86,13 +86,11 @@ class FilterTest(ChannelPluginTestCase):
def testBinary(self):
self.assertResponse('binary A', '01000001')
def testUnbinary(self):
self.assertResponse('unbinary 011011010110111101101111', 'moo')
def testUnbinary(self):
self.assertResponse('unbinary 011011010110111101101111', 'moo')
self.assertError('unbinary moo')
self.assertResponse('unbinary 01101101 01101111 01101111', 'moo')
def testRot13(self):
for s in map(str, range(1000, 1010)):