Change default of "syntax highlight" option to "long",
[docutils.git] / test / test_parsers / test_rst / test_directives / test_code.py
blob5e013d485d5008f3d3b8c918a8d381a0a2e30458
1 #! /usr/bin/env python
3 # $Id$
4 # Author: Guenter Milde
5 # Copyright: This module has been placed in the public domain.
7 """
8 Test the 'code' directive in parsers/rst/directives/body.py.
9 """
11 from __init__ import DocutilsTestSupport
12 from docutils.utils.code_analyzer import with_pygments
14 def suite():
15 s = DocutilsTestSupport.ParserTestSuite()
16 if not with_pygments:
17 del(totest['code-parsing'])
18 s.generateTests(totest)
19 return s
21 totest = {}
23 totest['code'] = [
24 ["""\
25 .. code::
27 This is a code block.
28 """,
29 """\
30 <document source="test data">
31 <literal_block classes="code" xml:space="preserve">
32 This is a code block.
33 """],
34 ["""\
35 .. code::
36 :class: testclass
37 :name: without argument
39 This is a code block with generic options.
40 """,
41 """\
42 <document source="test data">
43 <literal_block classes="code testclass" ids="without-argument" names="without\ argument" xml:space="preserve">
44 This is a code block with generic options.
45 """],
46 ["""\
47 .. code:: text
48 :class: testclass
50 This is a code block with text.
51 """,
52 """\
53 <document source="test data">
54 <literal_block classes="code text testclass" xml:space="preserve">
55 This is a code block with text.
56 """],
57 ["""\
58 .. code::
59 :number-lines:
61 This is a code block with text.
62 """,
63 """\
64 <document source="test data">
65 <literal_block classes="code" xml:space="preserve">
66 <inline classes="ln">
67 1 \n\
68 This is a code block with text.
69 """],
70 ["""\
71 .. code::
72 :number-lines: 30
74 This is a code block with text.
75 """,
76 """\
77 <document source="test data">
78 <literal_block classes="code" xml:space="preserve">
79 <inline classes="ln">
80 30 \n\
81 This is a code block with text.
82 """],
83 ["""\
84 .. code::
85 """,
86 """\
87 <document source="test data">
88 <system_message level="3" line="1" source="test data" type="ERROR">
89 <paragraph>
90 Content block expected for the "code" directive; none found.
91 <literal_block xml:space="preserve">
92 .. code::
93 """],
96 totest['code-parsing'] = [
97 ["""\
98 .. code:: python
99 :class: testclass
101 print 'hello world' # to stdout
102 """,
103 """\
104 <document source="test data">
105 <literal_block classes="code python testclass" xml:space="preserve">
107 <inline classes="keyword">
108 print
110 <inline classes="literal string">
111 'hello world'
113 <inline classes="comment">
114 # to stdout
115 """],
116 ["""\
117 .. code:: python
118 :class: testclass
119 :name: my_function
120 :number-lines: 7
122 def my_function():
123 '''Test the lexer.
126 # and now for something completely different
127 print 8/2
128 """,
129 """\
130 <document source="test data">
131 <literal_block classes="code python testclass" ids="my-function" names="my_function" xml:space="preserve">
132 <inline classes="ln">
133 7 \n\
134 <inline classes="keyword">
137 <inline classes="name function">
138 my_function
139 <inline classes="punctuation">
142 <inline classes="ln">
143 8 \n\
145 <inline classes="literal string doc">
146 \'\'\'Test the lexer.
147 <inline classes="ln">
148 9 \n\
149 <inline classes="literal string doc">
150 \'\'\'
152 <inline classes="ln">
153 10 \n\
155 <inline classes="ln">
156 11 \n\
158 <inline classes="comment">
159 # and now for something completely different
161 <inline classes="ln">
162 12 \n\
164 <inline classes="keyword">
165 print
167 <inline classes="literal number integer">
169 <inline classes="operator">
171 <inline classes="literal number integer">
173 """],
174 ["""\
175 .. code:: latex
176 :class: testclass
178 hello \emph{world} % emphasize
179 """,
180 """\
181 <document source="test data">
182 <literal_block classes="code latex testclass" xml:space="preserve">
183 hello \n\
184 <inline classes="keyword">
185 \\emph
186 <inline classes="name builtin">
188 world
189 <inline classes="name builtin">
192 <inline classes="comment">
193 % emphasize"""],
194 ["""\
195 .. code:: rst
196 :number-lines:
198 This is a code block with text.
199 """,
200 """\
201 <document source="test data">
202 <literal_block classes="code rst" xml:space="preserve">
203 <inline classes="ln">
204 1 \n\
205 This is a code block with text.
206 """],
207 ["""\
208 .. code:: s-lang
210 % abc.sl
211 autoload("abc_mode", "abc");
212 """,
213 """\
214 <document source="test data">
215 <system_message level="2" line="1" source="test data" type="WARNING">
216 <paragraph>
217 Cannot analyze code. No Pygments lexer found for "s-lang".
218 <literal_block xml:space="preserve">
219 .. code:: s-lang
221 % abc.sl
222 autoload("abc_mode", "abc");
223 """],
224 ["""\
225 Place the language name in a class argument to avoid the no-lexer warning:
227 .. code::
228 :class: s-lang
230 % abc.sl
231 autoload("abc_mode", "abc");
232 """,
233 """\
234 <document source="test data">
235 <paragraph>
236 Place the language name in a class argument to avoid the no-lexer warning:
237 <literal_block classes="code s-lang" xml:space="preserve">
238 % abc.sl
239 autoload("abc_mode", "abc");
240 """],
244 if __name__ == '__main__':
245 import unittest
246 unittest.main(defaultTest='suite')