Skip to content

Commit

Permalink
Merge pull request #7342 from tk0miya/tests_make_id
Browse files Browse the repository at this point in the history
test: Add testcase for make_id()
  • Loading branch information
tk0miya committed Mar 20, 2020
2 parents 046b55b + c0cc755 commit 593dcaf
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions tests/test_util_nodes.py
Expand Up @@ -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, prefix, term) == expected


def test_make_id_already_registered(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'
document.ids['term-sphinx'] = True # register "term-sphinx" manually
assert make_id(app.env, document, 'term', 'Sphinx') == 'term-0'

# 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_sequential(app):
document = create_new_document()
document.ids['term-0'] = True
assert make_id(app.env, document, 'term') == 'term-1'


@pytest.mark.parametrize(
Expand Down

0 comments on commit 593dcaf

Please sign in to comment.