2020-03-11 15:17:17 +00:00
|
|
|
import unittest
|
|
|
|
import irctokens
|
|
|
|
|
2020-03-11 17:38:30 +00:00
|
|
|
class EncodeTestPush(unittest.TestCase):
|
2020-03-11 15:17:17 +00:00
|
|
|
def test(self):
|
|
|
|
e = irctokens.StatefulEncoder()
|
|
|
|
line = irctokens.tokenise("PRIVMSG #channel hello")
|
|
|
|
e.push(line)
|
|
|
|
self.assertEqual(e.pending(), b"PRIVMSG #channel hello\r\n")
|
|
|
|
|
2020-03-11 17:38:30 +00:00
|
|
|
class EncodeTestPop(unittest.TestCase):
|
2020-03-11 16:30:11 +00:00
|
|
|
def test_partial(self):
|
2020-03-11 15:17:17 +00:00
|
|
|
e = irctokens.StatefulEncoder()
|
|
|
|
line = irctokens.tokenise("PRIVMSG #channel hello")
|
|
|
|
e.push(line)
|
|
|
|
e.pop(len(b"PRIVMSG #channel hello"))
|
|
|
|
self.assertEqual(e.pending(), b"\r\n")
|
2020-03-11 16:30:11 +00:00
|
|
|
|
|
|
|
def test_returned(self):
|
|
|
|
e = irctokens.StatefulEncoder()
|
|
|
|
line = irctokens.tokenise("PRIVMSG #channel hello")
|
|
|
|
e.push(line)
|
|
|
|
e.push(line)
|
|
|
|
lines = e.pop(len(b"PRIVMSG #channel hello\r\nPRIVMSG"))
|
|
|
|
self.assertEqual(len(lines), 1)
|
|
|
|
self.assertEqual(lines[0], line)
|
|
|
|
|
|
|
|
def test_none_returned(self):
|
|
|
|
e = irctokens.StatefulEncoder()
|
|
|
|
line = irctokens.tokenise("PRIVMSG #channel hello")
|
|
|
|
e.push(line)
|
|
|
|
lines = e.pop(1)
|
|
|
|
self.assertEqual(len(lines), 0)
|
2020-03-11 17:09:54 +00:00
|
|
|
|
2020-03-11 17:38:30 +00:00
|
|
|
class EncodeTestClear(unittest.TestCase):
|
2020-03-11 17:09:54 +00:00
|
|
|
def test(self):
|
|
|
|
e = irctokens.StatefulEncoder()
|
2020-03-11 17:13:10 +00:00
|
|
|
e.push(irctokens.tokenise("PRIVMSG #channel hello"))
|
2020-03-11 17:09:54 +00:00
|
|
|
e.clear()
|
|
|
|
self.assertEqual(e.pending(), b"")
|
2020-03-11 17:38:30 +00:00
|
|
|
|
|
|
|
class EncodeTestEncoding(unittest.TestCase):
|
|
|
|
def test(self):
|
|
|
|
e = irctokens.StatefulEncoder(encoding="iso-8859-2")
|
|
|
|
e.push(irctokens.tokenise("PRIVMSG #channel :hello Č"))
|
|
|
|
self.assertEqual(e.pending(),
|
|
|
|
"PRIVMSG #channel :hello Č\r\n".encode("iso-8859-2"))
|