Commits

Anonymous committed 3005a5b

[svn] Test that the HTML formatter output is complete.

  • Participants
  • Parent commits 51fad2f
  • Branches trunk

Comments (0)

Files changed (3)

File pygments/formatters/html.py

 <head>
   <title>%(title)s</title>
   <meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
-  <link rel="stylesheet" href="%(cssfile)s">
+  <link rel="stylesheet" href="%(cssfile)s" type="text/css">
 </head>
 <body>
 <h2>%(title)s</h2>
                         line += part + (lspan and '</span>') + lsep
                     yield 1, line
                     line = ''
+                elif part:
+                    yield 1, cspan + part + (cspan and '</span>') + lsep
                 else:
-                    yield 1, cspan + part + (cspan and '</span>') + lsep
+                    yield 1, lsep
             # for the last line
             if line and parts[-1]:
                 if lspan != cspan:

File tests/test_html_formatter.py

 """
 
 import os
+import re
 import unittest
 import StringIO
-import random
 import tempfile
 from os.path import join, dirname, isfile
 
-from pygments import lexers, formatters
-from pygments.token import _TokenType
-from pygments.formatters import HtmlFormatter
 from pygments.lexers import PythonLexer
+from pygments.formatters import HtmlFormatter, NullFormatter
+from pygments.formatters.html import escape_html
 
 tokensource = list(PythonLexer().get_tokens(file(os.path.join(testdir, testfile)).read()))
 
 class HtmlFormatterTest(unittest.TestCase):
+    def test_correct_output(self):
+        hfmt = HtmlFormatter(nowrap=True)
+        houtfile = StringIO.StringIO()
+        hfmt.format(tokensource, houtfile)
+
+        nfmt = NullFormatter()
+        noutfile = StringIO.StringIO()
+        nfmt.format(tokensource, noutfile)
+
+        stripped_html = re.sub('<.*?>', '', houtfile.getvalue())
+        escaped_text = escape_html(noutfile.getvalue())
+        self.assertEquals(stripped_html, escaped_text)
 
     def test_external_css(self):
         # test correct behavior
         except OSError:
             pass
 
-
     def test_all_options(self):
         for optdict in [dict(nowrap=True),
                         dict(linenos=True),

File tests/test_latex_formatter.py

 
 import os
 import unittest
-import StringIO
 import tempfile
 
-from pygments import lexers, formatters
-from pygments.token import _TokenType
 from pygments.formatters import LatexFormatter
 from pygments.lexers import PythonLexer