mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Refactor testcases for #2516
This commit is contained in:
parent
82ef3b0aeb
commit
c028cfc5d3
@ -28,6 +28,17 @@ def setup_module():
|
|||||||
parser = rst.Parser()
|
parser = rst.Parser()
|
||||||
|
|
||||||
|
|
||||||
|
def jsload(path):
|
||||||
|
searchindex = path.text()
|
||||||
|
assert searchindex.startswith('Search.setIndex(')
|
||||||
|
|
||||||
|
return jsdump.loads(searchindex[16:-2])
|
||||||
|
|
||||||
|
|
||||||
|
def is_registered_term(index, keyword):
|
||||||
|
return index['terms'].get(keyword, []) != []
|
||||||
|
|
||||||
|
|
||||||
FILE_CONTENTS = '''\
|
FILE_CONTENTS = '''\
|
||||||
.. test that comments are not indexed: boson
|
.. test that comments are not indexed: boson
|
||||||
|
|
||||||
@ -54,25 +65,28 @@ def test_objects_are_escaped(app, status, warning):
|
|||||||
index = jsdump.loads(searchindex[16:-2])
|
index = jsdump.loads(searchindex[16:-2])
|
||||||
assert 'n::Array<T, d>' in index.get('objects').get('') # n::Array<T,d> is escaped
|
assert 'n::Array<T, d>' in index.get('objects').get('') # n::Array<T,d> is escaped
|
||||||
|
|
||||||
def assert_lang_agnostic_key_words(searchindex):
|
|
||||||
assert 'thisnoteith' not in searchindex
|
|
||||||
assert 'thisonetoo' in searchindex
|
|
||||||
|
|
||||||
@with_app(testroot='search')
|
@with_app(testroot='search')
|
||||||
def test_meta_keys_are_handled_for_language_en(app, status, warning):
|
def test_meta_keys_are_handled_for_language_en(app, status, warning):
|
||||||
os.remove(app.outdir / 'searchindex.js')
|
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
searchindex = (app.outdir / 'searchindex.js').text()
|
searchindex = jsload(app.outdir / 'searchindex.js')
|
||||||
assert_lang_agnostic_key_words(searchindex)
|
assert not is_registered_term(searchindex, 'thisnoteith')
|
||||||
assert 'findthiskei' in searchindex
|
assert is_registered_term(searchindex, 'thisonetoo')
|
||||||
assert 'onlygerman' not in searchindex
|
assert is_registered_term(searchindex, 'findthiskei')
|
||||||
assert 'thistoo' in searchindex
|
assert is_registered_term(searchindex, 'thistoo')
|
||||||
|
assert not is_registered_term(searchindex, 'onlygerman')
|
||||||
|
assert is_registered_term(searchindex, 'notgerman')
|
||||||
|
assert not is_registered_term(searchindex, 'onlytoogerman')
|
||||||
|
|
||||||
|
|
||||||
@with_app(testroot='search', confoverrides={'html_search_language': 'de'})
|
@with_app(testroot='search', confoverrides={'html_search_language': 'de'})
|
||||||
def test_meta_keys_are_handled_for_language_de(app, status, warning):
|
def test_meta_keys_are_handled_for_language_de(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
searchindex = (app.outdir / 'searchindex.js').text()
|
searchindex = jsload(app.outdir / 'searchindex.js')
|
||||||
assert_lang_agnostic_key_words(searchindex)
|
assert not is_registered_term(searchindex, 'thisnoteith')
|
||||||
assert 'onlygerman' in searchindex
|
assert is_registered_term(searchindex, 'thisonetoo')
|
||||||
assert 'notgerman' not in searchindex
|
assert not is_registered_term(searchindex, 'findthiskei')
|
||||||
assert 'onlytoogerman' in searchindex
|
assert not is_registered_term(searchindex, 'thistoo')
|
||||||
|
assert is_registered_term(searchindex, 'onlygerman')
|
||||||
|
assert not is_registered_term(searchindex, 'notgerman')
|
||||||
|
assert is_registered_term(searchindex, 'onlytoogerman')
|
||||||
|
Loading…
Reference in New Issue
Block a user