Skip to content

Commit

Permalink
Auto merge of #50432 - GuillaumeGomez:fix-vec-new-search, r=QuietMisd…
Browse files Browse the repository at this point in the history
…reavus

Fix rustdoc pathes search

Fixes #50086.

Depends on #50302.

r? @QuietMisdreavus
  • Loading branch information
bors committed May 10, 2018
2 parents 95d0b9e + 2c91b49 commit c8a3ec1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@
Math.min(results_returned[fullId].lev, returned);
}
if (index !== -1 || lev <= MAX_LEV_DISTANCE) {
if (index !== -1) {
if (index !== -1 && paths.length < 2) {
lev = 0;
}
if (results[fullId] === undefined) {
Expand Down
20 changes: 20 additions & 0 deletions src/test/rustdoc-js/pinbox-new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// exact-check

const QUERY = 'pinbox::new';

const EXPECTED = {
'others': [
{ 'path': 'std::boxed::PinBox', 'name': 'new' },
{ 'path': 'alloc::boxed::PinBox', 'name': 'new' },
],
};
19 changes: 19 additions & 0 deletions src/test/rustdoc-js/vec-new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

const QUERY = 'Vec::new';

const EXPECTED = {
'others': [
{ 'path': 'std::vec::Vec', 'name': 'new' },
{ 'path': 'std::vec::Vec', 'name': 'ne' },
{ 'path': 'std::boxed::PinBox', 'name': 'new' },
],
};
10 changes: 8 additions & 2 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function loadContent(content) {
var m = new Module();
m._compile(content, "tmp.js");
m.exports.ignore_order = content.indexOf("\n// ignore-order\n") !== -1;
m.exports.exact_check = content.indexOf("\n// exact-check\n") !== -1;
return m.exports;
}

Expand Down Expand Up @@ -179,6 +180,7 @@ function main(argv) {
const expected = loadedFile.EXPECTED;
const query = loadedFile.QUERY;
const ignore_order = loadedFile.ignore_order;
const exact_check = loadedFile.exact_check;
var results = loaded.execSearch(loaded.getQuery(query), index);
process.stdout.write('Checking "' + file + '" ... ');
var error_text = [];
Expand All @@ -191,13 +193,17 @@ function main(argv) {
break;
}
var entry = expected[key];
var prev_pos = 0;
var prev_pos = -1;
for (var i = 0; i < entry.length; ++i) {
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) {
} else if (exact_check === true && prev_pos + 1 !== entry_pos) {
error_text.push("==> Exact check failed at position " + (prev_pos + 1) + ": " +
"expected '" + JSON.stringify(entry[i]) + "' but found '" +
JSON.stringify(results[key][i]) + "'");
} else if (ignore_order === false && entry_pos < prev_pos) {
error_text.push("==> '" + JSON.stringify(entry[i]) + "' was supposed to be " +
" before '" + JSON.stringify(results[key][entry_pos]) + "'");
} else {
Expand Down

0 comments on commit c8a3ec1

Please sign in to comment.