mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 06:04:21 +01:00
Made IrcString more efficient/better, added a test for it.
This commit is contained in:
parent
2f8b5370ab
commit
ce0002f454
@ -317,16 +317,9 @@ def shrinkList(L, sep='', limit=425):
|
||||
class IrcString(str):
|
||||
"""This class does case-insensitive comparison and hashing of nicks."""
|
||||
def __init__(self, s):
|
||||
s = str(s)
|
||||
self.original = s
|
||||
str.__init__(self, s)
|
||||
self.lowered = toLower(s)
|
||||
|
||||
def __repr__(self):
|
||||
return repr(self.original)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.original)
|
||||
|
||||
def __eq__(self, s):
|
||||
try:
|
||||
return toLower(s) == self.lowered
|
||||
|
@ -211,6 +211,15 @@ class IrcSetTestCase(unittest.TestCase):
|
||||
self.failIf('foo' in s)
|
||||
self.failIf('FOo' in s)
|
||||
|
||||
class IrcStringTestCase(unittest.TestCase):
|
||||
def test(self):
|
||||
self.assertEqual('#foo', ircutils.IrcString('#foo'))
|
||||
self.assertEqual('#foo', ircutils.IrcString('#FOO'))
|
||||
self.assertEqual('#FOO', ircutils.IrcString('#foo'))
|
||||
self.assertEqual('#FOO', ircutils.IrcString('#FOO'))
|
||||
self.assertEqual(hash(ircutils.IrcString('#FOO')),
|
||||
hash(ircutils.IrcString('#foo')))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user