OLD | NEW |
| (Empty) |
1 # Copyright (c) 2008 Twisted Matrix Laboratories. | |
2 # See LICENSE for details. | |
3 | |
4 | |
5 """ | |
6 Tests for L{twisted.lore.man2lore}. | |
7 """ | |
8 | |
9 from StringIO import StringIO | |
10 | |
11 from twisted.trial.unittest import TestCase | |
12 | |
13 from twisted.lore.man2lore import ManConverter | |
14 | |
15 | |
16 | |
17 class ManConverterTestCase(TestCase): | |
18 """ | |
19 Tests for L{ManConverter}. | |
20 """ | |
21 | |
22 def setUp(self): | |
23 """ | |
24 Build instance variables useful for tests. | |
25 | |
26 @ivar converter: a L{ManConverter} to be used during tests. | |
27 """ | |
28 self.converter = ManConverter() | |
29 | |
30 | |
31 def assertConvert(self, inputLines, expectedOutput): | |
32 """ | |
33 Helper method to check conversion from a man page to a Lore output. | |
34 | |
35 @param inputLines: lines of the manpages. | |
36 @type inputLines: C{list} | |
37 | |
38 @param expectedOutput: expected Lore content. | |
39 @type expectedOutput: C{str} | |
40 """ | |
41 inputFile = StringIO() | |
42 for line in inputLines: | |
43 inputFile.write(line + '\n') | |
44 inputFile.seek(0) | |
45 outputFile = StringIO() | |
46 self.converter.convert(inputFile, outputFile) | |
47 self.assertEquals(outputFile.getvalue(), expectedOutput) | |
48 | |
49 | |
50 def test_convert(self): | |
51 """ | |
52 Test convert on a minimal example. | |
53 """ | |
54 inputLines = ['.TH BAR "1" "Oct 2007" "" ""', "Foo\n"] | |
55 output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n" | |
56 "<h1>BAR.1</h1>\n\n<p>Foo\n\n</p>\n\n</body>\n</html>\n") | |
57 self.assertConvert(inputLines, output) | |
58 | |
59 | |
60 def test_TP(self): | |
61 """ | |
62 Test C{TP} parsing. | |
63 """ | |
64 inputLines = ['.TH BAR "1" "Oct 2007" "" ""', | |
65 ".SH HEADER", | |
66 ".TP", | |
67 "\\fB-o\\fR, \\fB--option\\fR", | |
68 "An option"] | |
69 output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n" | |
70 "<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl><dt>" | |
71 "<strong>-o</strong>, <strong>--option</strong>\n</dt>" | |
72 "<dd>An option\n</dd>\n\n</dl>\n\n</body>\n</html>\n") | |
73 self.assertConvert(inputLines, output) | |
74 | |
75 | |
76 def test_TPMultipleOptions(self): | |
77 """ | |
78 Try to parse multiple C{TP} fields. | |
79 """ | |
80 inputLines = ['.TH BAR "1" "Oct 2007" "" ""', | |
81 ".SH HEADER", | |
82 ".TP", | |
83 "\\fB-o\\fR, \\fB--option\\fR", | |
84 "An option", | |
85 ".TP", | |
86 "\\fB-n\\fR, \\fB--another\\fR", | |
87 "Another option", | |
88 ] | |
89 output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n" | |
90 "<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl><dt>" | |
91 "<strong>-o</strong>, <strong>--option</strong>\n</dt>" | |
92 "<dd>An option\n</dd>\n\n<dt>" | |
93 "<strong>-n</strong>, <strong>--another</strong>\n</dt>" | |
94 "<dd>Another option\n</dd>\n\n</dl>\n\n</body>\n</html>\n") | |
95 self.assertConvert(inputLines, output) | |
96 | |
97 | |
98 def test_TPMultiLineOptions(self): | |
99 """ | |
100 Try to parse multiple C{TP} fields, with options text on several lines. | |
101 """ | |
102 inputLines = ['.TH BAR "1" "Oct 2007" "" ""', | |
103 ".SH HEADER", | |
104 ".TP", | |
105 "\\fB-o\\fR, \\fB--option\\fR", | |
106 "An option", | |
107 "on two lines", | |
108 ".TP", | |
109 "\\fB-n\\fR, \\fB--another\\fR", | |
110 "Another option", | |
111 "on two lines", | |
112 ] | |
113 output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n" | |
114 "<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl><dt>" | |
115 "<strong>-o</strong>, <strong>--option</strong>\n</dt>" | |
116 "<dd>An option\non two lines\n</dd>\n\n" | |
117 "<dt><strong>-n</strong>, <strong>--another</strong>\n</dt>" | |
118 "<dd>Another option\non two lines\n</dd>\n\n</dl>\n\n" | |
119 "</body>\n</html>\n") | |
120 self.assertConvert(inputLines, output) | |
121 | |
122 | |
123 def test_ITLegacyManagement(self): | |
124 """ | |
125 Test management of BL/IT/EL used in some man pages. | |
126 """ | |
127 inputLines = ['.TH BAR "1" "Oct 2007" "" ""', | |
128 ".SH HEADER", | |
129 ".BL", | |
130 ".IT An option", | |
131 "on two lines", | |
132 ".IT", | |
133 "Another option", | |
134 "on two lines", | |
135 ".EL" | |
136 ] | |
137 output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n" | |
138 "<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl>" | |
139 "<dt>on two lines\n</dt><dd>Another option\non two lines\n" | |
140 "</dd></dl>\n\n</body>\n</html>\n") | |
141 self.assertConvert(inputLines, output) | |
142 | |
143 | |
144 def test_interactiveCommand(self): | |
145 """ | |
146 Test management of interactive command tag. | |
147 """ | |
148 inputLines = ['.TH BAR "1" "Oct 2007" "" ""', | |
149 ".SH HEADER", | |
150 ".BL", | |
151 ".IT IC foo AR bar", | |
152 "option 1", | |
153 ".IT IC egg AR spam OP AR stuff", | |
154 "option 2", | |
155 ".EL" | |
156 ] | |
157 output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n" | |
158 "<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl>" | |
159 "<dt>foo <u>bar</u></dt><dd>option 1\n</dd><dt>egg " | |
160 "<u>spam</u> [<u>stuff</u>]</dt><dd>option 2\n</dd></dl>" | |
161 "\n\n</body>\n</html>\n") | |
162 self.assertConvert(inputLines, output) | |
OLD | NEW |