refactor code/tests: keyword support for search index #2516

This commit is contained in:
Timotheus Kampik
2016-05-05 18:09:22 +02:00
parent 6f6b28d3e6
commit 01797faede
5 changed files with 23 additions and 29 deletions

View File

@@ -8,6 +8,7 @@
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import os
from docutils import frontend, utils
from docutils.parsers import rst
@@ -54,21 +55,24 @@ def test_objects_are_escaped(app, status, warning):
assert 'n::Array&lt;T, d&gt;' in index.get('objects').get('') # n::Array<T,d> is escaped
def assert_lang_agnostic_key_words(searchindex):
assert 'findnotthiskey' not in searchindex
assert 'thisnoteith' not in searchindex
assert 'thistoo' in searchindex
assert 'thisonetoo' in searchindex
@with_app(testroot='search')
def test_meta_keys_are_handled_for_language_en(app, status, warning):
os.remove(app.outdir / 'searchindex.js')
app.builder.build_all()
searchindex = (app.outdir / 'searchindex.js').text()
assert_lang_agnostic_key_words(searchindex)
assert 'findthiskei' in searchindex
assert 'onlygerman' not in searchindex
assert 'thistoo' in searchindex
@with_app(testroot='search-de')
@with_app(testroot='search', confoverrides={'html_search_language': 'de'})
def test_meta_keys_are_handled_for_language_de(app, status, warning):
app.builder.build_all()
searchindex = (app.outdir / 'searchindex.js').text()
assert_lang_agnostic_key_words(searchindex)
assert 'findthiskey' in searchindex
assert 'onlygerman' in searchindex
assert 'notgerman' not in searchindex
assert 'onlytoogerman' in searchindex