diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-01-02 00:09:32 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-01-02 22:03:39 +0900 |
commit | 1c5a5bbbe5c3e63763940b6f8cebf9af0e415009 (patch) | |
tree | bf3fda2999428b25ab73dae4b3b61b403e3f1ce8 /tests/test_util_nodes.py | |
parent | 7123f4038a185ad5783cea5a9054246a720cc2fb (diff) | |
download | sphinx-git-1c5a5bbbe5c3e63763940b6f8cebf9af0e415009.tar.gz |
Add sphinx.util.nodes:make_id() to generate better node_id
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', [ |