3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

Add validate-hostname tests from ircdocs/parser-tests

This commit is contained in:
James Lu 2019-09-10 19:21:56 -07:00
parent b803c23b57
commit 462fa91622

View File

@ -23,6 +23,8 @@ class MessageParserTest(unittest.TestCase):
cls.USER_HOST_SPLIT_TEST_DATA = yaml.safe_load(f) cls.USER_HOST_SPLIT_TEST_DATA = yaml.safe_load(f)
with open(PARSER_DATA_PATH / 'mask-match.yaml') as f: with open(PARSER_DATA_PATH / 'mask-match.yaml') as f:
cls.MASK_MATCH_TEST_DATA = yaml.safe_load(f) cls.MASK_MATCH_TEST_DATA = yaml.safe_load(f)
with open(PARSER_DATA_PATH / 'validate-hostname.yaml') as f:
cls.VALIDATE_HOSTNAME_TEST_DATA = yaml.safe_load(f)
def testMessageSplit(self): def testMessageSplit(self):
for testdata in self.MESSAGE_SPLIT_TEST_DATA['tests']: for testdata in self.MESSAGE_SPLIT_TEST_DATA['tests']:
@ -92,5 +94,14 @@ class MessageParserTest(unittest.TestCase):
with self.subTest(): with self.subTest():
self.assertFalse(utils.match_text(mask, fail)) self.assertFalse(utils.match_text(mask, fail))
def testValidateHostname(self):
for test in self.VALIDATE_HOSTNAME_TEST_DATA['tests']:
with self.subTest():
self.assertEqual(test['valid'], IRCCommonProtocol.is_server_name(test['host']),
"Failed test for %r; should be %s" % (test['host'], test['valid']))
# N.B. skipping msg-join tests because PyLink doesn't think about messages that way
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()