summaryrefslogtreecommitdiff
path: root/tests/test_domain_std.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_domain_std.py')
-rw-r--r--tests/test_domain_std.py62
1 files changed, 53 insertions, 9 deletions
diff --git a/tests/test_domain_std.py b/tests/test_domain_std.py
index 33a000a3f..cf32e7964 100644
--- a/tests/test_domain_std.py
+++ b/tests/test_domain_std.py
@@ -4,24 +4,20 @@
Tests the std domain
- :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
-import pytest
-
from unittest import mock
+import pytest
from docutils import nodes
from docutils.nodes import definition, definition_list, definition_list_item, term
-
from html5lib import HTMLParser
from sphinx import addnodes
-from sphinx.addnodes import (
- desc, desc_addname, desc_content, desc_name, desc_signature, glossary, index,
- pending_xref
-)
+from sphinx.addnodes import (desc, desc_addname, desc_content, desc_name, desc_signature,
+ glossary, index, pending_xref)
from sphinx.domains.std import StandardDomain
from sphinx.testing import restructuredtext
from sphinx.testing.util import assert_node
@@ -95,6 +91,28 @@ def test_get_full_qualified_name():
assert domain.get_full_qualified_name(node) == 'ls.-l'
+def test_cmd_option_with_optional_value(app):
+ text = ".. option:: -j[=N]"
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, (index,
+ [desc, ([desc_signature, ([desc_name, '-j'],
+ [desc_addname, '[=N]'])],
+ [desc_content, ()])]))
+ objects = list(app.env.get_domain("std").get_objects())
+ assert ('-j', '-j', 'cmdoption', 'index', 'cmdoption-j', 1) in objects
+
+
+def test_cmd_option_starting_with_bracket(app):
+ text = ".. option:: [enable=]PATTERN"
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, (index,
+ [desc, ([desc_signature, ([desc_name, '[enable'],
+ [desc_addname, '=]PATTERN'])],
+ [desc_content, ()])]))
+ objects = list(app.env.get_domain("std").get_objects())
+ assert ('[enable', '[enable', 'cmdoption', 'index', 'cmdoption-arg-enable', 1) in objects
+
+
def test_glossary(app):
text = (".. glossary::\n"
"\n"
@@ -337,7 +355,7 @@ def test_multiple_cmdoptions(app):
def test_productionlist(app, status, warning):
app.builder.build_all()
- warnings = warning.getvalue().split("\n");
+ warnings = warning.getvalue().split("\n")
assert len(warnings) == 2
assert warnings[-1] == ''
assert "Dup2.rst:4: WARNING: duplicate token description of Dup, other instance in Dup1" in warnings[0]
@@ -387,6 +405,22 @@ def test_productionlist(app, status, warning):
assert "A</strong> ::= B C D E F G" in text
+def test_productionlist2(app):
+ text = (".. productionlist:: P2\n"
+ " A: `:A` `A`\n"
+ " B: `P1:B` `~P1:B`\n")
+ doctree = restructuredtext.parse(app, text)
+ refnodes = list(doctree.traverse(pending_xref))
+ assert_node(refnodes[0], pending_xref, reftarget="A")
+ assert_node(refnodes[1], pending_xref, reftarget="P2:A")
+ assert_node(refnodes[2], pending_xref, reftarget="P1:B")
+ assert_node(refnodes[3], pending_xref, reftarget="P1:B")
+ assert_node(refnodes[0], [pending_xref, nodes.literal, "A"])
+ assert_node(refnodes[1], [pending_xref, nodes.literal, "A"])
+ assert_node(refnodes[2], [pending_xref, nodes.literal, "P1:B"])
+ assert_node(refnodes[3], [pending_xref, nodes.literal, "B"])
+
+
def test_disabled_docref(app):
text = (":doc:`index`\n"
":doc:`!index`\n")
@@ -394,3 +428,13 @@ def test_disabled_docref(app):
assert_node(doctree, ([nodes.paragraph, ([pending_xref, nodes.inline, "index"],
"\n",
[nodes.inline, "index"])],))
+
+
+def test_labeled_rubric(app):
+ text = (".. _label:\n"
+ ".. rubric:: blah *blah* blah\n")
+ restructuredtext.parse(app, text)
+
+ domain = app.env.get_domain("std")
+ assert 'label' in domain.labels
+ assert domain.labels['label'] == ('index', 'label', 'blah blah blah')