mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Fixed some mircColors indiscretions and added a test for the new (proper) behavior.
This commit is contained in:
parent
fb730d72a1
commit
7a281d5e4b
@ -199,38 +199,39 @@ def bold(s):
|
|||||||
|
|
||||||
mircColors = {
|
mircColors = {
|
||||||
None: '',
|
None: '',
|
||||||
'white': '0',
|
'white': 0,
|
||||||
'black': '1',
|
'black': 1,
|
||||||
'blue': '2',
|
'blue': 2,
|
||||||
'green': '3',
|
'green': 3,
|
||||||
'red': '4',
|
'red': 4,
|
||||||
'brown': '5',
|
'brown': 5,
|
||||||
'purple': '6',
|
'purple': 6,
|
||||||
'orange': '7',
|
'orange': 7,
|
||||||
'yellow': '8',
|
'yellow': 8,
|
||||||
'light green': '9',
|
'light green': 9,
|
||||||
'teal': '10',
|
'teal': 10,
|
||||||
'light blue': '11',
|
'light blue': 11,
|
||||||
'dark blue': '12',
|
'dark blue': 12,
|
||||||
'pink': '13',
|
'pink': 13,
|
||||||
'dark grey': '14',
|
'dark grey': 14,
|
||||||
'light grey': '15',
|
'light grey': 15,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (k, v) in mircColors.items():
|
for (k, v) in mircColors.items():
|
||||||
if v: # Ignore empty string for None.
|
if k is not None: # Ignore empty string for None.
|
||||||
i = int(v)
|
mircColors[v] = k
|
||||||
mircColors[v] = i
|
|
||||||
mircColors[i] = i
|
|
||||||
|
|
||||||
def mircColor(s, fg=None, bg=None):
|
def mircColor(s, fg=None, bg=None):
|
||||||
"""Returns s, with the appropriate mIRC color codes applied."""
|
"""Returns s, with the appropriate mIRC color codes applied."""
|
||||||
if fg is None and bg is None:
|
if fg is None and bg is None:
|
||||||
return s
|
return s
|
||||||
elif bg is None:
|
fg = mircColors[fg]
|
||||||
return '\x03%s%s\x03' % (mircColors[fg], s)
|
if bg is None:
|
||||||
|
return '\x03%s%s\x03' % (fg, s)
|
||||||
else:
|
else:
|
||||||
return '\x03%s,%s%s\x03' % (mircColors[fg], mircColors[bg], s)
|
if isinstance(bg, str):
|
||||||
|
bg = mircColors[bg]
|
||||||
|
return '\x03%s,%s%s\x03' % (fg, bg, s)
|
||||||
|
|
||||||
|
|
||||||
def isValidArgument(s):
|
def isValidArgument(s):
|
||||||
|
@ -76,18 +76,22 @@ class FunctionsTestCase(unittest.TestCase):
|
|||||||
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',
|
self.assertEqual('\x030foo\x03', ircutils.mircColor(s, 'white'))
|
||||||
ircutils.mircColor(s, 'white'))
|
self.assertEqual('\x031,2foo\x03',ircutils.mircColor(s,'black','blue'))
|
||||||
self.assertEqual('\x031,2foo\x03',
|
self.assertEqual('\x03,3foo\x03', ircutils.mircColor(s, None, 'green'))
|
||||||
ircutils.mircColor(s, 'black', 'blue'))
|
|
||||||
self.assertEqual('\x03,3foo\x03',
|
|
||||||
ircutils.mircColor(s, None, 'green'))
|
|
||||||
# Test keyword args
|
# Test keyword args
|
||||||
self.assertEqual('\x034foo\x03', ircutils.mircColor(s, fg='red'))
|
self.assertEqual('\x034foo\x03', ircutils.mircColor(s, fg='red'))
|
||||||
self.assertEqual('\x03,5foo\x03', ircutils.mircColor(s, bg='brown'))
|
self.assertEqual('\x03,5foo\x03', ircutils.mircColor(s, bg='brown'))
|
||||||
self.assertEqual('\x036,7foo\x03',
|
self.assertEqual('\x036,7foo\x03',
|
||||||
ircutils.mircColor(s, bg='orange', fg='purple'))
|
ircutils.mircColor(s, bg='orange', fg='purple'))
|
||||||
|
|
||||||
|
def testMircColors(self):
|
||||||
|
# Make sure all (k, v) pairs are also (v, k) pairs.
|
||||||
|
for (k, v) in ircutils.mircColors.items():
|
||||||
|
if k:
|
||||||
|
self.assertEqual(ircutils.mircColors[v], k)
|
||||||
|
|
||||||
|
|
||||||
def testSafeArgument(self):
|
def testSafeArgument(self):
|
||||||
s = 'I have been running for 9 seconds'
|
s = 'I have been running for 9 seconds'
|
||||||
bolds = ircutils.bold(s)
|
bolds = ircutils.bold(s)
|
||||||
|
Loading…
Reference in New Issue
Block a user