2 from info_translator
import InfoTranslator
3 from docutils
.transforms
import frontmatter
5 class T(rst_test_utils
.TestCase
):
7 def given_input(self
, input, transforms
= []):
8 super(T
, self
).given_input(input)
9 self
.visitor
= InfoTranslator(self
.document
)
12 self
.document
.transformer
.add_transform(t
)
13 self
.document
.transformer
.apply_transforms()
15 self
.document
.walkabout(self
.visitor
)
20 def test_adds_info_header(self
):
21 self
.assertTrue(self
.visitor
.astext().startswith('\\input texinfo'))
27 ''', transforms
= [frontmatter
.DocTitle
])
28 self
.assertEqual(['@node Top', '@top Hello, world!'], self
.visitor
.body
)
30 def test_subtitle(self
):
39 ''', transforms
= [frontmatter
.DocTitle
])
40 self
.assertEqual(['@node Top', '@top Title!',
41 '@majorheading Subtitle'],
44 def test_subsection(self
):
55 self
.assertEqual(['@chapter Chapter 1',
57 '@subsection Subsection 1'],
60 def test_section_layering(self
):
77 self
.assertEqual(['@chapter The Problem',
79 '@subsection Lunar mold',
81 '@chapter A Modest Solution'],
84 def test_beyond_subsections(self
):
105 self
.assertEqual(['@chapter Chapter 1',
106 '@section Section 1',
107 '@subsection Subsection 1',
108 '@subsection Something else',
109 '@subsection Subsection 2',
110 '@section Section 2'],
113 def test_comments_are_comments(self
):
117 self
.assertEqual(['@c hello-world:'], self
.visitor
.body
)
119 def test_paragraph_text_is_normal_text(self
):
121 Someone left the cake out in the rain.
122 I don't think that I can take it.
124 self
.assertEqual(["Someone left the cake out in the rain.\nI don't think that I can take it."], self
.visitor
.body
)
126 def test_two_paragraphs(self
):
128 MacArthur's park is melting in the dark.
130 Someone left the cake out in the rain.
131 I don't think that I can take it.
133 self
.assertEqual(["MacArthur's park is melting in the dark.",
134 "Someone left the cake out in the rain.\nI don't think that I can take it."], self
.visitor
.body
)
137 def test_single_bullet_list(self
):
141 self
.assertEqual(["@itemize @bullet",
145 "@end @itemize"], self
.visitor
.body
)
147 def test_three_bullet_list(self
):
153 self
.assertEqual(["@itemize @bullet",
163 "@end @itemize"], self
.visitor
.body
)
165 def test_quotation(self
):
167 Never precede any action with the words "Watch this!"
168 -- the first commandment of frisbeetarianism
171 self
.assertEqual(["@quotation",
172 '''Never precede any action with the words "Watch this!"
173 -- the first commandment of frisbeetarianism''',
174 "@end quotation"], self
.visitor
.body
)
176 def test_formatted_code(self
):
178 Frisbeetarianism is the belief that, when you die, your soul goes up
179 onto the roof and gets stuck.
181 Never precede any action with the words "Watch this!"
182 -- the first constant Law of Frisbee
185 '''Frisbeetarianism is the belief that, when you die, your soul goes up
186 onto the roof and gets stuck.''',
188 '''Never precede any action with the words "Watch this!"
189 -- the first constant Law of Frisbee''',
190 "@end quotation"], self
.visitor
.body
)
192 def test_literal_block(self
):
196 "Just the place for a Snark!" the Bellman cried,
197 As he landed his crew with care;
198 Supporting each man on the top of the tide
199 By a finger entwined in his hair.
202 self
.assertEqual(["THE LANDING:",
203 """"Just the place for a Snark!" the Bellman cried,
204 As he landed his crew with care;
205 Supporting each man on the top of the tide
206 By a finger entwined in his hair."""
207 ], self
.visitor
.body
)