can cope with deeper section levels
[rst2info.git] / texinfo / test_info_translator.py
blob2e25d30a2043f039fb3aea14b0e018969e80680c
1 import rst_test_utils
2 from info_translator import InfoTranslator
4 class T(rst_test_utils.TestCase):
6 def given_input(self, input):
7 super(T, self).given_input(input)
8 self.visitor = InfoTranslator(self.document)
9 self.visitor.section_level = -1 #HACK: core.publish_* start at 0, but that makes these tests fail - maybe missing some attribute set on the new document?
10 self.document.walkabout(self.visitor)
12 def setUp(self):
13 self.given_input('')
15 def test_adds_info_header(self):
16 self.assertTrue(self.visitor.astext().startswith('\\input texinfo'))
18 def test_title(self):
19 self.given_input('''
20 Hello, world!
21 ================
22 ''')
23 self.assertEqual(['@node Top', '@top Hello, world!'], self.visitor.body)
25 def test_chapter(self):
26 self.given_input('''
27 ======
28 Title!
29 ======
31 Chapter 1
32 =========
33 ''')
34 self.assertEqual(['@node Top', '@top Title!', '@chapter Chapter 1'],
35 self.visitor.body)
37 def test_section(self):
38 self.given_input('''
39 ======
40 Title!
41 ======
43 Chapter 1
44 =========
46 Section 1
47 ---------
48 ''')
49 self.assertEqual(['@node Top', '@top Title!',
50 '@chapter Chapter 1',
51 '@section Section 1'],
52 self.visitor.body)
54 def test_subsection(self):
55 self.given_input('''
56 ======
57 Title!
58 ======
60 Chapter 1
61 =========
63 Section 1
64 ---------
66 Subsection 1
67 ~~~~~~~~~~~~
68 ''')
69 self.assertEqual(['@node Top', '@top Title!',
70 '@chapter Chapter 1',
71 '@section Section 1',
72 '@subsection Subsection 1'],
73 self.visitor.body)
75 def test_section_layering(self):
76 self.given_input("""
77 ===================
78 A Plan for the Moon
79 ===================
81 The Problem
82 ===========
84 Cheese
85 ------
87 Lunar mold
88 ~~~~~~~~~~
90 Cows
91 ----
93 A Modest Solution
94 =================
95 """)
96 self.assertEqual(['@node Top', '@top A Plan for the Moon',
97 '@chapter The Problem',
98 '@section Cheese',
99 '@subsection Lunar mold',
100 '@section Cows',
101 '@chapter A Modest Solution'],
102 self.visitor.body)
104 def test_beyond_subsections(self):
105 self.given_input('''
106 ======
107 Title!
108 ======
110 Chapter 1
111 =========
113 Section 1
114 ---------
116 Subsection 1
117 ~~~~~~~~~~~~
119 Something else
120 ^^^^^^^^^^^^^^
122 Subsection 2
123 ~~~~~~~~~~~~
125 Section 2
126 ---------
128 ''')
129 self.assertEqual(['@node Top', '@top Title!',
130 '@chapter Chapter 1',
131 '@section Section 1',
132 '@subsection Subsection 1',
133 '@subsection Something else',
134 '@subsection Subsection 2',
135 '@section Section 2'],
136 self.visitor.body)
138 def test_comments_are_comments(self):
139 self.given_input("""
140 .. hello-world:
141 """)
142 self.assertEqual(['@c hello-world:'], self.visitor.body)
144 def test_paragraph_text_is_normal_text(self):
145 self.given_input("""
146 Someone left the cake out in the rain.
147 I don't think that I can take it.
148 """)
149 self.assertEqual(["Someone left the cake out in the rain.\nI don't think that I can take it."], self.visitor.body)
151 def test_two_paragraphs(self):
152 self.given_input("""
153 MacArthur's park is melting in the dark.
155 Someone left the cake out in the rain.
156 I don't think that I can take it.
157 """)
158 self.assertEqual(["MacArthur's park is melting in the dark.",
159 "Someone left the cake out in the rain.\nI don't think that I can take it."], self.visitor.body)
162 def test_single_bullet_list(self):
163 self.given_input("""
164 * milk
165 """)
166 self.assertEqual(["@itemize @bullet",
167 "@item",
168 "milk",
170 "@end @itemize"], self.visitor.body)
172 def test_three_bullet_list(self):
173 self.given_input("""
174 * milk
175 * eggs
176 * bread
177 """)
178 self.assertEqual(["@itemize @bullet",
179 "@item",
180 "milk",
182 "@item",
183 "eggs",
185 "@item",
186 "bread",
188 "@end @itemize"], self.visitor.body)
190 def test_quotation(self):
191 self.given_input("""
192 Never precede any action with the words "Watch this!"
193 -- the first commandment of frisbeetarianism
195 """)
196 self.assertEqual(["@quotation",
197 '''Never precede any action with the words "Watch this!"
198 -- the first commandment of frisbeetarianism''',
199 "@end quotation"], self.visitor.body)
201 def test_formatted_code(self):
202 self.given_input("""
203 Frisbeetarianism is the belief that, when you die, your soul goes up
204 onto the roof and gets stuck.
206 Never precede any action with the words "Watch this!"
207 -- the first constant Law of Frisbee
208 """)
209 self.assertEqual([
210 '''Frisbeetarianism is the belief that, when you die, your soul goes up
211 onto the roof and gets stuck.''',
212 "@quotation",
213 '''Never precede any action with the words "Watch this!"
214 -- the first constant Law of Frisbee''',
215 "@end quotation"], self.visitor.body)
217 def test_literal_block(self):
218 self.given_input("""
219 THE LANDING::
221 "Just the place for a Snark!" the Bellman cried,
222 As he landed his crew with care;
223 Supporting each man on the top of the tide
224 By a finger entwined in his hair.
226 """)
227 self.assertEqual(["THE LANDING:",
228 """"Just the place for a Snark!" the Bellman cried,
229 As he landed his crew with care;
230 Supporting each man on the top of the tide
231 By a finger entwined in his hair."""
232 ], self.visitor.body)