Spelling fixes
[docutils.git] / test / test_parsers / test_rst / test_section_headers.py
blob5b74365984a0668be08a8adb5bacea0760bc3530
1 # -*- coding: utf-8 -*-
2 #! /usr/bin/env python
4 # $Id$
5 # Author: David Goodger <goodger@python.org>
6 # Copyright: This module has been placed in the public domain.
8 """Tests for states.py."""
10 from __init__ import DocutilsTestSupport
12 def suite():
13 s = DocutilsTestSupport.ParserTestSuite()
14 s.generateTests(totest)
15 return s
17 totest = {}
19 totest['section_headers'] = [
20 ["""\
21 Title
22 =====
24 Paragraph.
25 """,
26 """\
27 <document source="test data">
28 <section ids="title" names="title">
29 <title>
30 Title
31 <paragraph>
32 Paragraph.
33 """],
34 ["""\
35 Title
36 =====
37 Paragraph (no blank line).
38 """,
39 """\
40 <document source="test data">
41 <section ids="title" names="title">
42 <title>
43 Title
44 <paragraph>
45 Paragraph (no blank line).
46 """],
47 ["""\
48 Paragraph.
50 Title
51 =====
53 Paragraph.
54 """,
55 """\
56 <document source="test data">
57 <paragraph>
58 Paragraph.
59 <section ids="title" names="title">
60 <title>
61 Title
62 <paragraph>
63 Paragraph.
64 """],
65 ["""\
66 Test unexpected section titles.
68 Title
69 =====
70 Paragraph.
72 -----
73 Title
74 -----
75 Paragraph.
76 """,
77 """\
78 <document source="test data">
79 <paragraph>
80 Test unexpected section titles.
81 <block_quote>
82 <system_message level="4" line="4" source="test data" type="SEVERE">
83 <paragraph>
84 Unexpected section title.
85 <literal_block xml:space="preserve">
86 Title
87 =====
88 <paragraph>
89 Paragraph.
90 <system_message level="4" line="7" source="test data" type="SEVERE">
91 <paragraph>
92 Unexpected section title or transition.
93 <literal_block xml:space="preserve">
94 -----
95 <system_message level="4" line="9" source="test data" type="SEVERE">
96 <paragraph>
97 Unexpected section title.
98 <literal_block xml:space="preserve">
99 Title
100 -----
101 <paragraph>
102 Paragraph.
103 """],
104 ["""\
105 Title
106 ====
108 Test short underline.
109 """,
110 """\
111 <document source="test data">
112 <section ids="title" names="title">
113 <title>
114 Title
115 <system_message level="2" line="2" source="test data" type="WARNING">
116 <paragraph>
117 Title underline too short.
118 <literal_block xml:space="preserve">
119 Title
120 ====
121 <paragraph>
122 Test short underline.
123 """],
124 [u"""\
125 à with combining varia
126 ======================
128 Do not count combining chars in title column width.
129 """,
130 u"""\
131 <document source="test data">
132 <section ids="a-with-combining-varia" names="a\u0300\ with\ combining\ varia">
133 <title>
134 à with combining varia
135 <paragraph>
136 Do not count combining chars in title column width.
137 """],
138 ["""\
139 =====
140 Title
141 =====
143 Test overline title.
144 """,
145 """\
146 <document source="test data">
147 <section ids="title" names="title">
148 <title>
149 Title
150 <paragraph>
151 Test overline title.
152 """],
153 ["""\
154 =======
155 Title
156 =======
158 Test overline title with inset.
159 """,
160 """\
161 <document source="test data">
162 <section ids="title" names="title">
163 <title>
164 Title
165 <paragraph>
166 Test overline title with inset.
167 """],
168 ["""\
169 ========================
170 Test Missing Underline
171 """,
172 """\
173 <document source="test data">
174 <system_message level="4" line="1" source="test data" type="SEVERE">
175 <paragraph>
176 Incomplete section title.
177 <literal_block xml:space="preserve">
178 ========================
179 Test Missing Underline
180 """],
181 ["""\
182 ========================
183 Test Missing Underline
185 """,
186 """\
187 <document source="test data">
188 <system_message level="4" line="1" source="test data" type="SEVERE">
189 <paragraph>
190 Missing matching underline for section title overline.
191 <literal_block xml:space="preserve">
192 ========================
193 Test Missing Underline
194 """],
195 ["""\
196 =======
197 Title
199 Test missing underline, with paragraph.
200 """,
201 """\
202 <document source="test data">
203 <system_message level="4" line="1" source="test data" type="SEVERE">
204 <paragraph>
205 Missing matching underline for section title overline.
206 <literal_block xml:space="preserve">
207 =======
208 Title
209 <paragraph>
210 Test missing underline, with paragraph.
211 """],
212 ["""\
213 =======
214 Long Title
215 =======
217 Test long title and space normalization.
218 """,
219 """\
220 <document source="test data">
221 <section ids="long-title" names="long\ title">
222 <title>
223 Long Title
224 <system_message level="2" line="1" source="test data" type="WARNING">
225 <paragraph>
226 Title overline too short.
227 <literal_block xml:space="preserve">
228 =======
229 Long Title
230 =======
231 <paragraph>
232 Test long title and space normalization.
233 """],
234 ["""\
235 =======
236 Title
237 -------
239 Paragraph.
240 """,
241 """\
242 <document source="test data">
243 <system_message level="4" line="1" source="test data" type="SEVERE">
244 <paragraph>
245 Title overline & underline mismatch.
246 <literal_block xml:space="preserve">
247 =======
248 Title
249 -------
250 <paragraph>
251 Paragraph.
252 """],
253 ["""\
254 ========================
256 ========================
258 Test missing titles; blank line in-between.
260 ========================
262 ========================
263 """,
264 """\
265 <document source="test data">
266 <transition>
267 <transition>
268 <paragraph>
269 Test missing titles; blank line in-between.
270 <transition>
271 <transition>
272 """],
273 ["""\
274 ========================
275 ========================
277 Test missing titles; nothing in-between.
279 ========================
280 ========================
281 """,
282 """\
283 <document source="test data">
284 <system_message level="3" line="1" source="test data" type="ERROR">
285 <paragraph>
286 Invalid section title or transition marker.
287 <literal_block xml:space="preserve">
288 ========================
289 ========================
290 <paragraph>
291 Test missing titles; nothing in-between.
292 <system_message level="3" line="6" source="test data" type="ERROR">
293 <paragraph>
294 Invalid section title or transition marker.
295 <literal_block xml:space="preserve">
296 ========================
297 ========================
298 """],
299 ["""\
300 .. Test return to existing, highest-level section (Title 3).
302 Title 1
303 =======
304 Paragraph 1.
306 Title 2
307 -------
308 Paragraph 2.
310 Title 3
311 =======
312 Paragraph 3.
314 Title 4
315 -------
316 Paragraph 4.
317 """,
318 """\
319 <document source="test data">
320 <comment xml:space="preserve">
321 Test return to existing, highest-level section (Title 3).
322 <section ids="title-1" names="title\ 1">
323 <title>
324 Title 1
325 <paragraph>
326 Paragraph 1.
327 <section ids="title-2" names="title\ 2">
328 <title>
329 Title 2
330 <paragraph>
331 Paragraph 2.
332 <section ids="title-3" names="title\ 3">
333 <title>
334 Title 3
335 <paragraph>
336 Paragraph 3.
337 <section ids="title-4" names="title\ 4">
338 <title>
339 Title 4
340 <paragraph>
341 Paragraph 4.
342 """],
343 ["""\
344 Test return to existing, highest-level section (Title 3, with overlines).
346 =======
347 Title 1
348 =======
349 Paragraph 1.
351 -------
352 Title 2
353 -------
354 Paragraph 2.
356 =======
357 Title 3
358 =======
359 Paragraph 3.
361 -------
362 Title 4
363 -------
364 Paragraph 4.
365 """,
366 """\
367 <document source="test data">
368 <paragraph>
369 Test return to existing, highest-level section (Title 3, with overlines).
370 <section ids="title-1" names="title\ 1">
371 <title>
372 Title 1
373 <paragraph>
374 Paragraph 1.
375 <section ids="title-2" names="title\ 2">
376 <title>
377 Title 2
378 <paragraph>
379 Paragraph 2.
380 <section ids="title-3" names="title\ 3">
381 <title>
382 Title 3
383 <paragraph>
384 Paragraph 3.
385 <section ids="title-4" names="title\ 4">
386 <title>
387 Title 4
388 <paragraph>
389 Paragraph 4.
390 """],
391 ["""\
392 Test return to existing, higher-level section (Title 4).
394 Title 1
395 =======
396 Paragraph 1.
398 Title 2
399 -------
400 Paragraph 2.
402 Title 3
403 ```````
404 Paragraph 3.
406 Title 4
407 -------
408 Paragraph 4.
409 """,
410 """\
411 <document source="test data">
412 <paragraph>
413 Test return to existing, higher-level section (Title 4).
414 <section ids="title-1" names="title\ 1">
415 <title>
416 Title 1
417 <paragraph>
418 Paragraph 1.
419 <section ids="title-2" names="title\ 2">
420 <title>
421 Title 2
422 <paragraph>
423 Paragraph 2.
424 <section ids="title-3" names="title\ 3">
425 <title>
426 Title 3
427 <paragraph>
428 Paragraph 3.
429 <section ids="title-4" names="title\ 4">
430 <title>
431 Title 4
432 <paragraph>
433 Paragraph 4.
434 """],
435 ["""\
436 Test bad subsection order (Title 4).
438 Title 1
439 =======
440 Paragraph 1.
442 Title 2
443 -------
444 Paragraph 2.
446 Title 3
447 =======
448 Paragraph 3.
450 Title 4
451 ```````
452 Paragraph 4.
453 """,
454 """\
455 <document source="test data">
456 <paragraph>
457 Test bad subsection order (Title 4).
458 <section ids="title-1" names="title\ 1">
459 <title>
460 Title 1
461 <paragraph>
462 Paragraph 1.
463 <section ids="title-2" names="title\ 2">
464 <title>
465 Title 2
466 <paragraph>
467 Paragraph 2.
468 <section ids="title-3" names="title\ 3">
469 <title>
470 Title 3
471 <paragraph>
472 Paragraph 3.
473 <system_message level="4" line="15" source="test data" type="SEVERE">
474 <paragraph>
475 Title level inconsistent:
476 <literal_block xml:space="preserve">
477 Title 4
478 ```````
479 <paragraph>
480 Paragraph 4.
481 """],
482 ["""\
483 Test bad subsection order (Title 4, with overlines).
485 =======
486 Title 1
487 =======
488 Paragraph 1.
490 -------
491 Title 2
492 -------
493 Paragraph 2.
495 =======
496 Title 3
497 =======
498 Paragraph 3.
500 ```````
501 Title 4
502 ```````
503 Paragraph 4.
504 """,
505 """\
506 <document source="test data">
507 <paragraph>
508 Test bad subsection order (Title 4, with overlines).
509 <section ids="title-1" names="title\ 1">
510 <title>
511 Title 1
512 <paragraph>
513 Paragraph 1.
514 <section ids="title-2" names="title\ 2">
515 <title>
516 Title 2
517 <paragraph>
518 Paragraph 2.
519 <section ids="title-3" names="title\ 3">
520 <title>
521 Title 3
522 <paragraph>
523 Paragraph 3.
524 <system_message level="4" line="19" source="test data" type="SEVERE">
525 <paragraph>
526 Title level inconsistent:
527 <literal_block xml:space="preserve">
528 ```````
529 Title 4
530 ```````
531 <paragraph>
532 Paragraph 4.
533 """],
534 ["""\
535 Title containing *inline* ``markup``
536 ====================================
538 Paragraph.
539 """,
540 """\
541 <document source="test data">
542 <section ids="title-containing-inline-markup" names="title\ containing\ inline\ markup">
543 <title>
544 Title containing \n\
545 <emphasis>
546 inline
548 <literal>
549 markup
550 <paragraph>
551 Paragraph.
552 """],
553 ["""\
554 1. Numbered Title
555 =================
557 Paragraph.
558 """,
559 """\
560 <document source="test data">
561 <section ids="numbered-title" names="1.\ numbered\ title">
562 <title>
563 1. Numbered Title
564 <paragraph>
565 Paragraph.
566 """],
567 ["""\
568 1. Item 1.
569 2. Item 2.
570 3. Numbered Title
571 =================
573 Paragraph.
574 """,
575 """\
576 <document source="test data">
577 <enumerated_list enumtype="arabic" prefix="" suffix=".">
578 <list_item>
579 <paragraph>
580 Item 1.
581 <list_item>
582 <paragraph>
583 Item 2.
584 <system_message level="2" line="3" source="test data" type="WARNING">
585 <paragraph>
586 Enumerated list ends without a blank line; unexpected unindent.
587 <section ids="numbered-title" names="3.\ numbered\ title">
588 <title>
589 3. Numbered Title
590 <paragraph>
591 Paragraph.
592 """],
593 ["""\
597 Short title.
598 """,
599 """\
600 <document source="test data">
601 <section ids="abc" names="abc">
602 <title>
604 <paragraph>
605 Short title.
606 """],
607 ["""\
611 Underline too short.
612 """,
613 """\
614 <document source="test data">
615 <system_message level="1" line="2" source="test data" type="INFO">
616 <paragraph>
617 Possible title underline, too short for the title.
618 Treating it as ordinary text because it's so short.
619 <paragraph>
622 <paragraph>
623 Underline too short.
624 """],
625 ["""\
630 Over & underline too short.
631 """,
632 """\
633 <document source="test data">
634 <system_message level="1" line="1" source="test data" type="INFO">
635 <paragraph>
636 Possible incomplete section title.
637 Treating the overline as ordinary text because it's so short.
638 <paragraph>
642 <paragraph>
643 Over & underline too short.
644 """],
645 ["""\
649 Overline too short, no underline.
650 """,
651 """\
652 <document source="test data">
653 <system_message level="1" line="1" source="test data" type="INFO">
654 <paragraph>
655 Possible incomplete section title.
656 Treating the overline as ordinary text because it's so short.
657 <paragraph>
660 <paragraph>
661 Overline too short, no underline.
662 """],
663 ["""\
666 """,
667 """\
668 <document source="test data">
669 <system_message level="1" line="1" source="test data" type="INFO">
670 <paragraph>
671 Possible incomplete section title.
672 Treating the overline as ordinary text because it's so short.
673 <paragraph>
676 """],
677 ["""\
679 Not a title: a definition list item.
680 """,
681 """\
682 <document source="test data">
683 <system_message level="1" line="1" source="test data" type="INFO">
684 <paragraph>
685 Possible incomplete section title.
686 Treating the overline as ordinary text because it's so short.
687 <definition_list>
688 <definition_list_item>
689 <term>
691 <definition>
692 <paragraph>
693 Not a title: a definition list item.
694 """],
695 ["""\
697 Not a title: a definition list item.
699 Another definition list item. It's in a different list,
700 but that's an acceptable limitation given that this will
701 probably never happen in real life.
703 The next line will trigger a warning:
705 """,
706 """\
707 <document source="test data">
708 <system_message level="1" line="1" source="test data" type="INFO">
709 <paragraph>
710 Possible incomplete section title.
711 Treating the overline as ordinary text because it's so short.
712 <definition_list>
713 <definition_list_item>
714 <term>
716 <definition>
717 <paragraph>
718 Not a title: a definition list item.
719 <system_message level="2" line="3" source="test data" type="WARNING">
720 <paragraph>
721 Definition list ends without a blank line; unexpected unindent.
722 <system_message level="1" line="3" source="test data" type="INFO">
723 <paragraph>
724 Possible incomplete section title.
725 Treating the overline as ordinary text because it's so short.
726 <definition_list>
727 <definition_list_item>
728 <term>
730 <definition>
731 <paragraph>
732 Another definition list item. It's in a different list,
733 but that's an acceptable limitation given that this will
734 probably never happen in real life.
735 <paragraph>
736 The next line will trigger a warning:
737 <system_message level="2" line="9" source="test data" type="WARNING">
738 <paragraph>
739 Definition list ends without a blank line; unexpected unindent.
740 <paragraph>
742 """],
743 ["""\
744 Paragraph
750 Over & underline too short.
751 """,
752 """\
753 <document source="test data">
754 <paragraph>
755 Paragraph
756 <block_quote>
757 <system_message level="1" line="3" source="test data" type="INFO">
758 <paragraph>
759 Unexpected possible title overline or transition.
760 Treating it as ordinary text because it's so short.
761 <paragraph>
765 <paragraph>
766 Over & underline too short.
767 """],
768 ["""\
769 Paragraph
774 Underline too short.
775 """,
776 """\
777 <document source="test data">
778 <paragraph>
779 Paragraph
780 <block_quote>
781 <paragraph>
784 <paragraph>
785 Underline too short.
786 """],
787 ["""\
797 """,
798 """\
799 <document source="test data">
800 <system_message level="1" line="1" source="test data" type="INFO">
801 <paragraph>
802 Possible incomplete section title.
803 Treating the overline as ordinary text because it's so short.
804 <section dupnames="..." ids="id1">
805 <title>
807 <system_message level="1" line="4" source="test data" type="INFO">
808 <paragraph>
809 Possible incomplete section title.
810 Treating the overline as ordinary text because it's so short.
811 <section dupnames="..." ids="id2">
812 <title>
814 <system_message backrefs="id2" level="1" line="5" source="test data" type="INFO">
815 <paragraph>
816 Duplicate implicit target name: "...".
817 <system_message level="1" line="7" source="test data" type="INFO">
818 <paragraph>
819 Possible incomplete section title.
820 Treating the overline as ordinary text because it's so short.
821 <system_message level="1" line="7" source="test data" type="INFO">
822 <paragraph>
823 Possible incomplete section title.
824 Treating the overline as ordinary text because it's so short.
825 <section dupnames="..." ids="id3">
826 <title>
828 <system_message backrefs="id3" level="1" line="8" source="test data" type="INFO">
829 <paragraph>
830 Duplicate implicit target name: "...".
831 <paragraph>
833 """],
834 ["""\
844 """,
845 """\
846 <document source="test data">
847 <comment xml:space="preserve">
848 <system_message level="2" line="2" source="test data" type="WARNING">
849 <paragraph>
850 Explicit markup ends without a blank line; unexpected unindent.
851 <section ids="hi" names="hi">
852 <title>
854 <section ids="yo" names="yo">
855 <title>
857 <paragraph>
859 """],
860 ["""\
861 Empty Section
862 =============
863 """,
864 """\
865 <document source="test data">
866 <section ids="empty-section" names="empty\ section">
867 <title>
868 Empty Section
869 """],
870 ["""\
875 The bubble-up parser strategy conflicts with short titles
876 (<= 3 char-long over- & underlines).
882 The parser currently contains a work-around kludge.
883 Without it, the parser ends up in an infinite loop.
884 """,
885 """\
886 <document source="test data">
887 <section ids="one" names="one">
888 <title>
890 <paragraph>
891 The bubble-up parser strategy conflicts with short titles
892 (<= 3 char-long over- & underlines).
893 <section ids="two" names="two">
894 <title>
896 <paragraph>
897 The parser currently contains a work-around kludge.
898 Without it, the parser ends up in an infinite loop.
899 """],
900 ["""\
901 """,
902 """\
903 <document source="test data">
904 """],
908 if __name__ == '__main__':
909 import unittest
910 unittest.main(defaultTest='suite')