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