| 1 |
""" |
| 2 |
Pygments IRC formatter tests |
| 3 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4 |
|
| 5 |
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS. |
| 6 |
:license: BSD, see LICENSE for details. |
| 7 |
""" |
| 8 |
|
| 9 |
from io import StringIO |
| 10 |
|
| 11 |
from pygments.lexers import PythonLexer |
| 12 |
from pygments.formatters import IRCFormatter |
| 13 |
|
| 14 |
tokensource = list(PythonLexer().get_tokens("lambda x: 123")) |
| 15 |
newlinetokensource = list(PythonLexer().get_tokens("from \\\n\\\n os import path\n")) |
| 16 |
|
| 17 |
def test_correct_output(): |
| 18 |
hfmt = IRCFormatter() |
| 19 |
houtfile = StringIO() |
| 20 |
hfmt.format(tokensource, houtfile) |
| 21 |
|
| 22 |
assert '\x0302lambda\x03 x: \x0302123\x03\n' == houtfile.getvalue() |
| 23 |
|
| 24 |
def test_linecount_output(): |
| 25 |
hfmt = IRCFormatter(linenos = True) |
| 26 |
houtfile = StringIO() |
| 27 |
hfmt.format(newlinetokensource, houtfile) |
| 28 |
|
| 29 |
expected_out = '0001: \x0302from\x03\x0315 \\\x03\n0002: \x0315\\\x03\n0003: \x0315 \x03\x1d\x0310os\x03\x1d\x0315 \x03\x0302import\x03 path\n0004: ' |
| 30 |
assert expected_out == houtfile.getvalue() |