summaryrefslogtreecommitdiffstats
path: root/tests/test_irc_formatter.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:33:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:33:32 +0000
commit1f403ad2197fc7442409f434ee574f3e6b46fb73 (patch)
tree0299c6dd11d5edfa918a29b6456bc1875f1d288c /tests/test_irc_formatter.py
parentInitial commit. (diff)
downloadpygments-upstream.tar.xz
pygments-upstream.zip
Adding upstream version 2.14.0+dfsg.upstream/2.14.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_irc_formatter.py')
-rw-r--r--tests/test_irc_formatter.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_irc_formatter.py b/tests/test_irc_formatter.py
new file mode 100644
index 0000000..c930166
--- /dev/null
+++ b/tests/test_irc_formatter.py
@@ -0,0 +1,30 @@
+"""
+ Pygments IRC formatter tests
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ :copyright: Copyright 2006-2022 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()