1 | #!/usr/bin/env python2
|
2 | """
|
3 | oils_doc_test.py: Tests for oils_doc.py
|
4 | """
|
5 | from __future__ import print_function
|
6 |
|
7 | import sys
|
8 | import unittest
|
9 |
|
10 | from doctools import oils_doc # module under test
|
11 | from lazylex import html
|
12 |
|
13 | with open('lazylex/testdata.html') as f:
|
14 | TEST_HTML = f.read()
|
15 |
|
16 |
|
17 | class 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<TAB> # 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 > 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 > out.txt' in h, h)
|
66 | #print(h)
|
67 |
|
68 |
|
69 | if __name__ == '__main__':
|
70 | unittest.main()
|