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