forked from oils-for-unix/oils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoil_doc_test.py
executable file
·67 lines (53 loc) · 1.44 KB
/
oil_doc_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python2
"""
oil_doc_test.py: Tests for oil_doc.py
"""
from __future__ import print_function
import sys
import unittest
from doctools import oil_doc # module under test
from lazylex import html
with open('lazylex/testdata.html') as f:
TEST_HTML = f.read()
class OilDoc(unittest.TestCase):
def testExpandLinks(self):
"""
<a href=$xref:bash>bash</a>
->
<a href=/cross-ref?tag=bash#bash>
NOTE: THIs could really be done with a ref like <a.*href="(.*)">
But we're testing it
"""
print(oil_doc.ExpandLinks(TEST_HTML))
def testHighlightCode(self):
"""
<pre><code language="sh">echo one
echo two
</code></pre>
"""
print(oil_doc.HighlightCode(TEST_HTML))
def testShPrompt(self):
r = oil_doc._PROMPT_LINE_RE
line = 'oil$ ls -l<TAB> # comment'
m = r.match(line)
print(m.groups())
print(m.group(2))
print(m.end(2))
plugin = oil_doc.ShPromptPlugin(line, 0, len(line))
out = html.Output(line, sys.stdout)
plugin.PrintHighlighted(out)
def testPygmentsPlugin(self):
# This test depends on pygments being installed, which isn't on Travis.
# TODO: Add it to Nix?
return
HTML = '''
<pre><code class="language-sh">
echo hi > out.txt
</code></pre>
'''
h = oil_doc.HighlightCode(HTML)
# assert there's no double escaping
self.assert_('hi > out.txt' in h, h)
print(h)
if __name__ == '__main__':
unittest.main()