2020-08-19 09:41:20 -05:00
|
|
|
describe('Basic html theme search', function() {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
hits = [[
|
|
|
|
"index",
|
|
|
|
"<no title>",
|
|
|
|
"",
|
|
|
|
null,
|
2024-03-03 08:18:07 -06:00
|
|
|
5,
|
2020-08-19 09:41:20 -05:00
|
|
|
"index.rst"
|
|
|
|
]];
|
|
|
|
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
|
|
|
|
});
|
|
|
|
|
2024-03-03 11:01:10 -06:00
|
|
|
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;
|
|
|
|
hits = [[
|
|
|
|
'index',
|
|
|
|
'Main Page',
|
|
|
|
'',
|
|
|
|
null,
|
|
|
|
15,
|
|
|
|
'index.rst']];
|
|
|
|
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
|
|
|
|
});
|
|
|
|
|
2024-03-26 06:18:26 -05:00
|
|
|
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;
|
|
|
|
|
|
|
|
hits = [[
|
|
|
|
"index",
|
|
|
|
"sphinx_utils module",
|
|
|
|
"",
|
|
|
|
null,
|
|
|
|
7,
|
|
|
|
"index.rst"
|
|
|
|
]];
|
|
|
|
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
|
|
|
|
});
|
|
|
|
|
2020-08-19 09:41:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2022-03-19 17:40:51 -05:00
|
|
|
|
2024-02-27 08:22:52 -06:00
|
|
|
describe("htmlToText", function() {
|
|
|
|
|
|
|
|
const testHTML = `<html>
|
2024-03-17 09:14:03 -05:00
|
|
|
<body>
|
|
|
|
<script src="directory/filename.js"></script>
|
|
|
|
<div class="body" role="main">
|
|
|
|
<script>
|
|
|
|
console.log('dynamic');
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
div.body p.centered {
|
|
|
|
text-align: center;
|
|
|
|
margin-top: 25px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<!-- main content -->
|
|
|
|
<section id="getting-started">
|
2024-04-24 13:09:14 -05:00
|
|
|
<h1>Getting Started <a class="headerlink" href="#getting-started" title="Link to this heading">¶</a></h1>
|
2024-03-17 09:14:03 -05:00
|
|
|
<p>Some text</p>
|
|
|
|
</section>
|
|
|
|
<section id="other-section">
|
2024-04-24 13:09:14 -05:00
|
|
|
<h1>Other Section <a class="headerlink" href="#other-section" title="Link to this heading">¶</a></h1>
|
2024-03-17 09:14:03 -05:00
|
|
|
<p>Other text</p>
|
|
|
|
</section>
|
|
|
|
<section id="yet-another-section">
|
2024-04-24 13:09:14 -05:00
|
|
|
<h1>Yet Another Section <a class="headerlink" href="#yet-another-section" title="Link to this heading">¶</a></h1>
|
2024-03-17 09:14:03 -05:00
|
|
|
<p>More text</p>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</body>
|
2024-02-27 08:22:52 -06:00
|
|
|
</html>`;
|
|
|
|
|
|
|
|
it("basic case", () => {
|
|
|
|
expect(Search.htmlToText(testHTML).trim().split(/\s+/)).toEqual([
|
|
|
|
'Getting', 'Started', 'Some', 'text',
|
|
|
|
'Other', 'Section', 'Other', 'text',
|
|
|
|
'Yet', 'Another', 'Section', 'More', 'text'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("will start reading from the anchor", () => {
|
|
|
|
expect(Search.htmlToText(testHTML, '#other-section').trim().split(/\s+/)).toEqual(['Other', 'Section', 'Other', 'text']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-03-19 17:40:51 -05:00
|
|
|
// This is regression test for https://github.com/sphinx-doc/sphinx/issues/3150
|
|
|
|
describe('splitQuery regression tests', () => {
|
|
|
|
|
|
|
|
it('can split English words', () => {
|
|
|
|
const parts = splitQuery(' Hello World ')
|
|
|
|
expect(parts).toEqual(['Hello', 'World'])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can split special characters', () => {
|
|
|
|
const parts = splitQuery('Pin-Code')
|
|
|
|
expect(parts).toEqual(['Pin', 'Code'])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can split Chinese characters', () => {
|
|
|
|
const parts = splitQuery('Hello from 中国 上海')
|
|
|
|
expect(parts).toEqual(['Hello', 'from', '中国', '上海'])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can split Emoji (surrogate pair) characters. It should keep emojis.', () => {
|
|
|
|
const parts = splitQuery('😁😁')
|
|
|
|
expect(parts).toEqual(['😁😁'])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can split umlauts. It should keep umlauts.', () => {
|
|
|
|
const parts = splitQuery('Löschen Prüfung Abändern ærlig spørsmål')
|
|
|
|
expect(parts).toEqual(['Löschen', 'Prüfung', 'Abändern', 'ærlig', 'spørsmål'])
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|