| 1 |
<html> |
| 2 |
<!-- |
| 3 |
This is a test file for pydoctor's search system. |
| 4 |
It needs to manually copied to the output directory once the build is finished. |
| 5 |
--> |
| 6 |
|
| 7 |
<pre id="test-results"></pre> |
| 8 |
|
| 9 |
<script type="text/javascript"> |
| 10 |
/** |
| 11 |
* part of expect |
| 12 |
* the essential JavaScript test library |
| 13 |
* |
| 14 |
* @copyright 2013 Enrico Marino |
| 15 |
* @license MIT |
| 16 |
*/ |
| 17 |
|
| 18 |
/** |
| 19 |
* equal |
| 20 |
* Expect `value` to be equal to `expected` |
| 21 |
* |
| 22 |
* @param value |
| 23 |
* @param expected |
| 24 |
* @param {String} message |
| 25 |
*/ |
| 26 |
|
| 27 |
function equal(value, expected, message) { |
| 28 |
if (value == expected) return; |
| 29 |
throw new Error(message); |
| 30 |
}; |
| 31 |
</script> |
| 32 |
|
| 33 |
<script src="ajax.js" type='text/javascript'></script> |
| 34 |
<script src="searchlib.js" type='text/javascript'></script> |
| 35 |
|
| 36 |
<!-- Search test script --> |
| 37 |
<script type="text/javascript"> |
| 38 |
|
| 39 |
function testSearch(query, expectedResults){ |
| 40 |
return lunrSearch(query, 'searchindex.json', ['qname', 'name', 'names'], 'lunr.js', 0).then((results) => { |
| 41 |
let flatResults = []; |
| 42 |
results.forEach(element => { |
| 43 |
flatResults.push(element.ref); |
| 44 |
}); |
| 45 |
_flat = JSON.stringify(flatResults, space=4); |
| 46 |
_expected = JSON.stringify(expectedResults, space=4); |
| 47 |
equal(_flat, _expected, `Got ${_flat} instead of ${_expected}.`); |
| 48 |
}).then(() => { |
| 49 |
document.getElementById('test-results').innerHTML += "Success!\n"; |
| 50 |
}).catch((error) => { |
| 51 |
document.getElementById('test-results').innerHTML += `Failure: ${error}\n`; |
| 52 |
}); |
| 53 |
} |
| 54 |
|
| 55 |
async function test(){ |
| 56 |
await testSearch('+qname:pydoctor', ['pydoctor']); |
| 57 |
await testSearch('+qname:pydoctor.epydoc2stan', ['pydoctor.epydoc2stan']); |
| 58 |
await testSearch('_colorize_re_pattern', ['pydoctor.epydoc.markup._pyval_repr.PyvalColorizer._colorize_re_pattern']) |
| 59 |
await testSearch('+name:Class', ['pydoctor.model.Class', 'pydoctor.model.DocumentableKind.CLASS']) |
| 60 |
|
| 61 |
let to_stan_results = [ |
| 62 |
'pydoctor.epydoc.markup.ParsedDocstring.to_stan', |
| 63 |
'pydoctor.epydoc.markup.plaintext.ParsedPlaintextDocstring.to_stan', |
| 64 |
'pydoctor.epydoc.markup._types.ParsedTypeDocstring.to_stan', |
| 65 |
'pydoctor.epydoc.markup._pyval_repr.ColorizedPyvalRepr.to_stan', |
| 66 |
]; |
| 67 |
|
| 68 |
await testSearch('to_stan*', to_stan_results); |
| 69 |
await testSearch('to_stan', to_stan_results); |
| 70 |
|
| 71 |
let to_node_results = [ |
| 72 |
'pydoctor.epydoc.markup.ParsedDocstring.to_node', |
| 73 |
'pydoctor.epydoc.markup.plaintext.ParsedPlaintextDocstring.to_node', |
| 74 |
'pydoctor.epydoc.markup._types.ParsedTypeDocstring.to_node', |
| 75 |
'pydoctor.epydoc.markup.restructuredtext.ParsedRstDocstring.to_node', |
| 76 |
'pydoctor.epydoc.markup.epytext.ParsedEpytextDocstring.to_node', |
| 77 |
]; |
| 78 |
|
| 79 |
await testSearch('to_node*', to_node_results); |
| 80 |
await testSearch('to_node', to_node_results); |
| 81 |
await testSearch('qname:pydoctor.epydoc.markup.restructuredtext.ParsedRstDocstring', |
| 82 |
['pydoctor.epydoc.markup.restructuredtext.ParsedRstDocstring']); |
| 83 |
await testSearch('pydoctor.epydoc.markup.restructuredtext.ParsedRstDocstring', |
| 84 |
['pydoctor.epydoc.markup.restructuredtext.ParsedRstDocstring']); |
| 85 |
} |
| 86 |
|
| 87 |
test(); |
| 88 |
|
| 89 |
</script> |
| 90 |
</html> |