##// END OF EJS Templates
minirst: add test for sections
Martin Geisler -
r10977:f4778f94 default
parent child Browse files
Show More
@@ -1,183 +1,190 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2
2
3 from pprint import pprint
3 from pprint import pprint
4 from mercurial import minirst
4 from mercurial import minirst
5
5
6 def debugformat(title, text, width, **kwargs):
6 def debugformat(title, text, width, **kwargs):
7 print "%s formatted to fit within %d characters:" % (title, width)
7 print "%s formatted to fit within %d characters:" % (title, width)
8 print "-" * 70
8 print "-" * 70
9 formatted = minirst.format(text, width, **kwargs)
9 formatted = minirst.format(text, width, **kwargs)
10 if type(formatted) == tuple:
10 if type(formatted) == tuple:
11 print formatted[0]
11 print formatted[0]
12 print "-" * 70
12 print "-" * 70
13 pprint(formatted[1])
13 pprint(formatted[1])
14 else:
14 else:
15 print formatted
15 print formatted
16 print "-" * 70
16 print "-" * 70
17 print
17 print
18
18
19 paragraphs = """
19 paragraphs = """
20 This is some text in the first paragraph.
20 This is some text in the first paragraph.
21
21
22 A small indented paragraph.
22 A small indented paragraph.
23 It is followed by some lines
23 It is followed by some lines
24 containing random whitespace.
24 containing random whitespace.
25 \n \n \nThe third and final paragraph.
25 \n \n \nThe third and final paragraph.
26 """
26 """
27
27
28 debugformat('paragraphs', paragraphs, 60)
28 debugformat('paragraphs', paragraphs, 60)
29 debugformat('paragraphs', paragraphs, 30)
29 debugformat('paragraphs', paragraphs, 30)
30
30
31
31
32 definitions = """
32 definitions = """
33 A Term
33 A Term
34 Definition. The indented
34 Definition. The indented
35 lines make up the definition.
35 lines make up the definition.
36 Another Term
36 Another Term
37 Another definition. The final line in the
37 Another definition. The final line in the
38 definition determines the indentation, so
38 definition determines the indentation, so
39 this will be indented with four spaces.
39 this will be indented with four spaces.
40
40
41 A Nested/Indented Term
41 A Nested/Indented Term
42 Definition.
42 Definition.
43 """
43 """
44
44
45 debugformat('definitions', definitions, 60)
45 debugformat('definitions', definitions, 60)
46 debugformat('definitions', definitions, 30)
46 debugformat('definitions', definitions, 30)
47
47
48
48
49 literals = r"""
49 literals = r"""
50 The fully minimized form is the most
50 The fully minimized form is the most
51 convenient form::
51 convenient form::
52
52
53 Hello
53 Hello
54 literal
54 literal
55 world
55 world
56
56
57 In the partially minimized form a paragraph
57 In the partially minimized form a paragraph
58 simply ends with space-double-colon. ::
58 simply ends with space-double-colon. ::
59
59
60 ////////////////////////////////////////
60 ////////////////////////////////////////
61 long un-wrapped line in a literal block
61 long un-wrapped line in a literal block
62 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
62 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
63
63
64 ::
64 ::
65
65
66 This literal block is started with '::',
66 This literal block is started with '::',
67 the so-called expanded form. The paragraph
67 the so-called expanded form. The paragraph
68 with '::' disappears in the final output.
68 with '::' disappears in the final output.
69 """
69 """
70
70
71 debugformat('literals', literals, 60)
71 debugformat('literals', literals, 60)
72 debugformat('literals', literals, 30)
72 debugformat('literals', literals, 30)
73
73
74
74
75 lists = """
75 lists = """
76 - This is the first list item.
76 - This is the first list item.
77
77
78 Second paragraph in the first list item.
78 Second paragraph in the first list item.
79
79
80 - List items need not be separated
80 - List items need not be separated
81 by a blank line.
81 by a blank line.
82 - And will be rendered without
82 - And will be rendered without
83 one in any case.
83 one in any case.
84
84
85 We can have indented lists:
85 We can have indented lists:
86
86
87 - This is an indented list item
87 - This is an indented list item
88
88
89 - Another indented list item::
89 - Another indented list item::
90
90
91 - A literal block in the middle
91 - A literal block in the middle
92 of an indented list.
92 of an indented list.
93
93
94 (The above is not a list item since we are in the literal block.)
94 (The above is not a list item since we are in the literal block.)
95
95
96 ::
96 ::
97
97
98 Literal block with no indentation (apart from
98 Literal block with no indentation (apart from
99 the two spaces added to all literal blocks).
99 the two spaces added to all literal blocks).
100
100
101 1. This is an enumerated list (first item).
101 1. This is an enumerated list (first item).
102 2. Continuing with the second item.
102 2. Continuing with the second item.
103
103
104 (1) foo
104 (1) foo
105 (2) bar
105 (2) bar
106
106
107 1) Another
107 1) Another
108 2) List
108 2) List
109
109
110 Line blocks are also a form of list:
110 Line blocks are also a form of list:
111
111
112 | This is the first line.
112 | This is the first line.
113 The line continues here.
113 The line continues here.
114 | This is the second line.
114 | This is the second line.
115 """
115 """
116
116
117 debugformat('lists', lists, 60)
117 debugformat('lists', lists, 60)
118 debugformat('lists', lists, 30)
118 debugformat('lists', lists, 30)
119
119
120
120
121 options = """
121 options = """
122 There is support for simple option lists,
122 There is support for simple option lists,
123 but only with long options:
123 but only with long options:
124
124
125 --all Output all.
125 --all Output all.
126 --both Output both (this description is
126 --both Output both (this description is
127 quite long).
127 quite long).
128 --long Output all day long.
128 --long Output all day long.
129
129
130 --par This option has two paragraphs in its description.
130 --par This option has two paragraphs in its description.
131 This is the first.
131 This is the first.
132
132
133 This is the second. Blank lines may be omitted between
133 This is the second. Blank lines may be omitted between
134 options (as above) or left in (as here).
134 options (as above) or left in (as here).
135
135
136 The next paragraph looks like an option list, but lacks the two-space
136 The next paragraph looks like an option list, but lacks the two-space
137 marker after the option. It is treated as a normal paragraph:
137 marker after the option. It is treated as a normal paragraph:
138
138
139 --foo bar baz
139 --foo bar baz
140 """
140 """
141
141
142 debugformat('options', options, 60)
142 debugformat('options', options, 60)
143 debugformat('options', options, 30)
143 debugformat('options', options, 30)
144
144
145
145
146 fields = """
146 fields = """
147 :a: First item.
147 :a: First item.
148 :ab: Second item. Indentation and wrapping
148 :ab: Second item. Indentation and wrapping
149 is handled automatically.
149 is handled automatically.
150
150
151 Next list:
151 Next list:
152
152
153 :small: The larger key below triggers full indentation here.
153 :small: The larger key below triggers full indentation here.
154 :much too large: This key is big enough to get its own line.
154 :much too large: This key is big enough to get its own line.
155 """
155 """
156
156
157 debugformat('fields', fields, 60)
157 debugformat('fields', fields, 60)
158 debugformat('fields', fields, 30)
158 debugformat('fields', fields, 30)
159
159
160 containers = """
160 containers = """
161 Normal output.
161 Normal output.
162
162
163 .. container:: debug
163 .. container:: debug
164
164
165 Initial debug output.
165 Initial debug output.
166
166
167 .. container:: verbose
167 .. container:: verbose
168
168
169 Verbose output.
169 Verbose output.
170
170
171 .. container:: debug
171 .. container:: debug
172
172
173 Debug output.
173 Debug output.
174 """
174 """
175
175
176 debugformat('containers (normal)', containers, 60)
176 debugformat('containers (normal)', containers, 60)
177 debugformat('containers (verbose)', containers, 60, keep=['verbose'])
177 debugformat('containers (verbose)', containers, 60, keep=['verbose'])
178 debugformat('containers (debug)', containers, 60, keep=['debug'])
178 debugformat('containers (debug)', containers, 60, keep=['debug'])
179 debugformat('containers (verbose debug)', containers, 60,
179 debugformat('containers (verbose debug)', containers, 60,
180 keep=['verbose', 'debug'])
180 keep=['verbose', 'debug'])
181
181
182 roles = """Please see :hg:`add`."""
182 roles = """Please see :hg:`add`."""
183 debugformat('roles', roles, 60)
183 debugformat('roles', roles, 60)
184
185
186 sections = """
187 A Somewhat Wide Section Header
188 ------------------------------
189 """
190 debugformat('sections', sections, 20)
@@ -1,305 +1,311 b''
1 paragraphs formatted to fit within 60 characters:
1 paragraphs formatted to fit within 60 characters:
2 ----------------------------------------------------------------------
2 ----------------------------------------------------------------------
3 This is some text in the first paragraph.
3 This is some text in the first paragraph.
4
4
5 A small indented paragraph. It is followed by some lines
5 A small indented paragraph. It is followed by some lines
6 containing random whitespace.
6 containing random whitespace.
7
7
8 The third and final paragraph.
8 The third and final paragraph.
9 ----------------------------------------------------------------------
9 ----------------------------------------------------------------------
10
10
11 paragraphs formatted to fit within 30 characters:
11 paragraphs formatted to fit within 30 characters:
12 ----------------------------------------------------------------------
12 ----------------------------------------------------------------------
13 This is some text in the first
13 This is some text in the first
14 paragraph.
14 paragraph.
15
15
16 A small indented paragraph.
16 A small indented paragraph.
17 It is followed by some lines
17 It is followed by some lines
18 containing random
18 containing random
19 whitespace.
19 whitespace.
20
20
21 The third and final paragraph.
21 The third and final paragraph.
22 ----------------------------------------------------------------------
22 ----------------------------------------------------------------------
23
23
24 definitions formatted to fit within 60 characters:
24 definitions formatted to fit within 60 characters:
25 ----------------------------------------------------------------------
25 ----------------------------------------------------------------------
26 A Term
26 A Term
27 Definition. The indented lines make up the definition.
27 Definition. The indented lines make up the definition.
28
28
29 Another Term
29 Another Term
30 Another definition. The final line in the definition
30 Another definition. The final line in the definition
31 determines the indentation, so this will be indented
31 determines the indentation, so this will be indented
32 with four spaces.
32 with four spaces.
33
33
34 A Nested/Indented Term
34 A Nested/Indented Term
35 Definition.
35 Definition.
36 ----------------------------------------------------------------------
36 ----------------------------------------------------------------------
37
37
38 definitions formatted to fit within 30 characters:
38 definitions formatted to fit within 30 characters:
39 ----------------------------------------------------------------------
39 ----------------------------------------------------------------------
40 A Term
40 A Term
41 Definition. The indented
41 Definition. The indented
42 lines make up the
42 lines make up the
43 definition.
43 definition.
44
44
45 Another Term
45 Another Term
46 Another definition. The
46 Another definition. The
47 final line in the
47 final line in the
48 definition determines the
48 definition determines the
49 indentation, so this will
49 indentation, so this will
50 be indented with four
50 be indented with four
51 spaces.
51 spaces.
52
52
53 A Nested/Indented Term
53 A Nested/Indented Term
54 Definition.
54 Definition.
55 ----------------------------------------------------------------------
55 ----------------------------------------------------------------------
56
56
57 literals formatted to fit within 60 characters:
57 literals formatted to fit within 60 characters:
58 ----------------------------------------------------------------------
58 ----------------------------------------------------------------------
59 The fully minimized form is the most convenient form:
59 The fully minimized form is the most convenient form:
60
60
61 Hello
61 Hello
62 literal
62 literal
63 world
63 world
64
64
65 In the partially minimized form a paragraph simply ends with
65 In the partially minimized form a paragraph simply ends with
66 space-double-colon.
66 space-double-colon.
67
67
68 ////////////////////////////////////////
68 ////////////////////////////////////////
69 long un-wrapped line in a literal block
69 long un-wrapped line in a literal block
70 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
70 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
71
71
72 This literal block is started with '::',
72 This literal block is started with '::',
73 the so-called expanded form. The paragraph
73 the so-called expanded form. The paragraph
74 with '::' disappears in the final output.
74 with '::' disappears in the final output.
75 ----------------------------------------------------------------------
75 ----------------------------------------------------------------------
76
76
77 literals formatted to fit within 30 characters:
77 literals formatted to fit within 30 characters:
78 ----------------------------------------------------------------------
78 ----------------------------------------------------------------------
79 The fully minimized form is
79 The fully minimized form is
80 the most convenient form:
80 the most convenient form:
81
81
82 Hello
82 Hello
83 literal
83 literal
84 world
84 world
85
85
86 In the partially minimized
86 In the partially minimized
87 form a paragraph simply ends
87 form a paragraph simply ends
88 with space-double-colon.
88 with space-double-colon.
89
89
90 ////////////////////////////////////////
90 ////////////////////////////////////////
91 long un-wrapped line in a literal block
91 long un-wrapped line in a literal block
92 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
92 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
93
93
94 This literal block is started with '::',
94 This literal block is started with '::',
95 the so-called expanded form. The paragraph
95 the so-called expanded form. The paragraph
96 with '::' disappears in the final output.
96 with '::' disappears in the final output.
97 ----------------------------------------------------------------------
97 ----------------------------------------------------------------------
98
98
99 lists formatted to fit within 60 characters:
99 lists formatted to fit within 60 characters:
100 ----------------------------------------------------------------------
100 ----------------------------------------------------------------------
101 - This is the first list item.
101 - This is the first list item.
102
102
103 Second paragraph in the first list item.
103 Second paragraph in the first list item.
104
104
105 - List items need not be separated by a blank line.
105 - List items need not be separated by a blank line.
106 - And will be rendered without one in any case.
106 - And will be rendered without one in any case.
107
107
108 We can have indented lists:
108 We can have indented lists:
109
109
110 - This is an indented list item
110 - This is an indented list item
111 - Another indented list item:
111 - Another indented list item:
112
112
113 - A literal block in the middle
113 - A literal block in the middle
114 of an indented list.
114 of an indented list.
115
115
116 (The above is not a list item since we are in the literal block.)
116 (The above is not a list item since we are in the literal block.)
117
117
118 Literal block with no indentation (apart from
118 Literal block with no indentation (apart from
119 the two spaces added to all literal blocks).
119 the two spaces added to all literal blocks).
120
120
121 1. This is an enumerated list (first item).
121 1. This is an enumerated list (first item).
122 2. Continuing with the second item.
122 2. Continuing with the second item.
123 (1) foo
123 (1) foo
124 (2) bar
124 (2) bar
125 1) Another
125 1) Another
126 2) List
126 2) List
127
127
128 Line blocks are also a form of list:
128 Line blocks are also a form of list:
129
129
130 This is the first line. The line continues here.
130 This is the first line. The line continues here.
131 This is the second line.
131 This is the second line.
132 ----------------------------------------------------------------------
132 ----------------------------------------------------------------------
133
133
134 lists formatted to fit within 30 characters:
134 lists formatted to fit within 30 characters:
135 ----------------------------------------------------------------------
135 ----------------------------------------------------------------------
136 - This is the first list item.
136 - This is the first list item.
137
137
138 Second paragraph in the
138 Second paragraph in the
139 first list item.
139 first list item.
140
140
141 - List items need not be
141 - List items need not be
142 separated by a blank line.
142 separated by a blank line.
143 - And will be rendered without
143 - And will be rendered without
144 one in any case.
144 one in any case.
145
145
146 We can have indented lists:
146 We can have indented lists:
147
147
148 - This is an indented list
148 - This is an indented list
149 item
149 item
150 - Another indented list
150 - Another indented list
151 item:
151 item:
152
152
153 - A literal block in the middle
153 - A literal block in the middle
154 of an indented list.
154 of an indented list.
155
155
156 (The above is not a list item since we are in the literal block.)
156 (The above is not a list item since we are in the literal block.)
157
157
158 Literal block with no indentation (apart from
158 Literal block with no indentation (apart from
159 the two spaces added to all literal blocks).
159 the two spaces added to all literal blocks).
160
160
161 1. This is an enumerated list
161 1. This is an enumerated list
162 (first item).
162 (first item).
163 2. Continuing with the second
163 2. Continuing with the second
164 item.
164 item.
165 (1) foo
165 (1) foo
166 (2) bar
166 (2) bar
167 1) Another
167 1) Another
168 2) List
168 2) List
169
169
170 Line blocks are also a form of
170 Line blocks are also a form of
171 list:
171 list:
172
172
173 This is the first line. The
173 This is the first line. The
174 line continues here.
174 line continues here.
175 This is the second line.
175 This is the second line.
176 ----------------------------------------------------------------------
176 ----------------------------------------------------------------------
177
177
178 options formatted to fit within 60 characters:
178 options formatted to fit within 60 characters:
179 ----------------------------------------------------------------------
179 ----------------------------------------------------------------------
180 There is support for simple option lists, but only with long
180 There is support for simple option lists, but only with long
181 options:
181 options:
182
182
183 --all Output all.
183 --all Output all.
184 --both Output both (this description is quite long).
184 --both Output both (this description is quite long).
185 --long Output all day long.
185 --long Output all day long.
186 --par This option has two paragraphs in its
186 --par This option has two paragraphs in its
187 description. This is the first.
187 description. This is the first.
188
188
189 This is the second. Blank lines may be omitted
189 This is the second. Blank lines may be omitted
190 between options (as above) or left in (as here).
190 between options (as above) or left in (as here).
191
191
192 The next paragraph looks like an option list, but lacks the
192 The next paragraph looks like an option list, but lacks the
193 two-space marker after the option. It is treated as a normal
193 two-space marker after the option. It is treated as a normal
194 paragraph:
194 paragraph:
195
195
196 --foo bar baz
196 --foo bar baz
197 ----------------------------------------------------------------------
197 ----------------------------------------------------------------------
198
198
199 options formatted to fit within 30 characters:
199 options formatted to fit within 30 characters:
200 ----------------------------------------------------------------------
200 ----------------------------------------------------------------------
201 There is support for simple
201 There is support for simple
202 option lists, but only with
202 option lists, but only with
203 long options:
203 long options:
204
204
205 --all Output all.
205 --all Output all.
206 --both Output both (this
206 --both Output both (this
207 description is
207 description is
208 quite long).
208 quite long).
209 --long Output all day
209 --long Output all day
210 long.
210 long.
211 --par This option has two
211 --par This option has two
212 paragraphs in its
212 paragraphs in its
213 description. This
213 description. This
214 is the first.
214 is the first.
215
215
216 This is the second.
216 This is the second.
217 Blank lines may be
217 Blank lines may be
218 omitted between
218 omitted between
219 options (as above)
219 options (as above)
220 or left in (as
220 or left in (as
221 here).
221 here).
222
222
223 The next paragraph looks like
223 The next paragraph looks like
224 an option list, but lacks the
224 an option list, but lacks the
225 two-space marker after the
225 two-space marker after the
226 option. It is treated as a
226 option. It is treated as a
227 normal paragraph:
227 normal paragraph:
228
228
229 --foo bar baz
229 --foo bar baz
230 ----------------------------------------------------------------------
230 ----------------------------------------------------------------------
231
231
232 fields formatted to fit within 60 characters:
232 fields formatted to fit within 60 characters:
233 ----------------------------------------------------------------------
233 ----------------------------------------------------------------------
234 a First item.
234 a First item.
235 ab Second item. Indentation and wrapping is handled
235 ab Second item. Indentation and wrapping is handled
236 automatically.
236 automatically.
237
237
238 Next list:
238 Next list:
239
239
240 small The larger key below triggers full indentation
240 small The larger key below triggers full indentation
241 here.
241 here.
242 much too large
242 much too large
243 This key is big enough to get its own line.
243 This key is big enough to get its own line.
244 ----------------------------------------------------------------------
244 ----------------------------------------------------------------------
245
245
246 fields formatted to fit within 30 characters:
246 fields formatted to fit within 30 characters:
247 ----------------------------------------------------------------------
247 ----------------------------------------------------------------------
248 a First item.
248 a First item.
249 ab Second item. Indentation
249 ab Second item. Indentation
250 and wrapping is handled
250 and wrapping is handled
251 automatically.
251 automatically.
252
252
253 Next list:
253 Next list:
254
254
255 small The larger key
255 small The larger key
256 below triggers
256 below triggers
257 full indentation
257 full indentation
258 here.
258 here.
259 much too large
259 much too large
260 This key is big
260 This key is big
261 enough to get its
261 enough to get its
262 own line.
262 own line.
263 ----------------------------------------------------------------------
263 ----------------------------------------------------------------------
264
264
265 containers (normal) formatted to fit within 60 characters:
265 containers (normal) formatted to fit within 60 characters:
266 ----------------------------------------------------------------------
266 ----------------------------------------------------------------------
267 Normal output.
267 Normal output.
268 ----------------------------------------------------------------------
268 ----------------------------------------------------------------------
269
269
270 containers (verbose) formatted to fit within 60 characters:
270 containers (verbose) formatted to fit within 60 characters:
271 ----------------------------------------------------------------------
271 ----------------------------------------------------------------------
272 Normal output.
272 Normal output.
273
273
274 Verbose output.
274 Verbose output.
275 ----------------------------------------------------------------------
275 ----------------------------------------------------------------------
276 ['debug', 'debug']
276 ['debug', 'debug']
277 ----------------------------------------------------------------------
277 ----------------------------------------------------------------------
278
278
279 containers (debug) formatted to fit within 60 characters:
279 containers (debug) formatted to fit within 60 characters:
280 ----------------------------------------------------------------------
280 ----------------------------------------------------------------------
281 Normal output.
281 Normal output.
282
282
283 Initial debug output.
283 Initial debug output.
284 ----------------------------------------------------------------------
284 ----------------------------------------------------------------------
285 ['verbose']
285 ['verbose']
286 ----------------------------------------------------------------------
286 ----------------------------------------------------------------------
287
287
288 containers (verbose debug) formatted to fit within 60 characters:
288 containers (verbose debug) formatted to fit within 60 characters:
289 ----------------------------------------------------------------------
289 ----------------------------------------------------------------------
290 Normal output.
290 Normal output.
291
291
292 Initial debug output.
292 Initial debug output.
293
293
294 Verbose output.
294 Verbose output.
295
295
296 Debug output.
296 Debug output.
297 ----------------------------------------------------------------------
297 ----------------------------------------------------------------------
298 []
298 []
299 ----------------------------------------------------------------------
299 ----------------------------------------------------------------------
300
300
301 roles formatted to fit within 60 characters:
301 roles formatted to fit within 60 characters:
302 ----------------------------------------------------------------------
302 ----------------------------------------------------------------------
303 Please see "hg add".
303 Please see "hg add".
304 ----------------------------------------------------------------------
304 ----------------------------------------------------------------------
305
305
306 sections formatted to fit within 20 characters:
307 ----------------------------------------------------------------------
308 A Somewhat Wide Section Header
309 ------------------------------
310 ----------------------------------------------------------------------
311
General Comments 0
You need to be logged in to leave comments. Login now