2010-04-16 04:51:19 -05:00
|
|
|
"""
|
|
|
|
Tests the reStructuredText domain.
|
|
|
|
|
2022-01-01 03:45:03 -06:00
|
|
|
:copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
|
2010-04-16 04:51:19 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
2019-04-12 06:58:10 -05:00
|
|
|
from sphinx import addnodes
|
2020-11-11 05:00:27 -06:00
|
|
|
from sphinx.addnodes import (desc, desc_addname, desc_annotation, desc_content, desc_name,
|
|
|
|
desc_signature)
|
2010-04-16 04:51:19 -05:00
|
|
|
from sphinx.domains.rst import parse_directive
|
2019-04-12 06:58:10 -05:00
|
|
|
from sphinx.testing import restructuredtext
|
|
|
|
from sphinx.testing.util import assert_node
|
2010-04-16 04:51:19 -05:00
|
|
|
|
2010-04-17 03:29:14 -05:00
|
|
|
|
2016-06-11 10:00:52 -05:00
|
|
|
def test_parse_directive():
|
2018-12-15 08:02:28 -06:00
|
|
|
s = parse_directive(' foö ')
|
|
|
|
assert s == ('foö', '')
|
2010-04-17 03:29:14 -05:00
|
|
|
|
2018-12-15 08:02:28 -06:00
|
|
|
s = parse_directive(' .. foö :: ')
|
2019-04-12 07:06:15 -05:00
|
|
|
assert s == ('foö', '')
|
2010-04-17 03:29:14 -05:00
|
|
|
|
2018-12-15 08:02:28 -06:00
|
|
|
s = parse_directive('.. foö:: args1 args2')
|
|
|
|
assert s == ('foö', ' args1 args2')
|
2010-04-17 03:29:14 -05:00
|
|
|
|
2010-04-16 04:51:19 -05:00
|
|
|
s = parse_directive('.. :: bar')
|
|
|
|
assert s == ('.. :: bar', '')
|
2019-04-12 06:58:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_rst_directive(app):
|
|
|
|
# bare
|
|
|
|
text = ".. rst:directive:: toctree"
|
|
|
|
doctree = restructuredtext.parse(app, text)
|
|
|
|
assert_node(doctree, (addnodes.index,
|
|
|
|
[desc, ([desc_signature, desc_name, ".. toctree::"],
|
|
|
|
[desc_content, ()])]))
|
|
|
|
assert_node(doctree[0],
|
|
|
|
entries=[("single", "toctree (directive)", "directive-toctree", "", None)])
|
|
|
|
assert_node(doctree[1], addnodes.desc, desctype="directive",
|
|
|
|
domain="rst", objtype="directive", noindex=False)
|
|
|
|
|
|
|
|
# decorated
|
|
|
|
text = ".. rst:directive:: .. toctree::"
|
|
|
|
doctree = restructuredtext.parse(app, text)
|
|
|
|
assert_node(doctree, (addnodes.index,
|
2019-04-12 07:06:15 -05:00
|
|
|
[desc, ([desc_signature, desc_name, ".. toctree::"],
|
2019-04-12 06:58:10 -05:00
|
|
|
[desc_content, ()])]))
|
|
|
|
assert_node(doctree[0],
|
|
|
|
entries=[("single", "toctree (directive)", "directive-toctree", "", None)])
|
|
|
|
assert_node(doctree[1], addnodes.desc, desctype="directive",
|
|
|
|
domain="rst", objtype="directive", noindex=False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_rst_directive_with_argument(app):
|
|
|
|
text = ".. rst:directive:: .. toctree:: foo bar baz"
|
|
|
|
doctree = restructuredtext.parse(app, text)
|
|
|
|
assert_node(doctree, (addnodes.index,
|
|
|
|
[desc, ([desc_signature, ([desc_name, ".. toctree::"],
|
|
|
|
[desc_addname, " foo bar baz"])],
|
|
|
|
[desc_content, ()])]))
|
|
|
|
assert_node(doctree[0],
|
|
|
|
entries=[("single", "toctree (directive)", "directive-toctree", "", None)])
|
|
|
|
assert_node(doctree[1], addnodes.desc, desctype="directive",
|
|
|
|
domain="rst", objtype="directive", noindex=False)
|
|
|
|
|
|
|
|
|
2019-04-12 21:00:16 -05:00
|
|
|
def test_rst_directive_option(app):
|
|
|
|
text = ".. rst:directive:option:: foo"
|
|
|
|
doctree = restructuredtext.parse(app, text)
|
|
|
|
assert_node(doctree, (addnodes.index,
|
|
|
|
[desc, ([desc_signature, desc_name, ":foo:"],
|
|
|
|
[desc_content, ()])]))
|
|
|
|
assert_node(doctree[0],
|
|
|
|
entries=[("single", ":foo: (directive option)",
|
2020-02-29 03:22:34 -06:00
|
|
|
"directive-option-foo", "", "F")])
|
2019-04-12 21:00:16 -05:00
|
|
|
assert_node(doctree[1], addnodes.desc, desctype="directive:option",
|
|
|
|
domain="rst", objtype="directive:option", noindex=False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_rst_directive_option_with_argument(app):
|
|
|
|
text = ".. rst:directive:option:: foo: bar baz"
|
|
|
|
doctree = restructuredtext.parse(app, text)
|
|
|
|
assert_node(doctree, (addnodes.index,
|
|
|
|
[desc, ([desc_signature, ([desc_name, ":foo:"],
|
|
|
|
[desc_annotation, " bar baz"])],
|
|
|
|
[desc_content, ()])]))
|
|
|
|
assert_node(doctree[0],
|
|
|
|
entries=[("single", ":foo: (directive option)",
|
2020-02-29 03:22:34 -06:00
|
|
|
"directive-option-foo", "", "F")])
|
2019-04-12 21:00:16 -05:00
|
|
|
assert_node(doctree[1], addnodes.desc, desctype="directive:option",
|
|
|
|
domain="rst", objtype="directive:option", noindex=False)
|
|
|
|
|
|
|
|
|
2019-04-16 08:32:51 -05:00
|
|
|
def test_rst_directive_option_type(app):
|
|
|
|
text = (".. rst:directive:option:: foo\n"
|
|
|
|
" :type: directives.flags\n")
|
|
|
|
doctree = restructuredtext.parse(app, text)
|
|
|
|
assert_node(doctree, (addnodes.index,
|
|
|
|
[desc, ([desc_signature, ([desc_name, ":foo:"],
|
|
|
|
[desc_annotation, " (directives.flags)"])],
|
|
|
|
[desc_content, ()])]))
|
|
|
|
assert_node(doctree[0],
|
|
|
|
entries=[("single", ":foo: (directive option)",
|
2020-02-29 03:22:34 -06:00
|
|
|
"directive-option-foo", "", "F")])
|
2019-04-16 08:32:51 -05:00
|
|
|
assert_node(doctree[1], addnodes.desc, desctype="directive:option",
|
|
|
|
domain="rst", objtype="directive:option", noindex=False)
|
|
|
|
|
|
|
|
|
2019-04-12 21:00:16 -05:00
|
|
|
def test_rst_directive_and_directive_option(app):
|
|
|
|
text = (".. rst:directive:: foo\n"
|
|
|
|
"\n"
|
|
|
|
" .. rst:directive:option:: bar\n")
|
|
|
|
doctree = restructuredtext.parse(app, text)
|
|
|
|
assert_node(doctree, (addnodes.index,
|
|
|
|
[desc, ([desc_signature, desc_name, ".. foo::"],
|
|
|
|
[desc_content, (addnodes.index,
|
|
|
|
desc)])]))
|
|
|
|
assert_node(doctree[1][1][0],
|
|
|
|
entries=[("pair", "foo (directive); :bar: (directive option)",
|
2020-02-29 03:22:34 -06:00
|
|
|
"directive-option-foo-bar", "", "B")])
|
2019-04-12 21:00:16 -05:00
|
|
|
assert_node(doctree[1][1][1], ([desc_signature, desc_name, ":bar:"],
|
|
|
|
[desc_content, ()]))
|
|
|
|
assert_node(doctree[1][1][1], addnodes.desc, desctype="directive:option",
|
|
|
|
domain="rst", objtype="directive:option", noindex=False)
|
|
|
|
|
|
|
|
|
2019-04-12 06:58:10 -05:00
|
|
|
def test_rst_role(app):
|
|
|
|
text = ".. rst:role:: ref"
|
|
|
|
doctree = restructuredtext.parse(app, text)
|
|
|
|
assert_node(doctree, (addnodes.index,
|
|
|
|
[desc, ([desc_signature, desc_name, ":ref:"],
|
|
|
|
[desc_content, ()])]))
|
|
|
|
assert_node(doctree[0],
|
|
|
|
entries=[("single", "ref (role)", "role-ref", "", None)])
|
|
|
|
assert_node(doctree[1], addnodes.desc, desctype="role",
|
|
|
|
domain="rst", objtype="role", noindex=False)
|