diff options
Diffstat (limited to 'tests/test_util_nodes.py')
-rw-r--r-- | tests/test_util_nodes.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/test_util_nodes.py b/tests/test_util_nodes.py index b1a6b7d1d..76ba51800 100644 --- a/tests/test_util_nodes.py +++ b/tests/test_util_nodes.py @@ -17,7 +17,9 @@ from docutils.parsers import rst from docutils.utils import new_document from sphinx.transforms import ApplySourceWorkaround -from sphinx.util.nodes import NodeMatcher, extract_messages, clean_astext, split_explicit_title +from sphinx.util.nodes import ( + NodeMatcher, extract_messages, clean_astext, make_id, split_explicit_title +) def _transform(doctree): @@ -27,6 +29,7 @@ def _transform(doctree): def create_new_document(): settings = frontend.OptionParser( components=(rst.Parser,)).get_default_values() + settings.id_prefix = 'id' document = new_document('dummy.txt', settings) return document @@ -180,6 +183,20 @@ def test_clean_astext(): assert 'hello world' == clean_astext(node) +def test_make_id(app): + document = create_new_document() + assert make_id(app.env, document) == 'id0' + assert make_id(app.env, document, 'term') == 'term-0' + assert make_id(app.env, document, 'term', 'Sphinx') == 'term-sphinx' + + # when same ID is already registered + document.ids['term-sphinx'] = True + assert make_id(app.env, document, 'term', 'Sphinx') == 'term-1' + + document.ids['term-2'] = True + assert make_id(app.env, document, 'term') == 'term-3' + + @pytest.mark.parametrize( 'title, expected', [ |