From d0840fd63bcbb3aa8dd43d83a2fe275b00e94f6d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 3 May 2018 22:20:57 +0200 Subject: [PATCH 1/2] Fix paths search --- src/librustdoc/html/static/main.js | 2 +- src/test/rustdoc-js/pinbox-new.js | 18 ++++++++++++++++++ src/test/rustdoc-js/vec-new.js | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-js/pinbox-new.js create mode 100644 src/test/rustdoc-js/vec-new.js diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 6d80145b29c7c..8569abeb09cc1 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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) { diff --git a/src/test/rustdoc-js/pinbox-new.js b/src/test/rustdoc-js/pinbox-new.js new file mode 100644 index 0000000000000..9d2bf1b4551ec --- /dev/null +++ b/src/test/rustdoc-js/pinbox-new.js @@ -0,0 +1,18 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const QUERY = 'pinbox::new'; + +const EXPECTED = { + 'others': [ + { 'path': 'std::boxed::PinBox', 'name': 'new' }, + { 'path': 'alloc::boxed::PinBox', 'name': 'new' }, + ], +}; diff --git a/src/test/rustdoc-js/vec-new.js b/src/test/rustdoc-js/vec-new.js new file mode 100644 index 0000000000000..702953e2e9dd1 --- /dev/null +++ b/src/test/rustdoc-js/vec-new.js @@ -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 or the MIT license +// , 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' }, + ], +}; From 2c91b49fe45b71e30f3e47e185671fc75b36952f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 3 May 2018 22:54:04 +0200 Subject: [PATCH 2/2] Add exact-check option to rustdoc-js tests --- src/test/rustdoc-js/pinbox-new.js | 2 ++ src/tools/rustdoc-js/tester.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/rustdoc-js/pinbox-new.js b/src/test/rustdoc-js/pinbox-new.js index 9d2bf1b4551ec..061c7b30741d9 100644 --- a/src/test/rustdoc-js/pinbox-new.js +++ b/src/test/rustdoc-js/pinbox-new.js @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// exact-check + const QUERY = 'pinbox::new'; const EXPECTED = { diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index 1c79443dedf35..25f7a2d1294c5 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -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; } @@ -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 = []; @@ -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 {