mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6493 from tk0miya/test_cmdoption
Add testcase for option directive
This commit is contained in:
commit
9314e5c38c
@ -13,7 +13,10 @@ from unittest import mock
|
||||
from docutils import nodes
|
||||
from docutils.nodes import definition, definition_list, definition_list_item, term
|
||||
|
||||
from sphinx.addnodes import glossary, index
|
||||
from sphinx import addnodes
|
||||
from sphinx.addnodes import (
|
||||
desc, desc_addname, desc_content, desc_name, desc_signature, glossary, index
|
||||
)
|
||||
from sphinx.domains.std import StandardDomain
|
||||
from sphinx.testing import restructuredtext
|
||||
from sphinx.testing.util import assert_node
|
||||
@ -239,3 +242,41 @@ def test_glossary_sorted(app):
|
||||
[nodes.definition, nodes.paragraph, "description"])
|
||||
assert_node(doctree[0][0][1][1],
|
||||
[nodes.definition, nodes.paragraph, "description"])
|
||||
|
||||
|
||||
def test_cmdoption(app):
|
||||
text = (".. program:: ls\n"
|
||||
"\n"
|
||||
".. option:: -l\n")
|
||||
domain = app.env.get_domain('std')
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_name, "-l"],
|
||||
[desc_addname, ()])],
|
||||
[desc_content, ()])]))
|
||||
assert_node(doctree[0], addnodes.index,
|
||||
entries=[('pair', 'ls command line option; -l', 'cmdoption-ls-l', '', None)])
|
||||
assert ('ls', '-l') in domain.progoptions
|
||||
assert domain.progoptions[('ls', '-l')] == ('index', 'cmdoption-ls-l')
|
||||
|
||||
|
||||
def test_multiple_cmdoptions(app):
|
||||
text = (".. program:: ls\n"
|
||||
"\n"
|
||||
".. option:: -h, --help\n")
|
||||
domain = app.env.get_domain('std')
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_name, "-h"],
|
||||
[desc_addname, ()],
|
||||
[desc_addname, ", "],
|
||||
[desc_name, "--help"],
|
||||
[desc_addname, ()])],
|
||||
[desc_content, ()])]))
|
||||
assert_node(doctree[0], addnodes.index,
|
||||
entries=[('pair', 'ls command line option; -h, --help',
|
||||
'cmdoption-ls-h', '', None)])
|
||||
assert ('ls', '-h') in domain.progoptions
|
||||
assert ('ls', '--help') in domain.progoptions
|
||||
assert domain.progoptions[('ls', '-h')] == ('index', 'cmdoption-ls-h')
|
||||
assert domain.progoptions[('ls', '--help')] == ('index', 'cmdoption-ls-h')
|
||||
|
Loading…
Reference in New Issue
Block a user