2020-03-11 13:43:13 +00:00
|
|
|
import unittest
|
|
|
|
import irctokens
|
|
|
|
|
2020-03-11 17:38:30 +00:00
|
|
|
class FormatTestTags(unittest.TestCase):
|
2020-03-11 13:43:13 +00:00
|
|
|
def test(self):
|
|
|
|
line = irctokens.format("PRIVMSG", ["#channel", "hello"],
|
|
|
|
tags={"id": "\\" + " " + ";" + "\r\n"})
|
2020-03-11 23:32:52 +00:00
|
|
|
self.assertEqual(line, "@id=\\\\\\s\\:\\r\\n PRIVMSG #channel hello")
|
2020-03-11 13:43:13 +00:00
|
|
|
|
|
|
|
def test_missing(self):
|
|
|
|
line = irctokens.format("PRIVMSG", ["#channel", "hello"])
|
|
|
|
self.assertEqual(line, "PRIVMSG #channel hello")
|
|
|
|
|
|
|
|
def test_none_value(self):
|
|
|
|
line = irctokens.format("PRIVMSG", ["#channel", "hello"],
|
|
|
|
tags={"a": None})
|
|
|
|
self.assertEqual(line, "@a PRIVMSG #channel hello")
|
|
|
|
|
|
|
|
def test_empty_value(self):
|
|
|
|
line = irctokens.format("PRIVMSG", ["#channel", "hello"],
|
|
|
|
tags={"a": ""})
|
|
|
|
self.assertEqual(line, "@a PRIVMSG #channel hello")
|
|
|
|
|
2020-03-11 17:38:30 +00:00
|
|
|
class FormatTestSource(unittest.TestCase):
|
2020-03-11 13:43:13 +00:00
|
|
|
def test(self):
|
|
|
|
line = irctokens.format("PRIVMSG", ["#channel", "hello"],
|
|
|
|
source="nick!user@host")
|
|
|
|
self.assertEqual(line, ":nick!user@host PRIVMSG #channel hello")
|
|
|
|
|
2020-03-11 17:38:30 +00:00
|
|
|
class FormatTestCommand(unittest.TestCase):
|
2020-03-11 13:43:13 +00:00
|
|
|
def test_lowercase(self):
|
|
|
|
line = irctokens.format("privmsg")
|
|
|
|
self.assertEqual(line, "PRIVMSG")
|
|
|
|
|
2020-03-11 17:38:30 +00:00
|
|
|
class FormatTestTrailing(unittest.TestCase):
|
2020-03-11 13:43:13 +00:00
|
|
|
def test_space(self):
|
|
|
|
line = irctokens.format("PRIVMSG", ["#channel", "hello world"])
|
|
|
|
self.assertEqual(line, "PRIVMSG #channel :hello world")
|
|
|
|
|
|
|
|
def test_no_space(self):
|
|
|
|
line = irctokens.format("PRIVMSG", ["#channel", "helloworld"])
|
|
|
|
self.assertEqual(line, "PRIVMSG #channel helloworld")
|
2020-03-11 23:05:11 +00:00
|
|
|
|
|
|
|
class FormatTestSpacedArg(unittest.TestCase):
|
|
|
|
def test(self):
|
2020-03-11 23:38:36 +00:00
|
|
|
def _inner():
|
|
|
|
irctokens.format("USER", ["user", "0 *", "real name"])
|
|
|
|
self.assertRaises(ValueError, _inner)
|