3 from info_translator
import InfoTranslator
4 from docutils
.transforms
import frontmatter
6 class T(rst_test_utils
.TestCase
):
8 def given_input(self
, input, transforms
=[], debug
=False):
9 super(T
, self
).given_input(input, debug
)
10 self
.visitor
= InfoTranslator(self
.document
)
13 self
.document
.transformer
.add_transform(t
)
14 self
.document
.transformer
.apply_transforms()
16 self
.document
.walkabout(self
.visitor
)
21 def test_adds_info_header(self
):
22 self
.assertTrue(self
.visitor
.astext().startswith('\\input texinfo'))
28 ''', transforms
= [frontmatter
.DocTitle
])
29 self
.assertEqual(['@node Top', '@top Hello, world!'], self
.visitor
.body
)
31 def test_subtitle(self
):
40 ''', transforms
= [frontmatter
.DocTitle
])
41 self
.assertEqual(['@node Top', '@top Title!',
42 '@majorheading Subtitle'],
45 def test_subsection(self
):
56 self
.assertEqual(['@chapter Chapter 1',
58 '@subsection Subsection 1'],
61 def test_section_layering(self
):
78 self
.assertEqual(['@chapter The Problem',
80 '@subsection Lunar mold',
82 '@chapter A Modest Solution'],
85 def test_beyond_subsections(self
):
106 self
.assertEqual(['@chapter Chapter 1',
107 '@section Section 1',
108 '@subsection Subsection 1',
109 '@subsection Something else',
110 '@subsection Subsection 2',
111 '@section Section 2'],
114 def test_comments_are_comments(self
):
118 self
.assertEqual(['@c hello-world:'], self
.visitor
.body
)
120 def test_paragraph_text_is_normal_text(self
):
122 Someone left the cake out in the rain.
123 I don't think that I can take it.
125 self
.assertEqual(["Someone left the cake out in the rain.\nI don't think that I can take it.", ''], self
.visitor
.body
)
127 def test_two_paragraphs(self
):
129 MacArthur's park is melting in the dark.
131 Someone left the cake out in the rain.
132 I don't think that I can take it.
134 self
.assertEqual(["MacArthur's park is melting in the dark.", '',
135 "Someone left the cake out in the rain.\nI don't think that I can take it.", ''], self
.visitor
.body
)
138 def test_single_bullet_list(self
):
142 self
.assertEqual(["@itemize @bullet",
144 "@end @itemize"], self
.visitor
.body
)
146 def test_three_bullet_list(self
):
152 self
.assertEqual(["@itemize @bullet",
155 "@item", "bread", "",
156 "@end @itemize"], self
.visitor
.body
)
158 def test_single_enumerated_list(self
):
160 (1) I was transferred to the moon.
162 self
.assertEqual(["@enumerate",
163 "@item", "I was transferred to the moon.", "",
164 "@end enumerate"], self
.visitor
.body
)
166 def test_three_item_enumerated_list(self
):
168 (1) I was transferred to the moon.
169 (2) Worse pay, better hours.
170 (3) Worse pay, better fellow workers.
172 self
.assertEqual(["@enumerate",
173 "@item", "I was transferred to the moon.", "",
174 "@item", "Worse pay, better hours.", "",
175 "@item", "Worse pay, better fellow workers.", "",
176 "@end enumerate"], self
.visitor
.body
)
178 def test_single_enumerated_sub_list(self
):
180 a. lower-case letters
182 1. with a sub-list starting at a different number
183 2. make sure the numbers are in the correct sequence though!
185 self
.assertEqual(["@enumerate",
186 "@item", "lower-case letters", "",
188 "@item", "with a sub-list starting at a different number", "",
189 "@item", "make sure the numbers are in the correct sequence though!", "",
191 "@end enumerate"], self
.visitor
.body
)
193 def test_quotation(self
):
195 Never precede any action with the words "Watch this!"
196 -- the second constant Law of Frisbee
199 self
.assertEqual(["@quotation",
200 '''Never precede any action with the words "Watch this!"
201 -- the second constant Law of Frisbee''', '',
202 "@end quotation"], self
.visitor
.body
)
204 def test_formatted_code(self
):
206 Frisbeetarianism is the belief that, when you die, your soul goes up
207 onto the roof and gets stuck.
209 Never precede any action with the words "Watch this!"
210 -- the second constant Law of Frisbee
213 '''Frisbeetarianism is the belief that, when you die, your soul goes up
214 onto the roof and gets stuck.''', '',
216 '''Never precede any action with the words "Watch this!"
217 -- the second constant Law of Frisbee''', '',
218 "@end quotation"], self
.visitor
.body
)
220 def test_literal_block(self
):
224 "Just the place for a Snark!" the Bellman cried,
225 As he landed his crew with care;
226 Supporting each man on the top of the tide
227 By a finger entwined in his hair.
230 self
.assertEqual(["THE LANDING:", '',
231 """"Just the place for a Snark!" the Bellman cried,
232 As he landed his crew with care;
233 Supporting each man on the top of the tide
234 By a finger entwined in his hair."""], self
.visitor
.body
)