-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tests] JavaScript: extract searchindex.js-format test fixtures. #12102
Changes from all commits
cf53a7c
311c4f0
e0bee37
4340bbe
40fc985
7e22d78
8f753a8
dd1fde8
695037d
58b5e90
c37bb53
8ac1b6c
e31a7bd
fbaff49
d619a52
b33d331
55b6072
ee4316d
0634502
0bc558a
a74bc15
a037867
68a6504
564de92
64ecd41
34752b1
1addb80
76cc8d5
d66b7a2
01a4509
262dcec
52ee7c4
916e5af
de6f7a0
ef8e4b0
450aafe
94b9fc5
d885288
6987c48
fac7694
a464bdf
5b6a479
fc76aef
e9614b9
4d62b15
38bfc34
51f9a4d
8c6c669
5827576
9773c0c
66328bc
7370d20
2ef85ba
cd1a368
7e4b562
ec4f236
9b709d7
3d108c1
1b59d03
d0125c7
fa64b98
0086771
3a6c784
14f1b98
d7e0e82
08460ca
2297164
9f5df2c
59d497d
cc8ee12
2cc1476
7e92842
9c0f2b2
7acb3cd
de00490
b8ab726
e66af4b
5c23157
ee2fd98
83fe92a
f9d6191
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* language_data.js | ||
* ~~~~~~~~~~~~~~~~ | ||
* | ||
* This script contains the language-specific data used by searchtools.js, | ||
* namely the list of stopwords, stemmer, scorer and splitter. | ||
* | ||
* :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS. | ||
* :license: BSD, see LICENSE for details. | ||
* | ||
*/ | ||
|
||
var stopwords = []; | ||
|
||
|
||
/* Non-minified version is copied as a separate JS file, if available */ | ||
|
||
/** | ||
* Dummy stemmer for languages without stemming rules. | ||
*/ | ||
var Stemmer = function() { | ||
this.stemWord = function(w) { | ||
return w; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This is a sample C++ project used to generate a search engine index fixture. | ||
|
||
.. cpp:class:: public Sphinx | ||
|
||
The description of Sphinx class. | ||
|
||
Indexing and querying the term C++ can be challenging, because search-related | ||
tokenization often drops punctuation and mathematical characters (they occur | ||
frequently on the web and would inflate the cardinality and size of web search | ||
indexes). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Main Page | ||
========= | ||
|
||
This is the main page of the ``multiterm`` test project. | ||
|
||
This document is used as a test fixture to check that the search functionality | ||
included when projects are built into an HTML output format can successfully | ||
match this document when a search query containing multiple terms is performed. | ||
|
||
At the time-of-writing this message, the application doesn't support "phrase | ||
queries" -- queries that require all of the contained terms to appear adjacent | ||
to each other and in the same order in the document as in the query; perhaps it | ||
will do in future? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sphinx_utils module | ||
=================== | ||
|
||
Partial (also known as "prefix") matches on document titles should be possible | ||
using the JavaScript search functionality included when HTML documentation | ||
projects are built. | ||
|
||
This document provides a sample reStructuredText input to confirm that partial | ||
title matching is possible. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
describe('Basic html theme search', function() { | ||
|
||
function loadFixture(name) { | ||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
req = new XMLHttpRequest(); | ||
req.open("GET", `base/tests/js/fixtures/${name}`, false); | ||
req.send(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing you used Apparently using XMLHttpRequest this way is discouraged and might be deprecated at some point, but they've been saying that since 2014. 😉 It's probably fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that's good to know :) Yep; we don't want the test to proceed until the fixture has definitely loaded -- I'm inclined to use a straightforward (even if seemingly dated) approach here. |
||
return req.responseText; | ||
} | ||
|
||
describe('terms search', function() { | ||
|
||
it('should find "C++" when in index', function() { | ||
index = { | ||
docnames:["index"], | ||
filenames:["index.rst"], | ||
terms:{'c++':0}, | ||
titles:["<no title>"], | ||
titleterms:{} | ||
} | ||
Search.setIndex(index); | ||
searchterms = ['c++']; | ||
excluded = []; | ||
terms = index.terms; | ||
titleterms = index.titleterms; | ||
eval(loadFixture("cpp/searchindex.js")); | ||
jayaddison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[_searchQuery, searchterms, excluded, ..._remainingItems] = Search._parseQuery('C++'); | ||
terms = Search._index.terms; | ||
titleterms = Search._index.titleterms; | ||
|
||
hits = [[ | ||
"index", | ||
|
@@ -28,22 +28,11 @@ describe('Basic html theme search', function() { | |
}); | ||
|
||
it('should be able to search for multiple terms', function() { | ||
index = { | ||
alltitles: { | ||
'Main Page': [[0, 'main-page']], | ||
}, | ||
docnames:["index"], | ||
filenames:["index.rst"], | ||
terms:{main:0, page:0}, | ||
titles:["Main Page"], | ||
titleterms:{ main:0, page:0 } | ||
} | ||
Search.setIndex(index); | ||
|
||
searchterms = ['main', 'page']; | ||
excluded = []; | ||
terms = index.terms; | ||
titleterms = index.titleterms; | ||
eval(loadFixture("multiterm/searchindex.js")); | ||
jayaddison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[_searchQuery, searchterms, excluded, ..._remainingItems] = Search._parseQuery('main page'); | ||
terms = Search._index.terms; | ||
titleterms = Search._index.titleterms; | ||
hits = [[ | ||
'index', | ||
'Main Page', | ||
|
@@ -55,18 +44,11 @@ describe('Basic html theme search', function() { | |
}); | ||
|
||
it('should partially-match "sphinx" when in title index', function() { | ||
index = { | ||
docnames:["index"], | ||
filenames:["index.rst"], | ||
terms:{'useful': 0, 'utilities': 0}, | ||
titles:["sphinx_utils module"], | ||
titleterms:{'sphinx_utils': 0} | ||
} | ||
Search.setIndex(index); | ||
searchterms = ['sphinx']; | ||
excluded = []; | ||
terms = index.terms; | ||
titleterms = index.titleterms; | ||
eval(loadFixture("partial/searchindex.js")); | ||
|
||
[_searchQuery, searchterms, excluded, ..._remainingItems] = Search._parseQuery('sphinx'); | ||
terms = Search._index.terms; | ||
titleterms = Search._index.titleterms; | ||
|
||
hits = [[ | ||
"index", | ||
|
@@ -81,6 +63,37 @@ describe('Basic html theme search', function() { | |
|
||
}); | ||
|
||
describe('aggregation of search results', function() { | ||
|
||
it('should combine document title and document term matches', function() { | ||
eval(loadFixture("multiterm/searchindex.js")); | ||
|
||
searchParameters = Search._parseQuery('main page'); | ||
|
||
// fixme: duplicate result due to https://github.com/sphinx-doc/sphinx/issues/11961 | ||
hits = [ | ||
[ | ||
'index', | ||
'Main Page', | ||
'', | ||
null, | ||
15, | ||
'index.rst' | ||
], | ||
[ | ||
'index', | ||
'Main Page', | ||
'#main-page', | ||
null, | ||
100, | ||
'index.rst' | ||
] | ||
]; | ||
expect(Search._performSearch(...searchParameters)).toEqual(hits); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe("htmlToText", function() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import subprocess | ||
from pathlib import Path | ||
|
||
SPHINX_ROOT = Path(__file__).resolve().parent.parent | ||
TEST_JS_FIXTURES = SPHINX_ROOT / 'tests' / 'js' / 'fixtures' | ||
TEST_JS_ROOTS = SPHINX_ROOT / 'tests' / 'js' / 'roots' | ||
|
||
|
||
def build(srcdir: Path) -> None: | ||
cmd = ( | ||
'sphinx-build', | ||
'--fresh-env', | ||
'--quiet', | ||
*('--builder', 'html'), | ||
f'{srcdir}', | ||
f'{srcdir}/_build', | ||
) | ||
subprocess.run(cmd, check=True, capture_output=True) | ||
|
||
|
||
for directory in TEST_JS_ROOTS.iterdir(): | ||
searchindex = directory / '_build' / 'searchindex.js' | ||
destination = TEST_JS_FIXTURES / directory.name / 'searchindex.js' | ||
|
||
print(f'Building {directory} ... ', end='') | ||
build(directory) | ||
print('done') | ||
|
||
print(f'Moving {searchindex} to {destination} ... ', end='') | ||
destination.parent.mkdir(exist_ok=True) | ||
searchindex.replace(destination) | ||
print('done') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments in this file seem a little misleading? This is really just test scaffolding AFAICT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mm, yep - this is an interesting case - it's an evaluated copy of a template file from the basic theme. That's me attempting to make the JavaScript test environment realistic, but it is duplicative (and a bit confusing).