from hisscl import lexer import unittest import io class TestComments(unittest.TestCase): def test_double_slash(self): tok, pos, lit = lexer.Lexer(io.StringIO('// this should be ignored'), 'TestComments.test_double_slash').scan() self.assertEqual(tok, lexer.Token.EOF) self.assertEqual(lit, '') def test_pound(self): tok, pos, lit = lexer.Lexer(io.StringIO('# this should be ignored'), 'TestComments.test_pound').scan() self.assertEqual(tok, lexer.Token.EOF) self.assertEqual(lit, '') def test_multiline(self): tok, pos, lit = lexer.Lexer(io.StringIO('/* this\nshould\nbe\nignored */'), 'TestComments.test_multiline').scan() self.assertEqual(tok, lexer.Token.EOF) self.assertEqual(lit, '') class TestOperators(unittest.TestCase): def test_lt(self): tok, pos, lit = lexer.Lexer(io.StringIO('<'), 'TestOperators.test_lt').scan() self.assertEqual(tok, lexer.Token.OPERATOR) self.assertEqual(lit, '<') def test_div(self): tok, pos, lit = lexer.Lexer(io.StringIO('/'), 'TestOperators.test_div').scan() self.assertEqual(tok, lexer.Token.OPERATOR) self.assertEqual(lit, '/') def test_multichar(self): tok, pos, lit = lexer.Lexer(io.StringIO('<='), 'TestOperators.test_multichar').scan() self.assertEqual(tok, lexer.Token.OPERATOR) self.assertEqual(lit, '<=') def test_ellipsis(self): tok, pos, lit = lexer.Lexer(io.StringIO('...'), 'TestOperators.test_ellipsis').scan() self.assertEqual(tok, lexer.Token.ELLIPSIS) self.assertEqual(lit, '...') def test_invalid_ellipsis(self): with self.assertRaises(lexer.ExpectedError) as ctx: lexer.Lexer(io.StringIO('..'), 'TestOperators.test_invalid_ellipsis').scan() self.assertIn("expected .", str(ctx.exception)) self.assertIn("got EOF", str(ctx.exception)) class TestHeredoc(unittest.TestCase): def test_heredoc(self): tok, pos, lit = lexer.Lexer(io.StringIO('<