mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
test: Add testcase for make_id()
This commit is contained in:
parent
82d49bafc5
commit
c0cc755306
@ -183,18 +183,37 @@ def test_clean_astext():
|
||||
assert 'hello world' == clean_astext(node)
|
||||
|
||||
|
||||
def test_make_id(app):
|
||||
@pytest.mark.parametrize(
|
||||
'prefix, term, expected',
|
||||
[
|
||||
('', '', 'id0'),
|
||||
('term', '', 'term-0'),
|
||||
('term', 'Sphinx', 'term-sphinx'),
|
||||
('', 'io.StringIO', 'io-stringio'), # contains a dot
|
||||
('', 'sphinx.setup_command', 'sphinx-setup-command'), # contains a dot
|
||||
('', '_io.StringIO', 'io-stringio'), # starts with underscore
|
||||
('', 'sphinx', 'sphinx'), # alphabets in unicode fullwidth characters
|
||||
('', '悠好', 'id0'), # multibytes text (in Chinese)
|
||||
('', 'Hello=悠好=こんにちは', 'hello'), # alphabets and multibytes text
|
||||
('', 'fünf', 'funf'), # latin1 (umlaut)
|
||||
('', '0sphinx', 'sphinx'), # starts with number
|
||||
('', 'sphinx-', 'sphinx'), # ends with hyphen
|
||||
])
|
||||
def test_make_id(app, prefix, term, expected):
|
||||
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'
|
||||
assert make_id(app.env, document, prefix, term) == expected
|
||||
|
||||
# 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'
|
||||
def test_make_id_already_registered(app):
|
||||
document = create_new_document()
|
||||
document.ids['term-sphinx'] = True # register "term-sphinx" manually
|
||||
assert make_id(app.env, document, 'term', 'Sphinx') == 'term-0'
|
||||
|
||||
|
||||
def test_make_id_sequential(app):
|
||||
document = create_new_document()
|
||||
document.ids['term-0'] = True
|
||||
assert make_id(app.env, document, 'term') == 'term-1'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
Loading…
Reference in New Issue
Block a user