Let's make sure to zfill those digits before we mircColor.

This commit is contained in:
Jeremy Fincher 2004-07-22 20:57:46 +00:00
parent d7df686b0c
commit c064aa1155
2 changed files with 9 additions and 6 deletions

View File

@ -305,10 +305,13 @@ def mircColor(s, fg=None, bg=None):
if fg is None or isinstance(fg, str): if fg is None or isinstance(fg, str):
fg = mircColors[fg] fg = mircColors[fg]
if bg is None: if bg is None:
fg = str(fg).zfill(2)
return '\x03%s%s\x03' % (fg, s) return '\x03%s%s\x03' % (fg, s)
else: else:
# We don't need to zfill fg here because the comma delimits it.
if isinstance(bg, str): if isinstance(bg, str):
bg = mircColors[bg] bg = mircColors[bg]
bg = str(bg).zfill(2)
return '\x03%s,%s%s\x03' % (fg, bg, s) return '\x03%s,%s%s\x03' % (fg, bg, s)
def canonicalColor(s, bg=False, shift=0): def canonicalColor(s, bg=False, shift=0):

View File

@ -108,13 +108,13 @@ class FunctionsTestCase(SupyTestCase):
s = 'foo' s = 'foo'
self.assertEqual(s, ircutils.mircColor(s)) self.assertEqual(s, ircutils.mircColor(s))
# Test positional args # Test positional args
self.assertEqual('\x030foo\x03', ircutils.mircColor(s, 'white')) self.assertEqual('\x0300foo\x03', ircutils.mircColor(s, 'white'))
self.assertEqual('\x031,2foo\x03',ircutils.mircColor(s,'black','blue')) self.assertEqual('\x031,02foo\x03',ircutils.mircColor(s,'black','blue'))
self.assertEqual('\x03,3foo\x03', ircutils.mircColor(s, None, 'green')) self.assertEqual('\x03,03foo\x03', ircutils.mircColor(s, None, 'green'))
# Test keyword args # Test keyword args
self.assertEqual('\x034foo\x03', ircutils.mircColor(s, fg='red')) self.assertEqual('\x0304foo\x03', ircutils.mircColor(s, fg='red'))
self.assertEqual('\x03,5foo\x03', ircutils.mircColor(s, bg='brown')) self.assertEqual('\x03,05foo\x03', ircutils.mircColor(s, bg='brown'))
self.assertEqual('\x036,7foo\x03', self.assertEqual('\x036,07foo\x03',
ircutils.mircColor(s, bg='orange', fg='purple')) ircutils.mircColor(s, bg='orange', fg='purple'))
def testMircColors(self): def testMircColors(self):