OILS / doctools / oils_doc_test.py View on Github | oilshell.org

70 lines, 32 significant
1#!/usr/bin/env python2
2"""
3oils_doc_test.py: Tests for oils_doc.py
4"""
5from __future__ import print_function
6
7import sys
8import unittest
9
10from doctools import oils_doc # module under test
11from lazylex import html
12
13with open('lazylex/testdata.html') as f:
14 TEST_HTML = f.read()
15
16
17class OilDoc(unittest.TestCase):
18
19 def testExpandLinks(self):
20 """
21 <a href=$xref:bash>bash</a>
22 ->
23 <a href=/cross-ref?tag=bash#bash>
24
25 NOTE: THIs could really be done with a ref like <a.*href="(.*)">
26 But we're testing it
27 """
28 h = oils_doc.ExpandLinks(TEST_HTML)
29 self.assert_('/blog/tags.html' in h, h)
30
31 def testShPrompt(self):
32 r = oils_doc._PROMPT_LINE_RE
33 line = 'oil$ ls -l&lt;TAB&gt; # comment'
34 m = r.match(line)
35
36 if 0:
37 print(m.groups())
38 print(m.group(2))
39 print(m.end(2))
40
41 plugin = oils_doc.ShPromptPlugin(line, 0, len(line))
42 out = html.Output(line, sys.stdout)
43 plugin.PrintHighlighted(out)
44
45 def testHighlightCode(self):
46 # lazylex/testdata.html has the language-sh-prompt
47
48 h = oils_doc.HighlightCode(TEST_HTML, None)
49 self.assert_('<span class="sh-prompt">' in h, h)
50 #print(h)
51
52 def testPygmentsPlugin(self):
53 # TODO: Doesn't pass on Travis because pygments isn't there
54 # use virtualenv or something?
55 return
56
57 HTML = '''
58<pre><code class="language-sh">
59 echo hi &gt; out.txt
60</code></pre>
61 '''
62 h = oils_doc.HighlightCode(HTML, None)
63
64 # assert there's no double escaping
65 self.assert_('hi &gt; out.txt' in h, h)
66 #print(h)
67
68
69if __name__ == '__main__':
70 unittest.main()