mirror of https://github.com/jesopo/irctokens
add .clear() to StatefulDecoder too (and tests for .clear() on both statefuls)
This commit is contained in:
parent
4b9ff45921
commit
53d056c3e0
|
@ -4,8 +4,14 @@ from .protocol import Line, tokenise
|
|||
class StatefulDecoder(object):
|
||||
def __init__(self, fallback: str="iso-8859"):
|
||||
self._fallback = fallback
|
||||
self.clear()
|
||||
|
||||
def clear(self):
|
||||
self._buffer = b""
|
||||
|
||||
def pending(self) -> bytes:
|
||||
return self._buffer
|
||||
|
||||
def push(self, data: bytes) -> typing.Optional[typing.List[Line]]:
|
||||
if not data:
|
||||
return None
|
||||
|
|
|
@ -43,3 +43,10 @@ class TestEmpty(unittest.TestCase):
|
|||
d.push(b"PRIVMSG #channel hello")
|
||||
lines = d.push(b"")
|
||||
self.assertIsNone(lines)
|
||||
|
||||
class TestClear(unittest.TestCase):
|
||||
def test(self):
|
||||
d = irctokens.StatefulDecoder()
|
||||
d.push(b"PRIVMSG ")
|
||||
d.clear()
|
||||
self.assertEqual(d.pending(), b"")
|
||||
|
|
|
@ -31,3 +31,10 @@ class TestPop(unittest.TestCase):
|
|||
e.push(line)
|
||||
lines = e.pop(1)
|
||||
self.assertEqual(len(lines), 0)
|
||||
|
||||
class TestClear(unittest.TetsCase):
|
||||
def test(self):
|
||||
e = irctokens.StatefulEncoder()
|
||||
e.push(irctokens.tokenise("PRIVMSG #channel hello")
|
||||
e.clear()
|
||||
self.assertEqual(e.pending(), b"")
|
||||
|
|
Loading…
Reference in New Issue