This repository has been archived on 2024-06-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
coffee.pygments/tests/test_irc_formatter.py
2023-03-29 21:11:12 +02:00

30 lines
954 B
Python

"""
Pygments IRC formatter tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from io import StringIO
from pygments.lexers import PythonLexer
from pygments.formatters import IRCFormatter
tokensource = list(PythonLexer().get_tokens("lambda x: 123"))
newlinetokensource = list(PythonLexer().get_tokens("from \\\n\\\n os import path\n"))
def test_correct_output():
hfmt = IRCFormatter()
houtfile = StringIO()
hfmt.format(tokensource, houtfile)
assert '\x0302lambda\x03 x: \x0302123\x03\n' == houtfile.getvalue()
def test_linecount_output():
hfmt = IRCFormatter(linenos = True)
houtfile = StringIO()
hfmt.format(newlinetokensource, houtfile)
expected_out = '0001: \x0302from\x03 \\\n0002: \\\n0003: \x1d\x0310os\x03\x1d \x0302import\x03 path\n0004: '
assert expected_out == houtfile.getvalue()