Clean up and update TODO list.
[docutils.git] / docutils / test / test_parsers / test_rst / test_option_lists.py
blob7ae01db25389f7d023a173e12beb022c57118276
1 #! /usr/bin/env python3
3 # $Id$
4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Tests for states.py.
9 """
11 from pathlib import Path
12 import sys
13 import unittest
15 if __name__ == '__main__':
16 # prepend the "docutils root" to the Python library path
17 # so we import the local `docutils` package.
18 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
20 from docutils.frontend import get_default_settings
21 from docutils.parsers.rst import Parser
22 from docutils.utils import new_document
25 class ParserTestCase(unittest.TestCase):
26 maxDiff = None
28 def test_parser(self):
29 parser = Parser()
30 settings = get_default_settings(Parser)
31 settings.warning_stream = ''
32 for name, cases in totest.items():
33 for casenum, (case_input, case_expected) in enumerate(cases):
34 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
35 document = new_document('test data', settings.copy())
36 parser.parse(case_input, document)
37 output = document.pformat()
38 self.assertEqual(case_expected, output)
41 totest = {}
43 totest['option_lists'] = [
44 ["""\
45 Short options:
47 -a option -a
49 -b file option -b
51 -c name option -c
52 """,
53 """\
54 <document source="test data">
55 <paragraph>
56 Short options:
57 <option_list>
58 <option_list_item>
59 <option_group>
60 <option>
61 <option_string>
63 <description>
64 <paragraph>
65 option -a
66 <option_list_item>
67 <option_group>
68 <option>
69 <option_string>
71 <option_argument delimiter=" ">
72 file
73 <description>
74 <paragraph>
75 option -b
76 <option_list_item>
77 <option_group>
78 <option>
79 <option_string>
81 <option_argument delimiter=" ">
82 name
83 <description>
84 <paragraph>
85 option -c
86 """],
87 ["""\
88 Long options:
90 --aaaa option --aaaa
91 --bbbb=file option --bbbb
92 --cccc name option --cccc
93 --d-e-f-g option --d-e-f-g
94 --h_i_j_k option --h_i_j_k
95 """,
96 """\
97 <document source="test data">
98 <paragraph>
99 Long options:
100 <option_list>
101 <option_list_item>
102 <option_group>
103 <option>
104 <option_string>
105 --aaaa
106 <description>
107 <paragraph>
108 option --aaaa
109 <option_list_item>
110 <option_group>
111 <option>
112 <option_string>
113 --bbbb
114 <option_argument delimiter="=">
115 file
116 <description>
117 <paragraph>
118 option --bbbb
119 <option_list_item>
120 <option_group>
121 <option>
122 <option_string>
123 --cccc
124 <option_argument delimiter=" ">
125 name
126 <description>
127 <paragraph>
128 option --cccc
129 <option_list_item>
130 <option_group>
131 <option>
132 <option_string>
133 --d-e-f-g
134 <description>
135 <paragraph>
136 option --d-e-f-g
137 <option_list_item>
138 <option_group>
139 <option>
140 <option_string>
141 --h_i_j_k
142 <description>
143 <paragraph>
144 option --h_i_j_k
145 """],
146 ["""\
147 Old GNU-style options:
149 +a option +a
151 +b file option +b
153 +c name option +c
154 """,
155 """\
156 <document source="test data">
157 <paragraph>
158 Old GNU-style options:
159 <option_list>
160 <option_list_item>
161 <option_group>
162 <option>
163 <option_string>
165 <description>
166 <paragraph>
167 option +a
168 <option_list_item>
169 <option_group>
170 <option>
171 <option_string>
173 <option_argument delimiter=" ">
174 file
175 <description>
176 <paragraph>
177 option +b
178 <option_list_item>
179 <option_group>
180 <option>
181 <option_string>
183 <option_argument delimiter=" ">
184 name
185 <description>
186 <paragraph>
187 option +c
188 """],
189 ["""\
190 VMS/DOS-style options:
192 /A option /A
193 /B file option /B
194 /CCC option /CCC
195 /DDD string option /DDD
196 /EEE=int option /EEE
197 """,
198 """\
199 <document source="test data">
200 <paragraph>
201 VMS/DOS-style options:
202 <option_list>
203 <option_list_item>
204 <option_group>
205 <option>
206 <option_string>
208 <description>
209 <paragraph>
210 option /A
211 <option_list_item>
212 <option_group>
213 <option>
214 <option_string>
216 <option_argument delimiter=" ">
217 file
218 <description>
219 <paragraph>
220 option /B
221 <option_list_item>
222 <option_group>
223 <option>
224 <option_string>
225 /CCC
226 <description>
227 <paragraph>
228 option /CCC
229 <option_list_item>
230 <option_group>
231 <option>
232 <option_string>
233 /DDD
234 <option_argument delimiter=" ">
235 string
236 <description>
237 <paragraph>
238 option /DDD
239 <option_list_item>
240 <option_group>
241 <option>
242 <option_string>
243 /EEE
244 <option_argument delimiter="=">
246 <description>
247 <paragraph>
248 option /EEE
249 """],
250 ["""\
251 Mixed short, long, and VMS/DOS options:
253 -a option -a
254 --bbbb=file option -bbbb
255 /C option /C
256 --dddd name option --dddd
257 -e string option -e
258 /F file option /F
259 """,
260 """\
261 <document source="test data">
262 <paragraph>
263 Mixed short, long, and VMS/DOS options:
264 <option_list>
265 <option_list_item>
266 <option_group>
267 <option>
268 <option_string>
270 <description>
271 <paragraph>
272 option -a
273 <option_list_item>
274 <option_group>
275 <option>
276 <option_string>
277 --bbbb
278 <option_argument delimiter="=">
279 file
280 <description>
281 <paragraph>
282 option -bbbb
283 <option_list_item>
284 <option_group>
285 <option>
286 <option_string>
288 <description>
289 <paragraph>
290 option /C
291 <option_list_item>
292 <option_group>
293 <option>
294 <option_string>
295 --dddd
296 <option_argument delimiter=" ">
297 name
298 <description>
299 <paragraph>
300 option --dddd
301 <option_list_item>
302 <option_group>
303 <option>
304 <option_string>
306 <option_argument delimiter=" ">
307 string
308 <description>
309 <paragraph>
310 option -e
311 <option_list_item>
312 <option_group>
313 <option>
314 <option_string>
316 <option_argument delimiter=" ">
317 file
318 <description>
319 <paragraph>
320 option /F
321 """],
322 ["""\
323 Aliased options:
325 -a, --aaaa, /A option -a, --aaaa, /A
326 -b file, --bbbb=file, /B file option -b, --bbbb, /B
327 """,
328 """\
329 <document source="test data">
330 <paragraph>
331 Aliased options:
332 <option_list>
333 <option_list_item>
334 <option_group>
335 <option>
336 <option_string>
338 <option>
339 <option_string>
340 --aaaa
341 <option>
342 <option_string>
344 <description>
345 <paragraph>
346 option -a, --aaaa, /A
347 <option_list_item>
348 <option_group>
349 <option>
350 <option_string>
352 <option_argument delimiter=" ">
353 file
354 <option>
355 <option_string>
356 --bbbb
357 <option_argument delimiter="=">
358 file
359 <option>
360 <option_string>
362 <option_argument delimiter=" ">
363 file
364 <description>
365 <paragraph>
366 option -b, --bbbb, /B
367 """],
368 ["""\
369 Multiple lines in descriptions, aligned:
371 -a option -a, line 1
372 line 2
373 -b file option -b, line 1
374 line 2
375 """,
376 """\
377 <document source="test data">
378 <paragraph>
379 Multiple lines in descriptions, aligned:
380 <option_list>
381 <option_list_item>
382 <option_group>
383 <option>
384 <option_string>
386 <description>
387 <paragraph>
388 option -a, line 1
389 line 2
390 <option_list_item>
391 <option_group>
392 <option>
393 <option_string>
395 <option_argument delimiter=" ">
396 file
397 <description>
398 <paragraph>
399 option -b, line 1
400 line 2
401 """],
402 ["""\
403 Multiple lines in descriptions, not aligned:
405 -a option -a, line 1
406 line 2
407 -b file option -b, line 1
408 line 2
409 """,
410 """\
411 <document source="test data">
412 <paragraph>
413 Multiple lines in descriptions, not aligned:
414 <option_list>
415 <option_list_item>
416 <option_group>
417 <option>
418 <option_string>
420 <description>
421 <paragraph>
422 option -a, line 1
423 line 2
424 <option_list_item>
425 <option_group>
426 <option>
427 <option_string>
429 <option_argument delimiter=" ">
430 file
431 <description>
432 <paragraph>
433 option -b, line 1
434 line 2
435 """],
436 ["""\
437 Descriptions begin on next line:
440 option -a, line 1
441 line 2
442 -b file
443 option -b, line 1
444 line 2
445 """,
446 """\
447 <document source="test data">
448 <paragraph>
449 Descriptions begin on next line:
450 <option_list>
451 <option_list_item>
452 <option_group>
453 <option>
454 <option_string>
456 <description>
457 <paragraph>
458 option -a, line 1
459 line 2
460 <option_list_item>
461 <option_group>
462 <option>
463 <option_string>
465 <option_argument delimiter=" ">
466 file
467 <description>
468 <paragraph>
469 option -b, line 1
470 line 2
471 """],
472 ["""\
473 Multiple body elements in descriptions:
475 -a option -a, para 1
477 para 2
478 -b file
479 option -b, para 1
481 para 2
482 """,
483 """\
484 <document source="test data">
485 <paragraph>
486 Multiple body elements in descriptions:
487 <option_list>
488 <option_list_item>
489 <option_group>
490 <option>
491 <option_string>
493 <description>
494 <paragraph>
495 option -a, para 1
496 <paragraph>
497 para 2
498 <option_list_item>
499 <option_group>
500 <option>
501 <option_string>
503 <option_argument delimiter=" ">
504 file
505 <description>
506 <paragraph>
507 option -b, para 1
508 <paragraph>
509 para 2
510 """],
511 ["""\
512 --option
513 empty item above, no blank line
514 """,
515 """\
516 <document source="test data">
517 <paragraph>
518 --option
519 empty item above, no blank line
520 """],
521 ["""\
522 An option list using equals:
524 --long1=arg1 Description 1
525 --long2=arg2 Description 2
527 An option list using spaces:
529 --long1 arg1 Description 1
530 --long2 arg2 Description 2
532 An option list using mixed delimiters:
534 --long1=arg1 Description 1
535 --long2 arg2 Description 2
537 An option list using mixed delimiters in one line:
539 --long1=arg1, --long2 arg2 Description
540 """,
541 """\
542 <document source="test data">
543 <paragraph>
544 An option list using equals:
545 <option_list>
546 <option_list_item>
547 <option_group>
548 <option>
549 <option_string>
550 --long1
551 <option_argument delimiter="=">
552 arg1
553 <description>
554 <paragraph>
555 Description 1
556 <option_list_item>
557 <option_group>
558 <option>
559 <option_string>
560 --long2
561 <option_argument delimiter="=">
562 arg2
563 <description>
564 <paragraph>
565 Description 2
566 <paragraph>
567 An option list using spaces:
568 <option_list>
569 <option_list_item>
570 <option_group>
571 <option>
572 <option_string>
573 --long1
574 <option_argument delimiter=" ">
575 arg1
576 <description>
577 <paragraph>
578 Description 1
579 <option_list_item>
580 <option_group>
581 <option>
582 <option_string>
583 --long2
584 <option_argument delimiter=" ">
585 arg2
586 <description>
587 <paragraph>
588 Description 2
589 <paragraph>
590 An option list using mixed delimiters:
591 <option_list>
592 <option_list_item>
593 <option_group>
594 <option>
595 <option_string>
596 --long1
597 <option_argument delimiter="=">
598 arg1
599 <description>
600 <paragraph>
601 Description 1
602 <option_list_item>
603 <option_group>
604 <option>
605 <option_string>
606 --long2
607 <option_argument delimiter=" ">
608 arg2
609 <description>
610 <paragraph>
611 Description 2
612 <paragraph>
613 An option list using mixed delimiters in one line:
614 <option_list>
615 <option_list_item>
616 <option_group>
617 <option>
618 <option_string>
619 --long1
620 <option_argument delimiter="=">
621 arg1
622 <option>
623 <option_string>
624 --long2
625 <option_argument delimiter=" ">
626 arg2
627 <description>
628 <paragraph>
629 Description
630 """],
631 ["""\
632 Some edge cases:
634 --option=arg arg too many arguments
636 --option=arg,arg not supported (yet?)
638 --option=arg=arg too many arguments
640 --option arg arg too many arguments
642 -a letter arg2 too many arguments
644 /A letter arg2 too many arguments
646 --option= argument missing
648 --=argument option missing
650 -- everything missing
652 - this should be a bullet list item
654 These next ones should be simple paragraphs:
658 --option
662 -1 and this one too.
663 """,
664 """\
665 <document source="test data">
666 <paragraph>
667 Some edge cases:
668 <paragraph>
669 --option=arg arg too many arguments
670 <paragraph>
671 --option=arg,arg not supported (yet?)
672 <paragraph>
673 --option=arg=arg too many arguments
674 <paragraph>
675 --option arg arg too many arguments
676 <paragraph>
677 -a letter arg2 too many arguments
678 <paragraph>
679 /A letter arg2 too many arguments
680 <paragraph>
681 --option= argument missing
682 <paragraph>
683 --=argument option missing
684 <paragraph>
685 -- everything missing
686 <bullet_list bullet="-">
687 <list_item>
688 <paragraph>
689 this should be a bullet list item
690 <paragraph>
691 These next ones should be simple paragraphs:
692 <paragraph>
694 <paragraph>
695 --option
696 <paragraph>
698 <paragraph>
699 -1 and this one too.
700 """],
701 ["""\
702 Complex optargs:
704 --source-url=<URL> Use the supplied <URL> verbatim.
705 --output-encoding=<name[:handler]>, -o<name[:handler]>
706 Specify the text encoding for output.
707 --af=<filter1[=parameter1:parameter2:...],filter2,...>
708 Setup a chain of audio filters.
709 Option argument containing delimiter ``=``.
710 -f <[path]filename> Send output to file.
711 -d <src dest> Use diff from <src> to <dest>.
712 --point=<x y z> 3D coordinates.
713 --vector <"x, y, z"> Another option expecting 3 arguments.
714 --cvs=<'a[, b[, ...]]]'>
715 Comma separated arguments.
716 -g <a, , c> Complex arg with empty list element.
717 """,
718 """\
719 <document source="test data">
720 <paragraph>
721 Complex optargs:
722 <option_list>
723 <option_list_item>
724 <option_group>
725 <option>
726 <option_string>
727 --source-url
728 <option_argument delimiter="=">
729 <URL>
730 <description>
731 <paragraph>
732 Use the supplied <URL> verbatim.
733 <option_list_item>
734 <option_group>
735 <option>
736 <option_string>
737 --output-encoding
738 <option_argument delimiter="=">
739 <name[:handler]>
740 <option>
741 <option_string>
743 <option_argument delimiter="">
744 <name[:handler]>
745 <description>
746 <paragraph>
747 Specify the text encoding for output.
748 <option_list_item>
749 <option_group>
750 <option>
751 <option_string>
752 --af
753 <option_argument delimiter="=">
754 <filter1[=parameter1:parameter2:...],filter2,...>
755 <description>
756 <paragraph>
757 Setup a chain of audio filters.
758 Option argument containing delimiter \n\
759 <literal>
762 <option_list_item>
763 <option_group>
764 <option>
765 <option_string>
767 <option_argument delimiter=" ">
768 <[path]filename>
769 <description>
770 <paragraph>
771 Send output to file.
772 <option_list_item>
773 <option_group>
774 <option>
775 <option_string>
777 <option_argument delimiter=" ">
778 <src dest>
779 <description>
780 <paragraph>
781 Use diff from <src> to <dest>.
782 <option_list_item>
783 <option_group>
784 <option>
785 <option_string>
786 --point
787 <option_argument delimiter="=">
788 <x y z>
789 <description>
790 <paragraph>
791 3D coordinates.
792 <option_list_item>
793 <option_group>
794 <option>
795 <option_string>
796 --vector
797 <option_argument delimiter=" ">
798 <"x, y, z">
799 <description>
800 <paragraph>
801 Another option expecting 3 arguments.
802 <option_list_item>
803 <option_group>
804 <option>
805 <option_string>
806 --cvs
807 <option_argument delimiter="=">
808 <'a[, b[, ...]]]'>
809 <description>
810 <paragraph>
811 Comma separated arguments.
812 <option_list_item>
813 <option_group>
814 <option>
815 <option_string>
817 <option_argument delimiter=" ">
818 <a, , c>
819 <description>
820 <paragraph>
821 Complex arg with empty list element.
822 """],
823 ["""\
824 Incorrect option syntax → no option list.
826 -f, , --force Empty synonym.
827 -f <a, , b Unbalanced angle bracket.
828 -f a, , b> Unbalanced angle bracket.
829 """,
830 """\
831 <document source="test data">
832 <paragraph>
833 Incorrect option syntax → no option list.
834 <paragraph>
835 -f, , --force Empty synonym.
836 -f <a, , b Unbalanced angle bracket.
837 -f a, , b> Unbalanced angle bracket.
838 """],
842 if __name__ == '__main__':
843 unittest.main()