OILS / doctools / oils_doc_test.py View on Github | oils.pub

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