Skip to content

Commit

Permalink
Add query search order check
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Apr 28, 2018
1 parent ff65726 commit 00bbda1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/test/rustdoc-js/alias.js
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-order

const QUERY = '[';

const EXPECTED = {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-js/basic.js
Expand Up @@ -13,8 +13,8 @@ const QUERY = 'String';
const EXPECTED = {
'others': [
{ 'path': 'std::string', 'name': 'String' },
{ 'path': 'std::ffi', 'name': 'OsString' },
{ 'path': 'std::ffi', 'name': 'CString' },
{ 'path': 'std::ffi', 'name': 'OsString' },
],
'in_args': [
{ 'path': 'std::str', 'name': 'eq' },
Expand Down
18 changes: 12 additions & 6 deletions src/tools/rustdoc-js/tester.js
Expand Up @@ -87,6 +87,7 @@ function loadContent(content) {
var Module = module.constructor;
var m = new Module();
m._compile(content, "tmp.js");
m.exports.ignore_order = content.indexOf("\n// ignore-order\n") !== -1;
return m.exports;
}

Expand Down Expand Up @@ -130,10 +131,10 @@ function lookForEntry(entry, data) {
}
}
if (allGood === true) {
return true;
return i;
}
}
return false;
return null;
}

function main(argv) {
Expand Down Expand Up @@ -177,6 +178,7 @@ function main(argv) {
'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
const expected = loadedFile.EXPECTED;
const query = loadedFile.QUERY;
const ignore_order = loadedFile.ignore_order;
var results = loaded.execSearch(loaded.getQuery(query), index);
process.stdout.write('Checking "' + file + '" ... ');
var error_text = [];
Expand All @@ -189,13 +191,17 @@ function main(argv) {
break;
}
var entry = expected[key];
var found = false;
var prev_pos = 0;
for (var i = 0; i < entry.length; ++i) {
if (lookForEntry(entry[i], results[key]) === true) {
found = true;
} else {
var entry_pos = lookForEntry(entry[i], results[key]);
if (entry_pos === null) {
error_text.push("==> Result not found in '" + key + "': '" +
JSON.stringify(entry[i]) + "'");
} else if (entry_pos < prev_pos && ignore_order === false) {
error_text.push("==> '" + JSON.stringify(entry[i]) + "' was supposed to be " +
" before '" + JSON.stringify(results[key][entry_pos]) + "'");
} else {
prev_pos = entry_pos;
}
}
}
Expand Down

0 comments on commit 00bbda1

Please sign in to comment.