System messages become comments.
[rst2info.git] / texinfo / test_info_translator.py
blobdd31fb4a4b9c9418454ed75d40e23865331582ff
2 import rst_test_utils
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)
12 for t in transforms:
13 self.document.transformer.add_transform(t)
14 self.document.transformer.apply_transforms()
16 self.document.walkabout(self.visitor)
18 def setUp(self):
19 self.given_input('')
21 def test_adds_info_header(self):
22 self.assertTrue(self.visitor.astext().startswith('\\input texinfo'))
24 def test_title(self):
25 self.given_input('''
26 Hello, world!
27 ================
28 ''', transforms = [frontmatter.DocTitle])
29 self.assertEqual(['@node Top', '@top Hello, world!'], self.visitor.body)
31 def test_subtitle(self):
32 self.given_input('''
33 ======
34 Title!
35 ======
37 --------
38 Subtitle
39 --------
40 ''', transforms = [frontmatter.DocTitle])
41 self.assertEqual(['@node Top', '@top Title!',
42 '@majorheading Subtitle'],
43 self.visitor.body)
45 def test_subsection(self):
46 self.given_input('''
47 Chapter 1
48 =========
50 Section 1
51 ---------
53 Subsection 1
54 ~~~~~~~~~~~~
55 ''')
56 self.assertEqual(['@chapter Chapter 1',
57 '@section Section 1',
58 '@subsection Subsection 1'],
59 self.visitor.body)
61 def test_section_layering(self):
62 self.given_input("""
63 The Problem
64 ===========
66 Cheese
67 ------
69 Lunar mold
70 ~~~~~~~~~~
72 Cows
73 ----
75 A Modest Solution
76 =================
77 """)
78 self.assertEqual(['@chapter The Problem',
79 '@section Cheese',
80 '@subsection Lunar mold',
81 '@section Cows',
82 '@chapter A Modest Solution'],
83 self.visitor.body)
85 def test_beyond_subsections(self):
86 self.given_input('''
87 Chapter 1
88 =========
90 Section 1
91 ---------
93 Subsection 1
94 ~~~~~~~~~~~~
96 Something else
97 ^^^^^^^^^^^^^^
99 Subsection 2
100 ~~~~~~~~~~~~
102 Section 2
103 ---------
105 ''')
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'],
112 self.visitor.body)
114 def test_comments_are_comments(self):
115 self.given_input("""
116 .. hello-world:
117 """)
118 self.assertEqual(['@c hello-world:'], self.visitor.body)
120 def test_paragraph_text_is_normal_text(self):
121 self.given_input("""
122 Someone left the cake out in the rain.
123 I don't think that I can take it.
124 """)
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):
128 self.given_input("""
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.
133 """)
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):
139 self.given_input("""
140 * milk
141 """)
142 self.assertEqual(["@itemize @bullet",
143 "@item", "milk", "",
144 "@end @itemize"], self.visitor.body)
146 def test_three_bullet_list(self):
147 self.given_input("""
148 * milk
149 * eggs
150 * bread
151 """)
152 self.assertEqual(["@itemize @bullet",
153 "@item", "milk", "",
154 "@item", "eggs", "",
155 "@item", "bread", "",
156 "@end @itemize"], self.visitor.body)
158 def test_single_enumerated_list(self):
159 self.given_input("""
160 (1) I was transferred to the moon.
161 """)
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):
167 self.given_input("""
168 (1) I was transferred to the moon.
169 (2) Worse pay, better hours.
170 (3) Worse pay, better fellow workers.
171 """)
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):
179 self.given_input("""
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!
184 """)
185 self.assertEqual(["@enumerate",
186 "@item", "lower-case letters", "",
187 "@enumerate",
188 "@item", "with a sub-list starting at a different number", "",
189 "@item", "make sure the numbers are in the correct sequence though!", "",
190 "@end enumerate",
191 "@end enumerate"], self.visitor.body)
193 def test_quotation(self):
194 self.given_input("""
195 Never precede any action with the words "Watch this!"
196 -- the second constant Law of Frisbee
198 """)
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):
205 self.given_input("""
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
211 """)
212 self.assertEqual([
213 '''Frisbeetarianism is the belief that, when you die, your soul goes up
214 onto the roof and gets stuck.''', '',
215 "@quotation",
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):
221 self.given_input("""
222 THE LANDING::
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.
229 """)
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)