summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Bussonnier <bussonniermatthias@gmail.com>2016-02-12 16:06:14 -0800
committerMatthias Bussonnier <bussonniermatthias@gmail.com>2016-02-12 16:06:14 -0800
commit4b70ceead784566eff81456239e3aee99d9b994d (patch)
tree92e6bf23018174862f61c27f4d1df0927105117a
parent9834d006ab8c196189a788ead199e0e1542da7b7 (diff)
downloadpygments-4b70ceead784566eff81456239e3aee99d9b994d.tar.gz
Add tests for Ansi functionality.
-rw-r--r--tests/test_lexers_other.py21
-rw-r--r--tests/test_terminal_formatter.py61
2 files changed, 71 insertions, 11 deletions
diff --git a/tests/test_lexers_other.py b/tests/test_lexers_other.py
index bb667c05..d3feaefc 100644
--- a/tests/test_lexers_other.py
+++ b/tests/test_lexers_other.py
@@ -9,6 +9,7 @@
import glob
import os
import unittest
+import sys
from pygments.lexers import guess_lexer
from pygments.lexers.scripting import EasytrieveLexer, JclLexer, RexxLexer
@@ -42,16 +43,16 @@ class AnalyseTextTest(unittest.TestCase):
for lexerToTest in LEXERS_TO_TEST:
self._testCanRecognizeAndGuessExampleFiles(lexerToTest)
-
-class EasyTrieveLexerTest(unittest.TestCase):
- def testCanGuessFromText(self):
- self.assertLess(0, EasytrieveLexer.analyse_text('MACRO'))
- self.assertLess(0, EasytrieveLexer.analyse_text('\nMACRO'))
- self.assertLess(0, EasytrieveLexer.analyse_text(' \nMACRO'))
- self.assertLess(0, EasytrieveLexer.analyse_text(' \n MACRO'))
- self.assertLess(0, EasytrieveLexer.analyse_text('*\nMACRO'))
- self.assertLess(0, EasytrieveLexer.analyse_text(
- '*\n *\n\n \n*\n MACRO'))
+if sys.version_info > (2,7,):
+ class EasyTrieveLexerTest(unittest.TestCase):
+ def testCanGuessFromText(self):
+ self.assertLess(0, EasytrieveLexer.analyse_text('MACRO'))
+ self.assertLess(0, EasytrieveLexer.analyse_text('\nMACRO'))
+ self.assertLess(0, EasytrieveLexer.analyse_text(' \nMACRO'))
+ self.assertLess(0, EasytrieveLexer.analyse_text(' \n MACRO'))
+ self.assertLess(0, EasytrieveLexer.analyse_text('*\nMACRO'))
+ self.assertLess(0, EasytrieveLexer.analyse_text(
+ '*\n *\n\n \n*\n MACRO'))
class RexxLexerTest(unittest.TestCase):
diff --git a/tests/test_terminal_formatter.py b/tests/test_terminal_formatter.py
index 07337cd5..f3836bd1 100644
--- a/tests/test_terminal_formatter.py
+++ b/tests/test_terminal_formatter.py
@@ -10,11 +10,17 @@
from __future__ import print_function
import unittest
+import sys
import re
from pygments.util import StringIO
from pygments.lexers.sql import PlPgsqlLexer
-from pygments.formatters import TerminalFormatter
+from pygments.formatters import TerminalFormatter,Terminal256Formatter, HtmlFormatter, LatexFormatter
+
+from pygments.style import Style
+from pygments.token import Token
+from pygments.lexers import Python3Lexer
+from pygments import highlight
DEMO_TEXT = '''\
-- comment
@@ -49,3 +55,56 @@ class TerminalFormatterTest(unittest.TestCase):
for a, b in zip(DEMO_TEXT.splitlines(), plain.splitlines()):
self.assertTrue(a in b)
+
+
+
+
+
+
+class MyStyle(Style):
+
+ styles = {
+ Token.Comment: '#ansidarkgray',
+ Token.String: '#ansiblue bg:#ansidarkred',
+ Token.Number : '#ansigreen bg:#ansidarkgreen',
+ Token.Number.Hex: '#ansidarkgreen bg:#ansired',
+ }
+
+
+
+code = '''
+# this should be a comment
+print("Hello World")
+async def function(a,b,c, *d, **kwarg:Bool)->Bool:
+ pass
+ return 123, 0xb3e3
+
+'''
+
+
+termtest = lambda x: highlight(x, Python3Lexer(), Terminal256Formatter(style=MyStyle))
+if sys.version_info > (2,7):
+ class Terminal256FormatterTest(unittest.TestCase):
+
+
+ def test_style_html(self):
+ style = HtmlFormatter(style=MyStyle).get_style_defs()
+ self.assertIn('#555555',style, "ansigray for comment not html css style")
+
+ def test_tex_works(self):
+ """check tex Formatter don't crash"""
+ highlight(code, Python3Lexer(), LatexFormatter(style=MyStyle))
+
+ def test_html_works(self):
+ highlight(code, Python3Lexer(), HtmlFormatter(style=MyStyle))
+
+ def test_256esc_seq(self):
+ """
+ test that a few escape sequences are actualy used when using #ansi<> color codes
+ """
+ self.assertIn('32;41',termtest('0x123'))
+ self.assertIn('32;42',termtest('123'))
+ self.assertIn('30;01',termtest('#comment'))
+ self.assertIn('34;41',termtest('"String"'))
+
+