2009-05-31 12:47:42 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_search
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the search index builder.
|
|
|
|
|
2016-01-14 15:54:04 -06:00
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
2009-05-31 12:47:42 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
2016-05-05 11:09:22 -05:00
|
|
|
import os
|
2009-05-31 12:47:42 -05:00
|
|
|
|
2010-01-17 05:02:15 -06:00
|
|
|
from docutils import frontend, utils
|
2009-05-31 12:47:42 -05:00
|
|
|
from docutils.parsers import rst
|
|
|
|
|
|
|
|
from sphinx.search import IndexBuilder
|
2016-02-28 19:52:15 -06:00
|
|
|
from sphinx.util import jsdump
|
|
|
|
|
|
|
|
from util import with_app
|
2009-05-31 12:47:42 -05:00
|
|
|
|
|
|
|
|
2010-01-17 05:02:15 -06:00
|
|
|
settings = parser = None
|
|
|
|
|
2009-05-31 12:47:42 -05:00
|
|
|
def setup_module():
|
|
|
|
global settings, parser
|
|
|
|
optparser = frontend.OptionParser(components=(rst.Parser,))
|
|
|
|
settings = optparser.get_default_values()
|
|
|
|
parser = rst.Parser()
|
|
|
|
|
|
|
|
|
|
|
|
FILE_CONTENTS = '''\
|
|
|
|
.. test that comments are not indexed: boson
|
|
|
|
|
|
|
|
test that non-comments are indexed: fermion
|
|
|
|
'''
|
|
|
|
|
|
|
|
def test_wordcollector():
|
2014-05-01 08:54:09 -05:00
|
|
|
doc = utils.new_document(b'test data', settings)
|
2009-05-31 12:47:42 -05:00
|
|
|
doc['file'] = 'dummy'
|
|
|
|
parser.parse(FILE_CONTENTS, doc)
|
|
|
|
|
2013-01-04 06:46:17 -06:00
|
|
|
ix = IndexBuilder(None, 'en', {}, None)
|
2009-05-31 12:47:42 -05:00
|
|
|
ix.feed('filename', 'title', doc)
|
|
|
|
assert 'boson' not in ix._mapping
|
|
|
|
assert 'fermion' in ix._mapping
|
2016-02-28 19:52:15 -06:00
|
|
|
|
|
|
|
|
2016-02-29 09:48:58 -06:00
|
|
|
@with_app(testroot='ext-viewcode')
|
2016-02-28 19:52:15 -06:00
|
|
|
def test_objects_are_escaped(app, status, warning):
|
|
|
|
app.builder.build_all()
|
|
|
|
searchindex = (app.outdir / 'searchindex.js').text()
|
|
|
|
assert searchindex.startswith('Search.setIndex(')
|
|
|
|
|
|
|
|
index = jsdump.loads(searchindex[16:-2])
|
|
|
|
assert 'n::Array<T, d>' in index.get('objects').get('') # n::Array<T,d> is escaped
|
2016-05-01 17:11:48 -05:00
|
|
|
|
2016-05-02 00:54:44 -05:00
|
|
|
def assert_lang_agnostic_key_words(searchindex):
|
|
|
|
assert 'thisnoteith' not in searchindex
|
|
|
|
assert 'thisonetoo' in searchindex
|
|
|
|
|
2016-05-01 17:11:48 -05:00
|
|
|
@with_app(testroot='search')
|
2016-05-02 00:54:44 -05:00
|
|
|
def test_meta_keys_are_handled_for_language_en(app, status, warning):
|
2016-05-05 11:09:22 -05:00
|
|
|
os.remove(app.outdir / 'searchindex.js')
|
2016-05-01 17:11:48 -05:00
|
|
|
app.builder.build_all()
|
|
|
|
searchindex = (app.outdir / 'searchindex.js').text()
|
2016-05-02 00:54:44 -05:00
|
|
|
assert_lang_agnostic_key_words(searchindex)
|
2016-05-01 17:11:48 -05:00
|
|
|
assert 'findthiskei' in searchindex
|
2016-05-05 11:09:22 -05:00
|
|
|
assert 'onlygerman' not in searchindex
|
|
|
|
assert 'thistoo' in searchindex
|
2016-05-02 00:54:44 -05:00
|
|
|
|
2016-05-05 11:09:22 -05:00
|
|
|
@with_app(testroot='search', confoverrides={'html_search_language': 'de'})
|
2016-05-02 00:54:44 -05:00
|
|
|
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)
|
2016-05-05 11:09:22 -05:00
|
|
|
assert 'onlygerman' in searchindex
|
|
|
|
assert 'notgerman' not in searchindex
|
|
|
|
assert 'onlytoogerman' in searchindex
|