1 #! /usr/bin/env python3
3 # Author: engelbert gruber <grubert@users.sourceforge.net>
4 # Copyright: This module has been placed in the public domain.
7 Tests for manpage writer.
10 from pathlib
import Path
14 if __name__
== '__main__':
15 # prepend the "docutils root" to the Python library path
16 # so we import the local `docutils` package.
17 sys
.path
.insert(0, str(Path(__file__
).resolve().parents
[2]))
19 from docutils
.core
import publish_string
22 class WriterPublishTestCase(unittest
.TestCase
):
23 def test_publish(self
):
24 writer_name
= 'manpage'
25 for name
, cases
in totest
.items():
26 for casenum
, (case_input
, case_expected
) in enumerate(cases
):
27 with self
.subTest(id=f
'totest[{name!r}][{casenum}]'):
28 output
= publish_string(
30 writer_name
=writer_name
,
32 '_disable_config': True,
33 'strict_visitor': True,
35 self
.assertEqual(case_expected
, output
)
39 .nr rst2man-indent-level 0
43 level \\n[rst2man-indent-level]
44 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
51 .\" .rstReportMargin pre
:
53 . nr rst2man
-indent
\\n
[rst2man
-indent
-level
] \\n
[an
-margin
]
54 . nr rst2man
-indent
-level
+1
55 .\" .rstReportMargin post
:
59 .\" indent
\\n
[an
-margin
]
60 .\" old
: \\n
[rst2man
-indent
\\n
[rst2man
-indent
-level
]]
61 .nr rst2man
-indent
-level
-1
62 .\" new
: \\n
[rst2man
-indent
\\n
[rst2man
-indent
-level
]]
63 .in \\n
[rst2man
-indent
\\n
[rst2man
-indent
-level
]]u
71 r""".\" Man page generated
from reStructuredText
.
73 """ + indend_macros + """.TH
"" "" ""
76 .\\" Generated by docutils manpage writer.
83 This broke docutils-sphinx.
86 r""".\" Man page generated from reStructuredText.
88 """ + indend_macros + """.TH "HELLO
, WORLD
." "" ""
95 This broke docutils\\-sphinx.
98 .\\" Generated by docutils manpage writer
.
113 :Author
: someone
@somewhere.net
115 :Copyright
: public domain
118 :Manual group
: text processing
119 :Arbitrary field
: some text
126 K
.I
.S
.S keep it simple
.
131 General rule of life
.
136 --config
=<file> Read configuration settings
from <file>, if it exists
.
137 --version
, -V Show this program
's version number and exit.
138 --help, -h Show this help message and exit.
147 Admonition with title
152 .. admonition:: homegrown
156 . period at line start.
158 and . in a line and at line start
161 r""".\" Man page generated from reStructuredText.
163 """ + indend_macros + r""".TH "SIMPLE" 1 "2009-08-05" "0.1" "text processing"
165 simple \- The way to go
171 K.I.S.S keep it simple.
177 General rule of life.
181 .BI \-\-config\fB= <file>
182 Read configuration settings from <file>, if it exists.
184 .B \-\-version\fP,\fB \-V
185 Show this program\(aqs version number and exit.
187 .B \-\-help\fP,\fB \-h
188 Show this help message and exit.
197 Admonition with title
214 \&. period at line start.
216 and . in a line and at line start
219 someone@somewhere.net
221 Arbitrary field: some text
224 .\" Generated by docutils manpage writer.
239 .\\" Man page generated from reStructuredText.
241 ''' + indend_macros + '''.TH "" "" ""
271 .\\" Generated by docutils manpage writer.
276 totest['optiongroup
'] = [
278 optin group with dot as group item
296 .\\" Man page generated from reStructuredText.
298 """ + indend_macros + """.TH "" "" ""
301 optin group with dot as group item
327 .\\" Generated by docutils manpage writer.
332 totest['definitionlist
'] = [
338 :Abstract: Docinfo is required.
345 Description of Term 1 Description of Term 1 Description of Term 1
346 Description of Term 1 Description of Term 1
348 Description of Term 1 Description of Term 1 Description of Term 1
349 Description of Term 1 Description of Term 1
353 .\\" Man page generated from reStructuredText.
355 ''' + indend_macros + '''.TH "DEFINITION LIST TEST" "" ""
357 Definition List Test \\- \n\
358 ''' + '''.SS Abstract
365 Description of Term 1 Description of Term 1 Description of Term 1
366 Description of Term 1 Description of Term 1
368 Description of Term 1 Description of Term 1 Description of Term 1
369 Description of Term 1 Description of Term 1
371 .\\" Generated by docutils manpage writer.
376 totest['cmdlineoptions
'] = [
377 ["""optional arguments:
378 -h, --help show this help
379 --output FILE, -o FILE output filename
380 -i DEVICE, --input DEVICE input device
382 r""".\" Man page generated from reStructuredText.
384 """ + indend_macros + """.TH "" "" ""
389 .B optional arguments:
392 .B \\-h\\fP,\\fB \\-\\-help
395 .BI \\-\\-output \\ FILE\\fR,\\fB \\ \\-o \\ FILE
398 .BI \\-i \\ DEVICE\\fR,\\fB \\ \\-\\-input \\ DEVICE
402 .\\" Generated by docutils manpage writer.
407 totest['citation
'] = [
408 [""".. [docutils] blah blah blah
411 r""".\" Man page generated from reStructuredText.
413 """ + indend_macros + """.TH "" "" ""
418 .IP [empty_citation] 5
419 .\\" Generated by docutils manpage writer.
425 [""".. rubric:: some rubric
430 r""".\" Man page generated from reStructuredText.
432 """ + indend_macros + """.TH "" "" ""
442 .\\" Generated by docutils manpage writer.
447 totest['double_quote
'] = [
448 ["""in "defintion list"
449 double quotes must be escaped on macro invocations.
451 They are "escaped" anywhere.
453 r""".\" Man page generated from reStructuredText.
455 """ + indend_macros + """.TH "" "" ""
460 .B in \\(dqdefintion list\\(dq
461 double quotes must be escaped on macro invocations.
464 They are \\(dqescaped\\(dq anywhere.
465 .\\" Generated by docutils manpage writer.
470 totest['man_header
'] = [
480 :Manual group: the books
484 Test title, docinfo to man page header.
486 r""".\" Man page generated from reStructuredText.
488 """ + indend_macros + r""".TH "PAGE TITLE" 3 "3/Nov/2022" "0.0" "the books"
490 page title \- in short
492 Test title, docinfo to man page header.
493 .\" Generated by docutils manpage writer.
499 if __name__ == '__main__
':